cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r490525 - /cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java
Date Wed, 27 Dec 2006 16:08:15 GMT
Author: cziegeler
Date: Wed Dec 27 08:08:15 2006
New Revision: 490525

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

Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java?view=diff&rev=490525&r1=490524&r2=490525
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/acting/BookmarkAction.java
Wed Dec 27 08:08:15 2006
@@ -43,6 +43,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;
 
 /**
@@ -74,12 +75,17 @@
     protected String historyParameterName;
 
     protected String configurationFile;
+    
+    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;
 
@@ -96,75 +102,89 @@
     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;
     }
 
     /**
@@ -184,7 +204,7 @@
         }
 
         if (this.configurationFile != null) {
-            loadConfig();
+            this.loadConfig();
         }
 
         Map result;



Mime
View raw message