You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/12/27 17:05:27 UTC

svn commit: r490524 - in /cocoon/branches/BRANCH_2_1_X: src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java status.xml

Author: cziegeler
Date: Wed Dec 27 08:05:27 2006
New Revision: 490524

URL: http://svn.apache.org/viewvc?view=rev&rev=490524
Log:
Block: Applied and improved patch for reloading bookmarks based on their (file) validity.
Fixes bug COCOON-1776"

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java?view=diff&rev=490524&r1=490523&r2=490524
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java Wed Dec 27 08:05:27 2006
@@ -46,6 +46,7 @@
 import org.apache.cocoon.portal.acting.helpers.LayoutMapping;
 import org.apache.cocoon.portal.acting.helpers.Mapping;
 import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.SAXException;
 
 /**
@@ -79,11 +80,16 @@
     
     protected String configurationFile;
     
-    /* (non-Javadoc)
+    protected SourceValidity oldValidity;
+
+    protected boolean reloadCheck = true;
+
+    /**
      * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
      */
     public void parameterize(Parameters parameters) throws ParameterException {
         this.historyParameterName = parameters.getParameter("history-parameter-name", "history");
+        this.reloadCheck = parameters.getParameterAsBoolean("check-reload", this.reloadCheck);
         this.configurationFile = parameters.getParameter("src", null);
         if ( this.configurationFile == null ) return;
         
@@ -100,77 +106,94 @@
     private void loadConfig() throws ParameterException {
         Configuration config;
         org.apache.excalibur.source.SourceResolver resolver = null;
+        Source source = null;  
         try {
-            resolver = (org.apache.excalibur.source.SourceResolver) this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
-            Source source = null;
-            try {
-                source = resolver.resolveURI(configurationFile);
-                SAXConfigurationHandler handler = new SAXConfigurationHandler();
-                SourceUtil.toSAX(source, handler);
-                config = handler.getConfiguration();
-            } catch (ProcessingException se) {
-                throw new ParameterException("Unable to read configuration from " + configurationFile, se);
-            } catch (SAXException se) {
-                throw new ParameterException("Unable to read configuration from " + configurationFile, se);
-            } catch (IOException ioe) {
-                throw new ParameterException("Unable to read configuration from " + configurationFile, ioe);
-            } finally {
-                resolver.release(source);
-            }
-        } catch (ServiceException se) {
-            throw new ParameterException("Unable to lookup source resolver.", se);
+        	try {
+        		resolver = (org.apache.excalibur.source.SourceResolver) this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
+        		source = resolver.resolveURI(configurationFile);
+        	} catch (IOException ioe) {
+				throw new ParameterException("Unable to read configuration from " + configurationFile, ioe);
+        	} catch (ServiceException se) {
+    			throw new ParameterException("Unable to lookup source resolver.", se);
+        	}
+        	SourceValidity newValidity = source.getValidity();
+        	if ( this.oldValidity == null
+                 || this.oldValidity.isValid() == SourceValidity.INVALID
+                 || this.oldValidity.isValid(newValidity) == SourceValidity.INVALID)	{
+                this.oldValidity = newValidity;
+        		try {
+        			SAXConfigurationHandler handler = new SAXConfigurationHandler();
+        			SourceUtil.toSAX(source, handler);
+        			config = handler.getConfiguration();
+        		} catch (ProcessingException se) {
+        			throw new ParameterException("Unable to read configuration from " + configurationFile, se);
+        		} catch (SAXException se) {
+        			throw new ParameterException("Unable to read configuration from " + configurationFile, se);
+        		} catch (IOException ioe) {
+        			throw new ParameterException("Unable to read configuration from " + configurationFile, ioe);
+        		}
+        		Configuration[] events = config.getChild("events").getChildren("event");
+        		
+        		if ( events != null ) {
+        			for(int i=0; i<events.length;i++) {
+        				try {
+        					final String type = events[i].getAttribute("type");
+        					final String id = events[i].getAttribute("id");
+        					if ( "jxpath".equals(type) ) {
+        						if ( this.eventMap.containsKey(id)) {
+        							throw new ParameterException("The id for the event " + id + " is not unique.");
+        						}
+        						final String targetType = events[i].getChild("targettype").getValue();
+        						final String targetId = events[i].getChild("targetid").getValue();
+        						final String path = events[i].getChild("path").getValue();
+        						if ( "layout".equals(targetType) ) {
+        							LayoutMapping mapping = new LayoutMapping();
+        							mapping.layoutId = targetId;
+        							mapping.path = path;
+        							this.eventMap.put(id, mapping);
+        						} else if ( "coplet".equals(targetType) ) {
+        							CopletMapping mapping = new CopletMapping();
+        							mapping.copletId = targetId;
+        							mapping.path = path;  
+        							this.eventMap.put(id, mapping);
+        						} else {
+        							throw new ParameterException("Unknown target type " + targetType);
+        						}
+        					} else if ( "fullscreen".equals(type) ) {
+        						if ( this.eventMap.containsKey(id)) {
+        							throw new ParameterException("The id for the event " + id + " is not unique.");
+        						}
+        						final String targetId = events[i].getChild("targetid").getValue();
+        						final String layoutId = events[i].getChild("layoutid").getValue();
+        						FullScreenMapping mapping = new FullScreenMapping();
+        						mapping.copletId = targetId;
+        						mapping.layoutId = layoutId;
+        						this.eventMap.put(id, mapping);                        
+        					} else {
+        						throw new ParameterException("Unknown event type for event " + id + ": " + type);                        
+        					}
+        				} catch (ConfigurationException ce) {
+        					throw new ParameterException("Configuration exception" ,ce);
+        				}
+        			}
+        		}
+        	}
         } finally {
-            this.manager.release(resolver);
+        	if (resolver != null) {
+        		resolver.release(source);
+        	}
+        	if (resolver != null) {
+        		this.manager.release(resolver);
+        	}
         }
-        Configuration[] events = config.getChild("events").getChildren("event");
-        if ( events != null ) {
-            for(int i=0; i<events.length;i++) {
-                try {
-                    final String type = events[i].getAttribute("type");
-                    final String id = events[i].getAttribute("id");
-                    if ( "jxpath".equals(type) ) {
-                        if ( this.eventMap.containsKey(id)) {
-                            throw new ParameterException("The id for the event " + id + " is not unique.");
-                        }
-                        final String targetType = events[i].getChild("targettype").getValue();
-                        final String targetId = events[i].getChild("targetid").getValue();
-                        final String path = events[i].getChild("path").getValue();
-                        if ( "layout".equals(targetType) ) {
-                            LayoutMapping mapping = new LayoutMapping();
-                            mapping.layoutId = targetId;
-                            mapping.path = path;
-                            this.eventMap.put(id, mapping);
-                        } else if ( "coplet".equals(targetType) ) {
-                            CopletMapping mapping = new CopletMapping();
-                            mapping.copletId = targetId;
-                            mapping.path = path;  
-                            this.eventMap.put(id, mapping);
-                        } else {
-                            throw new ParameterException("Unknown target type " + targetType);
-                        }
-                    } else if ( "fullscreen".equals(type) ) {
-                        if ( this.eventMap.containsKey(id)) {
-                            throw new ParameterException("The id for the event " + id + " is not unique.");
-                        }
-                        final String targetId = events[i].getChild("targetid").getValue();
-                        final String layoutId = events[i].getChild("layoutid").getValue();
-                        FullScreenMapping mapping = new FullScreenMapping();
-                        mapping.copletId = targetId;
-                        mapping.layoutId = layoutId;
-                        this.eventMap.put(id, mapping);                        
-                    } else {
-                        throw new ParameterException("Unknown event type for event " + id + ": " + type);                        
-                    }
-                } catch (ConfigurationException ce) {
-                    throw new ParameterException("Configuration exception" ,ce);
-                }
-            }
+        if ( !this.reloadCheck ) {
+            this.configurationFile = null;
         }
-        
-        // Nullify config filename so as not to reload it.
-        this.configurationFile = null;
     }
 
+    /**
+     * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
     public Map act(Redirector redirector,
                    SourceResolver resolver,
                    Map objectModel,
@@ -185,7 +208,7 @@
         }
 
         if (this.configurationFile != null) {
-            loadConfig();
+            this.loadConfig();
         }
 
         Map result;

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=490524&r1=490523&r2=490524
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed Dec 27 08:05:27 2006
@@ -181,6 +181,9 @@
 
   <changes>
   <release version="2.1.11" date="TBD">
+    <action dev="CZ" type="fix" fixes-bug="COCOON-1776" due-to="Vincent Demay">
+      Portal Block: Applied and improved patch for reloading bookmarks based on their (file) validity.
+    </action>
     <action dev="CZ" type="fix">
       Portal Block: Fix handling of missing special parameters for forms in NewEventLinkTransformer.
     </action>