cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r232779 - /cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
Date Mon, 15 Aug 2005 09:13:55 GMT
Author: cziegeler
Date: Mon Aug 15 02:13:51 2005
New Revision: 232779

URL: http://svn.apache.org/viewcvs?rev=232779&view=rev
Log:
Ingore sizing events

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java?rev=232779&r1=232778&r2=232779&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
Mon Aug 15 02:13:51 2005
@@ -25,6 +25,7 @@
 import org.apache.cocoon.portal.PortalService;
 import org.apache.cocoon.portal.coplet.CopletInstanceData;
 import org.apache.cocoon.portal.event.CopletInstanceEvent;
+import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -38,12 +39,21 @@
  * the user session.
  *
  * @author <a href="mailto:gerald.kahrer@rizit.at">Gerald Kahrer</a>
- * 
+ * @author <a href="mailto:cziegeler.at.apache.dot.org">Carsten Ziegeler</a>
  * @version CVS $Id$
  */
 public class CachingURICopletAdapter
     extends URICopletAdapter {
     
+    /** The configuration name for enabling/disabling the cache. */
+    public static final String CONFIGURATION_ENABLE_CACHING = "cache-enabled";
+
+    /** The configuration name for using the global cache. */
+    public static final String CONFIGURATION_CACHE_GLOBAL= "cache-global";
+
+    /** The configuration name for ignoring sizing events to clear the cache. */
+    public static final String CONFIGURATION_IGNORE_SIZING_EVENTS = "ignore-sizing-events";
+
     /** The attribute name for the storing the cached coplet content. */
     public static final String CACHE = "cacheData";
 
@@ -90,9 +100,9 @@
                                final ContentHandler contentHandler)
     throws SAXException {
         // Is caching enabled?
-        boolean cachingEnabled = ((Boolean)this.getConfiguration(coplet, "cache-enabled",
Boolean.TRUE)).booleanValue();
+        boolean cachingEnabled = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_ENABLE_CACHING,
Boolean.TRUE)).booleanValue();
         // do we cache globally?
-        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, "cache-global", Boolean.FALSE)).booleanValue();
+        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_CACHE_GLOBAL,
Boolean.FALSE)).booleanValue();
 
         Object data = null;
         // If caching is enabed and the cache is still valid, then use the cache
@@ -163,15 +173,32 @@
     public void handleCopletInstanceEvent(CopletInstanceEvent event) {
         final CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
 
-        // do we cache globally?
-        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, "cache-global", Boolean.FALSE)).booleanValue();
-        if ( cacheGlobal ) {
-            final String key = this.getCacheKey(coplet,
-                                                (String) coplet.getCopletData().getAttribute("uri"));
-            this.cache.remove(key);
-        } else {
-            coplet.removeAttribute(CACHE);
+        // do we ignore SizingEvents
+        boolean ignoreSizing = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_IGNORE_SIZING_EVENTS,
Boolean.TRUE)).booleanValue();
+
+        if ( !ignoreSizing || !isSizingEvent(event)) {
+            // do we cache globally?
+            boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_CACHE_GLOBAL,
Boolean.FALSE)).booleanValue();
+            if ( cacheGlobal ) {
+                final String key = this.getCacheKey(coplet,
+                                                    (String) coplet.getCopletData().getAttribute("uri"));
+                this.cache.remove(key);
+            } else {
+                coplet.removeAttribute(CACHE);
+            }
+        }
+    }
+
+    /**
+     * Tests if the event is a sizing event for the coplet.
+     */
+    protected boolean isSizingEvent(CopletInstanceEvent event) {
+        if ( event instanceof ChangeCopletInstanceAspectDataEvent ) {
+            if (((ChangeCopletInstanceAspectDataEvent)event).getAspectName().equals("size"))
{
+                return true;
+            }
         }
+        return false;
     }
 
     /**



Mime
View raw message