cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r393302 - in /cocoon/trunk/blocks/cocoon-portal: cocoon-portal-impl/ cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/ cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ cocoon-portal-impl/src/main/java/...
Date Tue, 11 Apr 2006 20:07:14 GMT
Author: cziegeler
Date: Tue Apr 11 13:07:12 2006
New Revision: 393302

URL: http://svn.apache.org/viewcvs?rev=393302&view=rev
Log:
Unify coplet adapter implementation and add preloading aspect

Added:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
  (with props)
Removed:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/portal.roles
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/status.xml
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletbasedata/portal.xml
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletdata/portal.xml

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java
Tue Apr 11 13:07:12 2006
@@ -15,25 +15,44 @@
  */
 package org.apache.cocoon.portal.coplet.adapter.impl;
 
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.Cache;
+import org.apache.cocoon.caching.CachedResponse;
+import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
+import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
 import org.apache.cocoon.components.thread.RunnableManager;
 import org.apache.cocoon.environment.CocoonRunnable;
+import org.apache.cocoon.portal.PortalService;
 import org.apache.cocoon.portal.coplet.CopletData;
 import org.apache.cocoon.portal.coplet.CopletInstanceData;
+import org.apache.cocoon.portal.coplet.CopletInstanceDataFeatures;
 import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
+import org.apache.cocoon.portal.event.CopletInstanceEvent;
+import org.apache.cocoon.portal.event.Receiver;
 import org.apache.cocoon.portal.impl.AbstractComponent;
+import org.apache.cocoon.util.NetUtils;
 import org.apache.cocoon.xml.SaxBuffer;
 import org.apache.cocoon.xml.XMLUtils;
+import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
 
 import EDU.oswego.cs.dl.util.concurrent.CountDown;
 
 /**
- * This is the abstract base adapter to use pipelines as coplets
+ * This is the abstract base adapter which could be used by any adapter
+ * implementation. It already provides several base features which can
+ * be used by sub classes.
  *
  * <h2>Configuration</h2>
  * <table><tbody>
@@ -62,7 +81,63 @@
  */
 public abstract class AbstractCopletAdapter 
     extends AbstractComponent
-    implements CopletAdapter {
+    implements CopletAdapter, Receiver {
+
+    /** The configuration name for buffering. */
+    public static final String CONFIGURATION_BUFFERING = "buffer";
+
+    /** The configuration name for timeout. */    
+    public static final String CONFIGURATION_TIMEOUT = "timeout";
+
+    /** 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 querying instance attributes to generate the key
+     * for the global cache. */
+    public static final String CONFIGURATION_CACHE_GLOBAL_USE_ATTRIBUTES= "cache-global-use-attributes";
+
+    /** The configuration name for ignoring all sizing events to clear the cache. */
+    public static final String CONFIGURATION_IGNORE_SIZING_EVENTS = "ignore-sizing-events";
+
+    /** The configuration name for ignoring just min/normal sizing events to clear the cache.
*/
+    public static final String CONFIGURATION_IGNORE_SIMPLE_SIZING_EVENTS = "ignore-simple-sizing-events";
+
+    /** The temporary attribute name for the storing the cached coplet content. */
+    public static final String CACHE = "cacheData";
+
+    /** This temporary attribute can be set on the instance to not cache the current response.
*/
+    public static final String DO_NOT_CACHE = "doNotCache";
+    
+    /** The cache to use for global caching. */
+    protected Cache cache;
+
+    /** The runnable manager for starting background tasks. */
+    protected RunnableManager runnableManager;
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        this.cache = (Cache)this.manager.lookup(Cache.ROLE);
+        this.runnableManager = (RunnableManager)this.manager.lookup( RunnableManager.ROLE
);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        if ( this.manager != null ) {
+            this.manager.release(this.cache);
+            this.cache = null;
+            this.manager.release(this.runnableManager);
+            this.runnableManager = null;
+        }
+        super.dispose();
+    }
 
     /**
      * Get a configuration value
@@ -95,10 +170,10 @@
     }
 
     /**
-     * Implement this and not toSAX()
+     * Implement this and not toSAX().
      */
     public abstract void streamContent(CopletInstanceData coplet, 
-                                         ContentHandler contentHandler)
+                                       ContentHandler contentHandler)
     throws SAXException; 
 
     /**
@@ -112,8 +187,8 @@
     public void toSAX(CopletInstanceData coplet, ContentHandler contentHandler)
     throws SAXException {
         final long startTime = System.currentTimeMillis();
-        Boolean bool = (Boolean) this.getConfiguration( coplet, "buffer" );
-        Integer timeout = (Integer) this.getConfiguration( coplet, "timeout");
+        Boolean bool = (Boolean) this.getConfiguration( coplet, CONFIGURATION_BUFFERING );
+        Integer timeout = (Integer) this.getConfiguration( coplet, CONFIGURATION_TIMEOUT);
         if ( timeout != null ) {
             // if timeout is set we have to buffer!
             bool = Boolean.TRUE;
@@ -127,13 +202,8 @@
 
                 if ( timeout != null ) {
                     final int milli = timeout.intValue() * 1000;
-                    LoaderThread loader = new LoaderThread(this, coplet, buffer);
-                    final RunnableManager runnableManager = (RunnableManager)this.manager.lookup(
RunnableManager.ROLE );
-                    try {
-                        runnableManager.execute( new CocoonRunnable(loader) );
-                    } finally {
-                        this.manager.release( runnableManager );
-                    }
+                    final LoaderThread loader = new LoaderThread(this, coplet, buffer);
+                    this.runnableManager.execute( new CocoonRunnable(loader) );
                     try {
                         read = loader.join( milli );
                     } catch (InterruptedException ignore) {
@@ -144,7 +214,7 @@
                         this.getLogger().warn("Unable to get content of coplet: " + coplet.getId(),
error);                        
                     }
                 } else {
-                    this.streamContent( coplet, buffer );
+                    this.streamContentAndCache( coplet, buffer );
                     read = true;
                 }
             } catch (Exception exception ) {
@@ -168,7 +238,7 @@
                 }
             }
         } else {
-            this.streamContent( coplet, contentHandler );
+            this.streamContentAndCache( coplet, contentHandler );
         }
         if ( this.getLogger().isInfoEnabled() ) {
             final long msecs = System.currentTimeMillis() - startTime;
@@ -178,6 +248,74 @@
     }
 
     /**
+     * This method does the caching (if enabled).
+     */
+    public void streamContentAndCache( final CopletInstanceData coplet,
+                                       final ContentHandler contentHandler)
+    throws SAXException {
+        // Is caching enabled?
+        boolean cachingEnabled = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_ENABLE_CACHING,
Boolean.TRUE)).booleanValue();
+        // do we cache globally?
+        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
+        if (cachingEnabled) {
+            if ( cacheGlobal ) {
+                final String key = this.getCacheKey(coplet);
+                CachedResponse response = this.cache.get(key);
+                if (response != null ) {
+                    data = response.getResponse();
+                }
+            } else {
+                data = coplet.getTemporaryAttribute(CACHE);
+            }
+        }
+        if (data == null) {
+            // if caching is permanently or temporary disabled, flush the cache and invoke
coplet
+            if ( !cachingEnabled || coplet.getTemporaryAttribute(DO_NOT_CACHE) != null )
{
+                coplet.removeTemporaryAttribute(DO_NOT_CACHE);
+                if ( cacheGlobal ) {
+                    final String key = this.getCacheKey(coplet);
+                    this.cache.remove(key); 
+                } else {
+                    coplet.removeTemporaryAttribute(CACHE);
+                }
+                this.streamContent(coplet, contentHandler);                
+            } else {
+
+                XMLByteStreamCompiler bc = new XMLByteStreamCompiler();
+
+                this.streamContent(coplet, bc);
+                data = bc.getSAXFragment();
+                if (coplet.removeTemporaryAttribute(DO_NOT_CACHE) == null) {
+                    if ( cacheGlobal ) {
+                        CachedResponse response = new CachedResponse((SourceValidity[])null,
(byte[])data);
+                        try {
+                            final String key = this.getCacheKey(coplet);
+                            this.cache.store(key, response);
+                        } catch (ProcessingException pe) {
+                            // we ignore this
+                            this.getLogger().warn("Exception during storing response into
cache.", pe);
+                        }
+                    } else {
+                        coplet.setTemporaryAttribute(CACHE, data);
+                    }
+                }
+            }
+        }
+        // and now stream the data
+        if ( data != null ) {
+            XMLByteStreamInterpreter bi = new XMLByteStreamInterpreter();
+            bi.setContentHandler(contentHandler);
+            if ( contentHandler instanceof LexicalHandler ) {
+                bi.setLexicalHandler((LexicalHandler)contentHandler);
+            }
+            bi.deserialize(data);
+        }
+    }
+
+    /**
      * @see org.apache.cocoon.portal.coplet.adapter.CopletAdapter#init(org.apache.cocoon.portal.coplet.CopletInstanceData)
      */
     public void init(CopletInstanceData coplet) {
@@ -227,6 +365,105 @@
     throws SAXException {
         return false;
     }
+    /**
+     * This adapter listens for CopletInstanceEvents. Each event sets the cache invalid.
+     * @see org.apache.cocoon.portal.event.Receiver
+     */
+    public void inform(CopletInstanceEvent event, PortalService service) {
+        final CopletInstanceData coplet = event.getTarget();
+
+        // do we ignore SizingEvents
+        boolean ignoreSizing = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_IGNORE_SIZING_EVENTS,
Boolean.TRUE)).booleanValue();
+
+        if ( !ignoreSizing || !CopletInstanceDataFeatures.isSizingEvent(event)) {
+            boolean cleanupCache = true;
+            boolean ignoreSimpleSizing = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_IGNORE_SIMPLE_SIZING_EVENTS,
Boolean.FALSE)).booleanValue();
+            if ( ignoreSimpleSizing && CopletInstanceDataFeatures.isSizingEvent(event)
) {
+                int newSize = CopletInstanceDataFeatures.getSize(event);
+                int oldSize = coplet.getSize();
+                if (  (oldSize == CopletInstanceData.SIZE_NORMAL || oldSize == CopletInstanceData.SIZE_MINIMIZED
)
+                   && (newSize == CopletInstanceData.SIZE_NORMAL || newSize == CopletInstanceData.SIZE_MINIMIZED
)) {
+                    cleanupCache = false;
+                }
+            }
+            if ( cleanupCache ) {
+                // do we cache globally?
+                boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_CACHE_GLOBAL,
Boolean.FALSE)).booleanValue();
+                boolean cacheGlobalUseAttributes = ((Boolean)this.getConfiguration(coplet,
CONFIGURATION_CACHE_GLOBAL_USE_ATTRIBUTES, Boolean.FALSE)).booleanValue();
+                if ( cacheGlobal ) {
+                    if ( !cacheGlobalUseAttributes ) {
+                        final String key = this.getCacheKey(coplet);
+                        this.cache.remove(key);
+                    }
+                } else {
+                    coplet.removeTemporaryAttribute(CACHE);
+                }
+            }
+        }
+    }
+
+    /**
+     * Build the key for the global cache.
+     */
+    protected String getCacheKey(CopletInstanceData coplet) {
+        final Boolean useAttributes = (Boolean)this.getConfiguration(coplet,
+                                                            CONFIGURATION_CACHE_GLOBAL_USE_ATTRIBUTES,
+                                                            Boolean.FALSE);
+        if ( !useAttributes.booleanValue() ) {
+            return "coplet:" + coplet.getCopletData().getId();
+        }
+        final StringBuffer buffer = new StringBuffer("coplet:");
+        buffer.append(coplet.getCopletData().getId());
+        boolean hasParams = false;
+        // first add attributes:
+        // sort the keys
+        List keyList = new ArrayList(coplet.getAttributes().keySet());
+        Collections.sort(keyList);
+        Iterator i = keyList.iterator();
+        while ( i.hasNext() ) {
+            final Object name = i.next();
+            final Object value = coplet.getAttribute(name.toString());
+            if ( hasParams ) {
+                buffer.append('&');
+            } else {
+                buffer.append('?');
+                hasParams = true;
+            }
+            buffer.append(name.toString());
+            buffer.append('=');
+            if ( value != null ) {
+                try {
+                    buffer.append(NetUtils.encode(value.toString(), "utf-8"));
+                } catch (UnsupportedEncodingException ignore) {
+                    // we ignore this
+                }
+            }
+        }
+        // second add temporary attributes
+        keyList = new ArrayList(coplet.getTemporaryAttributes().keySet());
+        Collections.sort(keyList);
+        i = keyList.iterator();
+        while ( i.hasNext() ) {
+            final Object name = i.next();
+            final Object value = coplet.getTemporaryAttribute(name.toString());
+            if ( hasParams ) {
+                buffer.append('&');
+            } else {
+                buffer.append('?');
+                hasParams = true;
+            }
+            buffer.append(name.toString());
+            buffer.append('=');
+            if ( value != null ) {
+                try {
+                    buffer.append(NetUtils.encode(value.toString(), "utf-8"));
+                } catch (UnsupportedEncodingException ignore) {
+                    // we ignore this
+                }
+            }
+        }
+        return buffer.toString();            
+    }
 }
 
 final class LoaderThread implements Runnable {
@@ -248,7 +485,7 @@
 
     public void run() {
         try {
-            adapter.streamContent( this.coplet, this.handler );
+            adapter.streamContentAndCache( this.coplet, this.handler );
         } catch (Exception local) {
             this.exception = local;
         } finally {

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java
Tue Apr 11 13:07:12 2006
@@ -23,6 +23,7 @@
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.portal.LinkService;
+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.CopletLinkEvent;
@@ -36,9 +37,10 @@
  * This coplet adapter is used to connect to external applications that are 
  * plugged into the portal.
  *
+ * TODO: Decide if we still need this adapter.
  * @version $Id$
  */
-public class ApplicationCopletAdapter extends CachingURICopletAdapter {
+public class ApplicationCopletAdapter extends URICopletAdapter {
 
     /**
      * @see org.apache.cocoon.portal.coplet.adapter.impl.URICopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData,
java.lang.String, org.xml.sax.ContentHandler)
@@ -64,8 +66,8 @@
      * There is a special CopletLinkEvent with the uri "createNewCopletInstance", which is
the
      * trigger to create a new instance of the one that is the target of the event.
      */
-    public void handleCopletInstanceEvent(CopletInstanceEvent e) {
-        super.handleCopletInstanceEvent(e);
+    public void inform(CopletInstanceEvent e, PortalService service) {
+        super.inform(e, service);
 
         if ( e instanceof CopletLinkEvent ) {
             CopletLinkEvent event = (CopletLinkEvent) e;

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
Tue Apr 11 13:07:12 2006
@@ -29,7 +29,6 @@
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.portal.Constants;
-import org.apache.cocoon.portal.PortalService;
 import org.apache.cocoon.portal.coplet.CopletInstanceData;
 import org.apache.cocoon.portal.coplet.CopletInstanceDataFeatures;
 import org.apache.excalibur.source.Source;
@@ -68,16 +67,13 @@
         this.streamContent( coplet, uri, contentHandler);
     }
 
-    public void streamContent(final CopletInstanceData coplet, 
-                              final String uri,
-                              final ContentHandler contentHandler)
+    protected void streamContent(final CopletInstanceData coplet, 
+                                 final String uri,
+                                 final ContentHandler contentHandler)
     throws SAXException {
 		Source copletSource = null;
-		PortalService portalService = null;
 		try {
 			if (uri.startsWith("cocoon:")) {
-                portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
-
                 Boolean handlePars = (Boolean)this.getConfiguration( coplet, "handleParameters",
Boolean.FALSE);
 
                 String sourceUri = uri;
@@ -98,7 +94,7 @@
                 }
 
 				HashMap par = new HashMap();
-				par.put(Constants.PORTAL_NAME_KEY, portalService.getPortalName());
+				par.put(Constants.PORTAL_NAME_KEY, this.portalService.getPortalName());
 				par.put(Constants.COPLET_ID_KEY, coplet.getId());
 
 				copletSource = this.resolver.resolveURI(sourceUri, null, par);
@@ -110,11 +106,8 @@
 			throw new SAXException("IOException", ioe);
 		} catch (ProcessingException pe) {
 			throw new SAXException("ProcessingException", pe);
-		} catch (ServiceException ce) {
-			throw new SAXException("ServiceException", ce);
 		} finally {
 			this.resolver.release(copletSource);
-			this.manager.release(portalService);
 		}
     }
 

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java?rev=393302&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
Tue Apr 11 13:07:12 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.impl;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.portal.PortalManagerAspect;
+import org.apache.cocoon.portal.PortalManagerAspectPrepareContext;
+import org.apache.cocoon.portal.PortalManagerAspectRenderContext;
+import org.apache.cocoon.portal.PortalService;
+import org.apache.cocoon.portal.coplet.CopletInstanceData;
+import org.apache.cocoon.portal.coplet.CopletInstanceDataFeatures;
+import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * This aspect preloads all changed coplets.
+ * TODO - preload all coplets for the first page rendering (as changed list is empty)
+ * TODO - provide hook in CopletAdapter for preloading.
+ *
+ * @version $Id$
+ */
+public class PreloadPortalManagerAspect
+	extends AbstractLogEnabled
+	implements PortalManagerAspect {
+
+    /** Handler that simply ignores all sax events. */
+    protected static final ContentHandler nullHandler = new DefaultHandler();
+
+    /**
+     * @see org.apache.cocoon.portal.PortalManagerAspect#prepare(org.apache.cocoon.portal.PortalManagerAspectPrepareContext,
org.apache.cocoon.portal.PortalService)
+     */
+    public void prepare(PortalManagerAspectPrepareContext context,
+                        PortalService                     service)
+    throws ProcessingException {
+        // let's just invoke the next
+        context.invokeNext();
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.PortalManagerAspect#render(org.apache.cocoon.portal.PortalManagerAspectRenderContext,
org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void render(PortalManagerAspectRenderContext context,
+                       PortalService                    service,
+                       ContentHandler                   ch,
+                       Parameters                       parameters)
+    throws SAXException {
+        // we should be the first aspect for rendering
+        // preload all changed coplets
+        final List changedCoplets = CopletInstanceDataFeatures.getChangedCopletInstanceDataObjects(service);
+        final Iterator i = changedCoplets.iterator();
+        while (i.hasNext()) {
+            final CopletInstanceData cid = (CopletInstanceData)i.next();
+            final String adapterName = cid.getCopletData().getCopletBaseData().getCopletAdapterName();
+            final CopletAdapter adapter = service.getCopletAdapter(adapterName);
+            adapter.toSAX(cid, nullHandler );
+        }
+        // start "real" rendering
+        context.invokeNext(ch, parameters);
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PreloadPortalManagerAspect.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/portal.roles
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/portal.roles?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/portal.roles
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/portal.roles
Tue Apr 11 13:07:12 2006
@@ -60,6 +60,8 @@
     <role name="org.apache.cocoon.portal.PortalManagerAspectSelector"
           default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
 
+    <role name="org.apache.cocoon.portal.PortalManagerAspect/preload"
+          default-class="org.apache.cocoon.portal.impl.PreloadPortalManagerAspect"/>
 
   <!--+
       | Renderer Aspects
@@ -141,12 +143,6 @@
         +-->
     <role name="org.apache.cocoon.portal.coplet.adapter.CopletAdapter/uri"
           default-class="org.apache.cocoon.portal.coplet.adapter.impl.URICopletAdapter"/>
-
-    <!--+
-        | This is an extension of the uri adapter supporting caching the content.
-        +-->
-    <role name="org.apache.cocoon.portal.coplet.adapter.CopletAdapter/caching-uri"
-          default-class="org.apache.cocoon.portal.coplet.adapter.impl.CachingURICopletAdapter"/>
 
     <!--+
         |  This is the application adapter.

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/status.xml?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/status.xml (original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/status.xml Tue Apr 11 13:07:12 2006
@@ -66,6 +66,10 @@
  <changes>
   <release version="@version@" date="@date@">
     <action dev="CZ" type="add">
+      Unify coplet adapters: Caching is now supported by all adapters including
+      the portlet and wsrp adapters. Therefore the caching-uri adapter has been removed.
+    </action>
+    <action dev="CZ" type="add">
       Implement (hot)deployment for JSR 168 portlets.
     </action>
     <action dev="CZ" type="add">

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletbasedata/portal.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletbasedata/portal.xml?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletbasedata/portal.xml
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletbasedata/portal.xml
Tue Apr 11 13:07:12 2006
@@ -19,14 +19,8 @@
    <coplet-base-data id="URICoplet">
       <coplet-adapter>uri</coplet-adapter>
    </coplet-base-data>
-   <coplet-base-data id="CachingURICoplet">
-      <coplet-adapter>caching-uri</coplet-adapter>
-   </coplet-base-data>
    <coplet-base-data id="Portlet">
       <coplet-adapter>portlet</coplet-adapter>
-   </coplet-base-data>
-   <coplet-base-data id="Application">
-      <coplet-adapter>application</coplet-adapter>
    </coplet-base-data>
    <coplet-base-data id="WSRP">
       <coplet-adapter>wsrp</coplet-adapter>

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletdata/portal.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletdata/portal.xml?rev=393302&r1=393301&r2=393302&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletdata/portal.xml
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sample/src/main/resources/COB-INF/profiles/copletdata/portal.xml
Tue Apr 11 13:07:12 2006
@@ -140,7 +140,7 @@
    </coplet-data>
    <coplet-data id="Portal-Demo">
       <title>Introduction</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>uri</name>
          <value xsi:type="java:java.lang.String">cocoon:/coplets/docs/portal-demo.html</value>
@@ -212,7 +212,7 @@
      -->
    <coplet-data id="Gallery">
       <title>Picture Gallery</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
         <name>buffer</name>
         <value xsi:type="java:java.lang.Boolean">true</value>
@@ -244,7 +244,7 @@
    </coplet-data>
    <coplet-data id="GalleryViewer">
       <title>Gallery Viewer</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
         <name>buffer</name>
         <value xsi:type="java:java.lang.Boolean">true</value>
@@ -345,7 +345,7 @@
    </coplet-data>
    <coplet-data id="BasketSampleCopletWithInputProcess">
       <title>Coplet with Input Processing</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>group</name>
          <value xsi:type="java:java.lang.String">notepad</value>
@@ -381,7 +381,7 @@
    </coplet-data>
    <coplet-data id="BasketSampleCopletWithApp">
       <title>Coplet with Application</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>group</name>
          <value xsi:type="java:java.lang.String">request</value>
@@ -405,7 +405,7 @@
    </coplet-data>
    <coplet-data id="BasketSampleCopletList">
       <title>Coplet List</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>group</name>
          <value xsi:type="java:java.lang.String">request</value>
@@ -479,7 +479,7 @@
      -->
    <coplet-data id="app-test-one">
       <title>Application Test</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>buffer</name>
          <value xsi:type="java:java.lang.Boolean">true</value>
@@ -499,7 +499,7 @@
    </coplet-data>
    <coplet-data id="app-test-two">
       <title>Application Test</title>
-      <coplet-base-data>CachingURICoplet</coplet-base-data>
+      <coplet-base-data>URICoplet</coplet-base-data>
       <attribute>
          <name>buffer</name>
          <value xsi:type="java:java.lang.Boolean">true</value>



Mime
View raw message