cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 47280 - in cocoon/branches/BRANCH_2_1_X: . src/java/org/apache/cocoon/caching src/java/org/apache/cocoon/components/pipeline src/java/org/apache/cocoon/components/pipeline/impl
Date Mon, 27 Sep 2004 08:01:15 GMT
Author: cziegeler
Date: Mon Sep 27 01:01:15 2004
New Revision: 47280

Modified:
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/caching/CachedResponse.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Cache the mime-type of readers and serializers.

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/caching/CachedResponse.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/caching/CachedResponse.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/caching/CachedResponse.java	Mon
Sep 27 01:01:15 2004
@@ -28,7 +28,7 @@
  *
  * @since 2.1
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: CachedResponse.java,v 1.6 2004/03/05 13:02:45 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public class CachedResponse
         implements Serializable {
@@ -37,7 +37,8 @@
     protected final byte[]           response;
     protected Long                   expires;
     protected final long             lastModified;
-
+    protected String                 contentType;
+    
     /**
      * Create a new entry for the cache.
      *
@@ -128,4 +129,16 @@
         return lastModified;
     }
 
+    /**
+     * @return Returns the cached content type (or null).
+     */
+    public String getContentType() {
+        return this.contentType;
+    }
+    /**
+     * @param value The content type to cache.
+     */
+    public void setContentType(String value) {
+        this.contentType = value;
+    }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
Mon Sep 27 01:01:15 2004
@@ -188,7 +188,9 @@
      * Informs pipeline we have come across a branch point
      * Default Behaviour is do nothing
      */
-    public void informBranchPoint() {}
+    public void informBranchPoint() {
+        // this can be overwritten in subclasses
+    }
 
     /**
      * Set the generator that will be used as the initial step in the pipeline.
@@ -387,28 +389,6 @@
                     this.serializerParam
                 );
             }
-
-            if (this.lastConsumer == null) {
-                // internal processing: text/xml
-                environment.setContentType("text/xml");
-            } else {
-                String mimeType = this.serializer.getMimeType();
-                if (mimeType != null) {
-                    // we have a mimeType from the component itself
-                    environment.setContentType (mimeType);
-                } else if (serializerMimeType != null) {
-                    // there was a mimeType specified in the sitemap pipeline
-                    environment.setContentType (serializerMimeType);
-                } else if (this.sitemapSerializerMimeType != null) {
-                    // use the mimeType specified in the sitemap component declaration
-                    environment.setContentType (this.sitemapSerializerMimeType);
-                } else {
-                    // No mimeType available
-                    String message = "Unable to determine MIME type for " +
-                        environment.getURIPrefix() + "/" + environment.getURI();
-                    throw new ProcessingException(message);
-                }
-            }
         } catch (SAXException e) {
             throw new ProcessingException(
                 "Could not setup pipeline.",
@@ -485,10 +465,9 @@
             }
 
             return this.processReader(environment);
-        } else {
-            this.connectPipeline(environment);
-            return this.processXMLPipeline(environment);
         }
+        this.connectPipeline(environment);
+        return this.processXMLPipeline(environment);
     }
 
     /**
@@ -524,6 +503,8 @@
     protected boolean processXMLPipeline(Environment environment)
     throws ProcessingException {
 
+        this.setMimeTypeForSerializer(environment);
+        
         try {
             if (this.serializer != this.lastConsumer) {
                 // internal processing
@@ -560,16 +541,7 @@
     protected void setupReader(Environment environment)
     throws ProcessingException {
         try {
-            String mimeType;
             this.reader.setup(environment,environment.getObjectModel(),readerSource,readerParam);
-            mimeType = this.reader.getMimeType();
-            if ( mimeType != null ) {
-                environment.setContentType(mimeType);
-            } else if ( readerMimeType != null ) {
-                environment.setContentType(this.readerMimeType);
-            } else {
-                environment.setContentType(this.sitemapReaderMimeType);
-            }
             // set the expires parameter on the pipeline if the reader is configured with
one
             if (readerParam.isParameter("expires")) {
 	            // should this checking be done somewhere else??
@@ -584,12 +556,55 @@
         }
     }
 
+    /**
+     * Set the mime-type for a reader
+     * @param environment The current environment
+     */
+    protected void setMimeTypeForReader(Environment environment) {
+        String mimeType = this.reader.getMimeType();
+        if ( mimeType != null ) {
+            environment.setContentType(mimeType);
+        } else if ( readerMimeType != null ) {
+            environment.setContentType(this.readerMimeType);
+        } else {
+            environment.setContentType(this.sitemapReaderMimeType);
+        }
+    }
+    
+    /**
+     * Set the mime-type for a serializer
+     * @param environment The current environment
+     */
+    protected void setMimeTypeForSerializer(Environment environment) 
+    throws ProcessingException {
+        if (this.lastConsumer == null) {
+            // internal processing: text/xml
+            environment.setContentType("text/xml");
+        } else {
+            String mimeType = this.serializer.getMimeType();
+            if (mimeType != null) {
+                // we have a mimeType from the component itself
+                environment.setContentType (mimeType);
+            } else if (serializerMimeType != null) {
+                // there was a mimeType specified in the sitemap pipeline
+                environment.setContentType (serializerMimeType);
+            } else if (this.sitemapSerializerMimeType != null) {
+                // use the mimeType specified in the sitemap component declaration
+                environment.setContentType (this.sitemapSerializerMimeType);
+            } else {
+                // No mimeType available
+                String message = "Unable to determine MIME type for " +
+                    environment.getURIPrefix() + "/" + environment.getURI();
+                throw new ProcessingException(message);
+            }
+        }
+    }
+
     protected boolean checkIfModified(Environment environment,
                                         long lastModified)
     throws ProcessingException {
         // has the read resource been modified?
         if(!environment.isResponseModified(lastModified)) {
-
             // environment supports this, so we are finished
             environment.setResponseIsNotModified();
             return true;
@@ -604,6 +619,7 @@
     protected boolean processReader(Environment environment)
     throws ProcessingException {
         try {
+            this.setMimeTypeForReader(environment);
             if (this.reader.shouldSetContentLength()) {
                 ByteArrayOutputStream os = new ByteArrayOutputStream();
                 this.reader.setOutputStream(os);
@@ -674,10 +690,9 @@
         this.lastConsumer = consumer;
         if ( this.reader != null ) {
             throw new ProcessingException("Streaming of an internal pipeline is not possible
with a reader.");
-        } else {
-            this.connectPipeline(environment);
-            return this.processXMLPipeline(environment);
         }
+        this.connectPipeline(environment);
+        return this.processXMLPipeline(environment);
     }
 
     /**

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Mon Sep 27 01:01:15 2004
@@ -65,8 +65,8 @@
     /** The role name of the reader */
     protected String readerRole;
 
-    /** The cached byte stream */
-    protected byte[]           cachedResponse;
+    /** The cached response */
+    protected CachedResponse   cachedResponse;
     /** The timestamp of the cached byte stream */
     protected long             cachedLastModified;
 
@@ -180,17 +180,24 @@
                 return true;
             }
 
+            // set mime-type
+            if ( this.cachedResponse.getContentType() != null ) {
+                environment.setContentType(this.cachedResponse.getContentType());
+            } else {
+                this.setMimeTypeForSerializer(environment);
+            }
             try {
-                final OutputStream outputStream =
-                            environment.getOutputStream(0);
-                if (this.cachedResponse.length > 0) {
-                    environment.setContentLength(this.cachedResponse.length);
-                    outputStream.write(this.cachedResponse);
+                final OutputStream outputStream = environment.getOutputStream(0);
+                final byte[] content = this.cachedResponse.getResponse();
+                if (content.length > 0) {
+                    environment.setContentLength(content.length);
+                    outputStream.write(content);
                 }
             } catch (Exception e) {
                 handleException(e);
             }
         } else {
+            this.setMimeTypeForSerializer(environment);
             if (getLogger().isDebugEnabled() && this.toCacheKey != null) {
                 getLogger().debug("processXMLPipeline: caching content for further" +
                                   " requests of '" + environment.getURI() +
@@ -463,7 +470,7 @@
                                 ", ignoring all other cache settings. This entry expires
on "+
                                 new Date(responseExpires.longValue()));
                         }
-                        this.cachedResponse = response.getResponse();
+                        this.cachedResponse = response;
                         this.cachedLastModified = response.getLastModified();
                         return;
                     } else {
@@ -542,7 +549,7 @@
                         this.getLogger().debug("validatePipeline: using valid cached content
for '" + environment.getURI() + "'.");
                     }
                     // we are valid, ok that's it
-                    this.cachedResponse = response.getResponse();
+                    this.cachedResponse = response;
                     this.cachedLastModified = response.getLastModified();
                     this.toCacheSourceValidities = fromCacheValidityObjects;
                 } else {
@@ -732,6 +739,11 @@
                             byte[] response = cachedObject.getResponse();
                             if (response.length > 0) {
                                 usedCache = true;
+                                if ( cachedObject.getContentType() != null ) {
+                                    environment.setContentType(cachedObject.getContentType());
+                                } else {
+                                    this.setMimeTypeForReader(environment);
+                                }
                                 outputStream = environment.getOutputStream(0);
                                 environment.setContentLength(response.length);
                                 outputStream.write(response);
@@ -771,6 +783,7 @@
                     }
                 }
 
+                this.setMimeTypeForReader(environment);
                 if (this.reader.shouldSetContentLength()) {
                     ByteArrayOutputStream os = new ByteArrayOutputStream();
                     this.reader.setOutputStream(os);
@@ -790,10 +803,12 @@
 
                 // store the response
                 if (pcKey != null) {
+                    final CachedResponse res = new CachedResponse( new SourceValidity[] {readerValidity},
+                            ((CachingOutputStream)outputStream).getContent());
+                    res.setContentType(environment.getContentType());
                     this.cache.store(
                         pcKey,
-                        new CachedResponse( new SourceValidity[] {readerValidity},
-                                            ((CachingOutputStream)outputStream).getContent())
+                        res
                     );
                 }
             }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
Mon Sep 27 01:01:15 2004
@@ -41,7 +41,7 @@
  *
  * @since 2.1
  * @author <a href="mailto:Michael.Melhem@managesoft.com">Michael Melhem</a>
- * @version CVS $Id: CachingPointProcessingPipeline.java,v 1.6 2004/03/05 13:02:50 bdelacretaz
Exp $
+ * @version CVS $Id$
  */
 public class CachingPointProcessingPipeline
     extends AbstractCachingProcessingPipeline {
@@ -50,7 +50,7 @@
     protected ArrayList xmlSerializerArray = new ArrayList();
     protected boolean nextIsCachePoint = false;
     protected String autoCachingPointSwitch;
-    protected  boolean autoCachingPoint = true;
+    protected boolean autoCachingPoint = true;
 
 
    /**
@@ -79,9 +79,9 @@
         }
     }
 
-   /**
-    * Set the generator.
-    */
+    /**
+     * Set the generator.
+     */
     public void setGenerator (String role, String source, Parameters param, Parameters hintParam)

     throws ProcessingException {
         super.setGenerator(role, source, param, hintParam);
@@ -94,9 +94,7 @@
             if (this.getLogger().isDebugEnabled()) {
                 getLogger().debug("generator caching-point pipeline-hint is set to: " + pipelinehint);
             }
-        }
-        catch (Exception ex)
-        {
+        } catch (Exception ex) {
             if (this.getLogger().isWarnEnabled()) {
                 getLogger().warn("caching-point hint Exception, pipeline-hint ignored: "
+ ex);
             }
@@ -125,9 +123,7 @@
             if (this.getLogger().isDebugEnabled()) {
                 getLogger().debug("transformer caching-point pipeline-hint is set to: " +
pipelinehint);
             }
-        }
-        catch (Exception ex)
-        {
+        } catch (Exception ex) {
             if (this.getLogger().isWarnEnabled()) {
                 getLogger().warn("caching-point hint Exception, pipeline-hint ignored: "
+ ex);
             }
@@ -155,16 +151,17 @@
      */
     public void informBranchPoint() {
 
-        if (this.generator == null)
-        return;
-
-    if (!this.autoCachingPoint)
-        return;
+        if (this.generator == null) {
+            return;
+        }
+        if (!this.autoCachingPoint) {
+            return;
+        }   
 
         this.nextIsCachePoint = true;
-         if (this.getLogger().isDebugEnabled()) {
-           this.getLogger().debug("Informed Pipeline of branch point");
-         }
+        if (this.getLogger().isDebugEnabled()) {
+            this.getLogger().debug("Informed Pipeline of branch point");
+        }
     }
 
     /**
@@ -180,6 +177,7 @@
                 }
                 CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
                                           ((CachingOutputStream)os).getContent());
+                response.setContentType(environment.getContentType());
                 this.cache.store(this.toCacheKey.copy(),
                                  response);
                 //

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
Mon Sep 27 01:01:15 2004
@@ -37,7 +37,7 @@
  *
  * @since 2.1
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: CachingProcessingPipeline.java,v 1.6 2004/05/06 19:34:13 upayavira Exp
$
+ * @version CVS $Id$
  */
 public class CachingProcessingPipeline
     extends AbstractCachingProcessingPipeline {
@@ -53,6 +53,7 @@
                 CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
                                           ((CachingOutputStream)os).getContent(),
                                           expiresObj);
+                response.setContentType(environment.getContentType());
                 this.cache.store(this.toCacheKey,
                                  response);
             } else {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml	Mon Sep 27 01:01:15 2004
@@ -204,6 +204,9 @@
 
   <changes>
  <release version="@version@" date="@date@">
+   <action dev="CZ" type="update">
+     Cache the mime-type of readers and serializers.
+   </action>
    <action dev="AG" type="fix" fixes-bug="30372" due-to="Johnson Hsu" due-to-email="johnson@soho.club.tw">
       The daylight time cause error when timezone is CST. Updated icu4j to 3.0.
    </action>

Mime
View raw message