forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r447311 - in /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher: default.plugin.properties.xml internal.xmap src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Date Mon, 18 Sep 2006 07:51:11 GMT
Author: thorsten
Date: Mon Sep 18 00:51:10 2006
New Revision: 447311

URL: http://svn.apache.org/viewvc?view=rev&rev=447311
Log:
FOR-931
Activating enhanced caching. We are using now an AggregateValidity over all contracts and
their raw data
(if exists). Still we can move some methods (marked with *) to the startDocument method and
make the jx 
generator cacheable. You can turn the caching on/off by either define it in your f.p.x or
on a request base
by adding "?dispatcher.caching=off" to the requested url. 

Modified:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/default.plugin.properties.xml
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/default.plugin.properties.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/default.plugin.properties.xml?view=diff&rev=447311&r1=447310&r2=447311
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/default.plugin.properties.xml
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/default.plugin.properties.xml
Mon Sep 18 00:51:10 2006
@@ -22,4 +22,5 @@
   <property name="dispatcher.fallback.theme-ext" value=".fv"/>
   <property name="dispatcher.themer" value="org.apache.forrest.themes.core"/>
   <property name="dispatcher.home" value="org.apache.forrest.plugin.internal.dispatcher"/>
+  <property name="dispatcher.caching" value="on" />
 </properties>

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap?view=diff&rev=447311&r1=447310&r2=447311
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap
Mon Sep 18 00:51:10 2006
@@ -169,6 +169,7 @@
         <map:transform type="dispatcher">
           <map:parameter name="cacheKey" value="{0}" />
           <map:parameter name="validityFile" value="cocoon:/resolve.structurer.{1}" />
+          <map:parameter name="dispatcher.caching" value="{forrest:dispatcher.caching}"
/>
           <map:parameter name="request" value="{1}" />
           <map:parameter name="type" value="internal{2}" />
         </map:transform>
@@ -183,6 +184,7 @@
         <map:transform type="dispatcher">
           <map:parameter name="cacheKey" value="{0}" />
           <map:parameter name="validityFile" value="cocoon:/resolve.structurer.{1}" />
+          <map:parameter name="dispatcher.caching" value="{forrest:dispatcher.caching}"
/>
           <map:parameter name="request" value="{1}" />
           <map:parameter name="type" value="css" />
         </map:transform>
@@ -206,6 +208,7 @@
         <map:transform type="dispatcher">
           <map:parameter name="cacheKey" value="{0}" />
           <map:parameter name="validityFile" value="cocoon:/resolve.structurer.{1}" />
+          <map:parameter name="dispatcher.caching" value="{forrest:dispatcher.caching}"
/>
           <map:parameter name="request" value="{1}" />
           <map:parameter name="type" value="xhtml2" />
         </map:transform>

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?view=diff&rev=447311&r1=447310&r2=447311
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Mon Sep 18 00:51:10 2006
@@ -19,7 +19,6 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
-import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -46,6 +45,7 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.AggregatedValidity;
 import org.apache.excalibur.xml.xpath.XPathProcessor;
 import org.apache.forrest.dispatcher.ContractBean;
 import org.apache.forrest.dispatcher.ContractBeanDOMImpl;
@@ -196,7 +196,9 @@
 
     private Document defaultProperties;
 
-    private SourceValidity validity;
+    private AggregatedValidity validity;
+
+    private String validityOverride;
 
     public static final String HOOKS_TRANSFORMER_PARAMETER = "hooksTransformer";
 
@@ -206,6 +208,13 @@
     public static final String CACHE_PARAMETER = "cacheKey";
     public static final String VALIDITY_PARAMETER = "validityFile";
 
+    private static final String VALIDITY_OVERRIDE_PARAMETER = "dispatcher.caching";
+    
+    private static final String CACHING_OFF = "off";
+    
+    private static final String CACHING_ON = "on";
+    
+
     /**
      * Constructor Set the namespace
      */
@@ -230,6 +239,19 @@
      *         component is currently not cacheable.
      */
     public SourceValidity getValidity() {
+//      You can either request URL?dispatcher.caching=off
+        // or add this property to forrest.properties.xml
+        // to force a SourceValidity.INVALID
+        if(null!=validityFile&!(validityOverride.equals(CACHING_OFF))){
+            this.validity= new AggregatedValidity();
+            try {
+                this.validity.add(m_resolver.resolveURI(validityFile).getValidity());
+            } catch (Exception e) {
+                getLogger().error(e.getMessage());
+            }
+        }
+        else 
+            this.validity=null;
         return this.validity;
     }
 
@@ -258,6 +280,7 @@
      */
     public void recycle() {
         localRecycle();
+        this.validity = null;
         super.recycle();
 
     }
@@ -296,19 +319,14 @@
         this.requestId= parameters.getParameter(
                 DISPATCHER_REQUEST_ATTRIBUTE, null);
         this.cacheKey = parameters.getParameter(
-                this.CACHE_PARAMETER, null);
+                CACHE_PARAMETER, null);
         if(null==this.cacheKey) getLogger().warn("Caching not activated! Declare the CACHE_KEY_PARAMETER="+CACHE_PARAMETER+"
in your sitemap.");
         this.validityFile = parameters.getParameter(
-                this.VALIDITY_PARAMETER, null);
-        // FIXME: We are taking here a shortcut that we need to enhance ASAP
-        // We assume that all contracts that a structurer may include
-        // have not changed, which may the wrong assumption.
-        // The workaround is to do a touch on the $validityFile
-        // to force a SourceValidity.INVALID
-        if(null!=validityFile)
-            this.validity=m_resolver.resolveURI(validityFile).getValidity();
-        else 
-            this.validity=null;
+                VALIDITY_PARAMETER, null);
+        this.validityOverride = parameters.getParameter(
+                VALIDITY_OVERRIDE_PARAMETER, "");
+        this.cacheKey+=validityOverride;
+        
         if (requestId == null) {
             String error = "dispatcherError:\n"
                     + "You have to set the \"request\" parameter in the sitemap!";
@@ -336,16 +354,7 @@
             throw new ProcessingException(error);
         }
         parameterHelper.put(STRUCTURER_FORMAT_ATTRIBUTE, requestedFormat);
-        /*
-         * this.pathXSL = parameters.getParameter(PATH_PARAMETER,null); if
-         * (this.pathXSL==null){ String warning = "dispatcherError:\n" + "You
-         * did not set up the \"path\" parameter in the sitemap, we are not
-         * going to support default variables in contracts." + " Meaning that
-         * you are not able to use e.g. $skin-img-dir, if you do the contract
-         * bean implementation will throw an exception.";
-         * getLogger().warn(warning); }
-         * parameterHelper.put(PATH_PARAMETER,pathXSL);
-         */
+
         this.hooksXSL = parameters.getParameter(HOOKS_TRANSFORMER_PARAMETER,
                 null);
         try {
@@ -673,6 +682,15 @@
                 String contractUri = ContractBean.CONTRACT_RESOLVE_PREFIX + "."
                         + currentFormat + "." + value;
                 try {
+                    // Adding the contract to the validity object.
+                    // As soon the contract changes we want a rebuild of 
+                    // the page and not the cached object.
+                    if(!validityOverride.equals(CACHING_OFF)) {
+                        SourceValidity contractValidityId = m_resolver.resolveURI(contractUri).getValidity();
+//                      we cannot allow null in an AggregatedValidity
+                        if (null!=contractValidityId)
+                            this.validity.add(contractValidityId);
+                    }
                     Document doc = org.apache.forrest.dispatcher.util.SourceUtil
                             .readDOM(contractUri, this.manager);
                     contract.setContractImpl(doc, contractUri);
@@ -699,6 +717,15 @@
                 // contract is a nugget-contract
                 contract.setNugget(true);
                 try {
+                    // Adding the raw data to the validity object.
+                    // As soon the raw data changes we want a rebuild of 
+                    // the page and not the cached object.
+                    if(!validityOverride.equals(CACHING_OFF)) {
+                        SourceValidity contractValidityRaw = m_resolver.resolveURI(value).getValidity();
+                        // we cannot allow null in an AggregatedValidity
+                        if(null!=contractValidityRaw)
+                            this.validity.add(contractValidityRaw);
+                    }
                     Document doc = org.apache.forrest.dispatcher.util.SourceUtil
                             .readDOM(value, this.manager);
                     contract.setContractRawData(doc);



Mime
View raw message