cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r673733 - in /cocoon/trunk/blocks/cocoon-eventcache: cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/ cocoon-eventcache-sample/src/main/resources/COB-INF/ cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/
Date Thu, 03 Jul 2008 16:25:18 GMT
Author: reinhard
Date: Thu Jul  3 09:25:17 2008
New Revision: 673733

URL: http://svn.apache.org/viewvc?rev=673733&view=rev
Log:
migrate the EventAwareGenerator to Spring (done together with Lukas Lang)

Modified:
    cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/EventAwareGenerator.java
    cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/COB-INF/sitemap.xmap
    cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/cocoon-eventcache-sample.xml

Modified: cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/EventAwareGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/EventAwareGenerator.java?rev=673733&r1=673732&r2=673733&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/EventAwareGenerator.java
(original)
+++ cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-impl/src/main/java/org/apache/cocoon/samples/EventAwareGenerator.java
Thu Jul  3 09:25:17 2008
@@ -18,75 +18,81 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Map;
 
+import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.caching.validity.EventValidity;
 import org.apache.cocoon.caching.validity.NamedEvent;
+import org.apache.cocoon.el.objectmodel.ObjectModel;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.template.JXTemplateGenerator;
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.SAXException;
 
 /**
- * This is a sample generator to demonstrate the event aware caching.
- * We simply extend the JXTG.
+ * This is a sample generator to demonstrate the event aware caching. We simply extend the
JXTG.
+ * 
  * @version $Id$
  */
 public class EventAwareGenerator extends JXTemplateGenerator {
 
+    private Map oldObjectModel;
+
     /**
      * Generate the unique key for the cache.
-     *
-     * This key must be unique inside the space of this XSP page, it is used
-     * to find the page contents in the cache (if getValidity says that the
-     * contents are still valid).
-     *
+     * 
+     * This key must be unique inside the space of this XSP page, it is used to find the
page contents in the cache (if
+     * getValidity says that the contents are still valid).
+     * 
      * This method will be invoked before the getValidity() method.
-     *
-     * @return The generated key or null if the component
-     *         is currently not cacheable.
+     * 
+     * @return The generated key or null if the component is currently not cacheable.
      */
     public Serializable getKey() {
-        final Request request = ObjectModelHelper.getRequest(this.getObjectModel());
+        final Request request = ObjectModelHelper.getRequest(oldObjectModel);
         // for our test, pages having the same value of "pageKey" will share
         // the same cache location
-        String key = request.getParameter("pageKey") ;
-        return ((key==null||"".equals(key)) ? "one" : key);
+        String key = request.getParameter("pageKey");
+        return ((key == null || "".equals(key)) ? "one" : key);
     }
 
     /**
-     * Generate the validity object, tells the cache how long to
-     * keep contents having this key around.  In this case, it will 
-     * be until an Event is retrieved matching the NamedEvent created below.
-     *
-     * Before this method can be invoked the getKey() method
-     * will be invoked.
-     *
-     * @return The generated validity object or null if the
-     *         component is currently not cacheable.
+     * Generate the validity object, tells the cache how long to keep contents having this
key around. In this case, it
+     * will be until an Event is retrieved matching the NamedEvent created below.
+     * 
+     * Before this method can be invoked the getKey() method will be invoked.
+     * 
+     * @return The generated validity object or null if the component is currently not cacheable.
      */
     public SourceValidity getValidity() {
-        final Request request = ObjectModelHelper.getRequest(this.getObjectModel());
-        String key = request.getParameter("pageKey") ;
-        return new EventValidity(
-                   new NamedEvent(
-                       (key==null||"".equals(key)) ? "one" : key));
+        final Request request = ObjectModelHelper.getRequest(this.oldObjectModel);
+        String key = request.getParameter("pageKey");
+        return new EventValidity(new NamedEvent((key == null || "".equals(key)) ? "one" :
key));
+    }
+    
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
+            throws ProcessingException, SAXException, IOException {
+        this.oldObjectModel = objectModel;
+        super.setup(resolver, objectModel, src, parameters);
     }
 
-
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.apache.cocoon.generation.Generator#generate()
      */
-    public void generate() 
-    throws IOException, SAXException, ProcessingException {
+    public void generate() throws IOException, SAXException, ProcessingException {
         super.generate();
         // slowdown page generation.
         long DELAY_SECS = this.parameters.getParameterAsLong("DELAY_SECS", 2);
         try {
-          Thread.sleep(DELAY_SECS * 1000L);
+            Thread.sleep(DELAY_SECS * 1000L);
         } catch (InterruptedException ie) {
-          // Not much that can be done...
+            // Not much that can be done...
         }
     }
 }

Modified: cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/COB-INF/sitemap.xmap?rev=673733&r1=673732&r2=673733&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/COB-INF/sitemap.xmap
(original)
+++ cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/COB-INF/sitemap.xmap
Thu Jul  3 09:25:17 2008
@@ -15,30 +15,12 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-
-<!--+
-    | Event Cache Sample
-    |
-    | CVS $Id$
-    +-->
-
+<!-- $Id$ -->
 <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
-
-  <!-- =========================== Components =================================== -->
-
   <map:components>
-
-    <!-- =========================== Generators =================================== -->
-
-    <map:generators>
-      <map:generator name="sample" src="org.apache.cocoon.samples.EventAwareGenerator"
/>
-    </map:generators>
     <map:actions>
       <map:action name="cacheevent" src="org.apache.cocoon.acting.CacheEventAction" />
     </map:actions>
-
-    <!-- =========================== Pipes =================================== -->
-
     <map:pipes default="caching">
       <!-- A pipe must be defined configured to use the EventAware cache. -->
       <map:pipe name="event-aware" src="org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline">
@@ -47,14 +29,10 @@
     </map:pipes>
   </map:components>
 
-  <!-- =========================== Flowscripts =================================== -->
-
   <map:flow language="javascript">
     <map:script src="event.js" />
   </map:flow>
 
-  <!-- =========================== Views =================================== -->
-
   <map:views>
     <map:view from-label="content" name="content">
       <map:serialize type="xml" />
@@ -72,8 +50,6 @@
     </map:view>
   </map:views>
 
-  <!-- =========================== Pipelines =================================== -->
-
   <map:pipelines>
     <!-- Our content must occur in a pipeline configured to use our Event Aware cache
-->
     <map:pipeline type="event-aware">
@@ -81,12 +57,14 @@
       <map:match pattern="flow">
         <map:call function="cacheEvent" />
       </map:match>
+      
       <map:match pattern="action">
         <map:act type="cacheevent">
           <map:parameter name="event" value="{request-param:event}" />
         </map:act>
         <map:redirect-to uri="demo?pageKey={request-param:pageKey}&amp;rand={random:x}"
/>
       </map:match>
+      
       <map:match pattern="*">
         <map:generate type="event-cache-sample" src="eventcache.xml">
           <map:parameter name="DELAY_SECS" value="2" />
@@ -98,7 +76,7 @@
           <map:parameter name="service" value="servlet:style-default:/service/blocks/dynamic-page2html"
/>
         </map:serialize>
       </map:match>
+      
     </map:pipeline>
   </map:pipelines>
-</map:sitemap>
-
+</map:sitemap>
\ No newline at end of file

Modified: cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/cocoon-eventcache-sample.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/cocoon-eventcache-sample.xml?rev=673733&r1=673732&r2=673733&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/cocoon-eventcache-sample.xml
(original)
+++ cocoon/trunk/blocks/cocoon-eventcache/cocoon-eventcache-sample/src/main/resources/META-INF/cocoon/spring/cocoon-eventcache-sample.xml
Thu Jul  3 09:25:17 2008
@@ -24,10 +24,6 @@
                            http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd">
 
   <bean name="org.apache.cocoon.generation.Generator/event-cache-sample" class="org.apache.cocoon.samples.EventAwareGenerator"
-    scope="prototype">
-    <property name="saxParser" ref="org.apache.cocoon.core.xml.SAXParser" />
-    <property name="scriptManager" ref="org.apache.cocoon.template.script.ScriptManager"
/>
-    <property name="objectModel" ref="org.apache.cocoon.el.objectmodel.ObjectModel" />
   
-  </bean>
+    scope="prototype" parent="org.apache.cocoon.generation.Generator/jx" />
 
 </beans>
\ No newline at end of file



Mime
View raw message