cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r586256 - in /cocoon/branches/BRANCH_2_1_X: src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java status.xml
Date Fri, 19 Oct 2007 04:06:50 GMT
Author: joerg
Date: Thu Oct 18 21:06:50 2007
New Revision: 586256

URL: http://svn.apache.org/viewvc?rev=586256&view=rev
Log:
backport COCOON-1354,
formatting/limiting diffs to trunk as much as possible

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java?rev=586256&r1=586255&r2=586256&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
Thu Oct 18 21:06:50 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You 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.
@@ -27,14 +27,16 @@
 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
 import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.sitemap.PatternException;
+
 /**
- *
  * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
  * @version CVS $Id$
  */
-public class SerializeNode extends PipelineEventComponentProcessingNode implements ParameterizableProcessingNode
{
+public class SerializeNode extends PipelineEventComponentProcessingNode
+                           implements ParameterizableProcessingNode {
+
+    private static final int DEFAULT_STATUS_CODE = 200;
 
     private String serializerName;
 
@@ -42,7 +44,7 @@
 
     private VariableResolver mimeType;
 
-    private int statusCode;
+    private VariableResolver statusCode;
 
     private Map parameters;
 
@@ -54,7 +56,10 @@
      * @param mimeType the mime-type, or <code>null</code> not specified.
      * @param statusCode the HTTP response status code, or <code>-1</code> if
not specified.
      */
-    public SerializeNode(String name, VariableResolver source, VariableResolver mimeType,
int statusCode) throws PatternException {
+    public SerializeNode(String name,
+                         VariableResolver source,
+                         VariableResolver mimeType,
+                         VariableResolver statusCode) {
         this.serializerName = name;
         this.source = source;
         this.mimeType = mimeType;
@@ -65,12 +70,15 @@
         this.parameters = parameterMap;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment,
org.apache.cocoon.components.treeprocessor.InvokeContext)
+     */
     public final boolean invoke(Environment env, InvokeContext context)
     throws Exception {
 
         // Check view
         if (this.views != null) {
-	   
+
             //inform the pipeline that we have a branch point
             context.getProcessingPipeline().informBranchPoint();
 
@@ -88,41 +96,54 @@
                 }
             }
         }
-        
-        Map objectModel = env.getObjectModel();
-        ProcessingPipeline pipeline = context.getProcessingPipeline();
+
+        final Map objectModel = env.getObjectModel();
+        final ProcessingPipeline pipeline = context.getProcessingPipeline();
 
         // Perform link translation if requested
         if (objectModel.containsKey(Constants.LINK_OBJECT)) {
             pipeline.addTransformer("<translator>", null, Parameters.EMPTY_PARAMETERS,
Parameters.EMPTY_PARAMETERS);
         }
-        
+
         if (objectModel.containsKey(Constants.LINK_COLLECTION_OBJECT) && env.isExternal())
{
             pipeline.addTransformer("<gatherer>", null, Parameters.EMPTY_PARAMETERS,
Parameters.EMPTY_PARAMETERS);
         }
 
-        pipeline.setSerializer(
-            this.serializerName,
-            source.resolve(context, objectModel),
-            VariableResolver.buildParameters(this.parameters, context, objectModel),
-            this.pipelineHints == null
+        String type = this.serializerName;
+        String source = this.source.resolve(context, objectModel);
+        Parameters parameters = VariableResolver.buildParameters(this.parameters, context,
objectModel);
+        Parameters hintParameters = this.pipelineHints == null
                 ? Parameters.EMPTY_PARAMETERS
-                : VariableResolver.buildParameters(this.pipelineHints, context, objectModel),
-            this.mimeType.resolve(context, env.getObjectModel())
-        );
-
-        // Set status code if there is one
-        if (this.statusCode >= 0) {
-            env.setStatus(this.statusCode);
+                : VariableResolver.buildParameters(this.pipelineHints, context, objectModel);
+        String mimeType = this.mimeType.resolve(context, objectModel);
+
+        pipeline.setSerializer(type,
+                               source,
+                               parameters,
+                               hintParameters,
+                               mimeType);
+
+        // Set status code *only* if there is one - do not override status
+        // code if it was set elsewhere.
+        String statusCodeString = this.statusCode.resolve(context, objectModel);
+        if (statusCodeString != null) {
+            int statusCodeInt = DEFAULT_STATUS_CODE;
+            try {
+                statusCodeInt = Integer.parseInt(statusCodeString);
+            } catch (NumberFormatException e) {
+                getLogger().warn("Status code value '" + statusCodeString + "' is not an
integer. " +
+                                 "Using " + DEFAULT_STATUS_CODE + " instead.", e);
+            }
+            if (statusCodeInt >= 0) {
+                env.setStatus(statusCodeInt);
+            }
         }
 
-        if (! context.isBuildingPipelineOnly()) {
+        if (!context.isBuildingPipelineOnly()) {
             // Process pipeline
             return pipeline.process(env);
-
-        } else {
-            // Return true : pipeline is finished.
-            return true;
         }
+        // Return true : pipeline is finished.
+        return true;
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java?rev=586256&r1=586255&r2=586256&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
Thu Oct 18 21:06:50 2007
@@ -16,23 +16,21 @@
  */
 package org.apache.cocoon.components.treeprocessor.sitemap;
 
+import java.util.Collection;
+import java.util.Map;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
 import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
-
 import org.apache.cocoon.serialization.Serializer;
 
-import java.util.Collection;
-import java.util.Map;
-
 /**
  *
  * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  * @version CVS $Id$
  */
-
 public class SerializeNodeBuilder extends AbstractProcessingNodeBuilder
   implements LinkedProcessingNodeBuilder {
 
@@ -50,14 +48,16 @@
 
         String type = this.treeBuilder.getTypeForStatement(config, Serializer.ROLE + "Selector");
 
-        this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Serializer.ROLE,
type, config);
-        this.pipelineHints = ((SitemapLanguage)this.treeBuilder).getHintsForStatement(Serializer.ROLE,
type, config);
+        SitemapLanguage sitemapBuilder = (SitemapLanguage)this.treeBuilder;
+
+        this.views = sitemapBuilder.getViewsForStatement(Serializer.ROLE, type, config);
+        this.pipelineHints = sitemapBuilder.getHintsForStatement(Serializer.ROLE, type, config);
 
         this.node = new SerializeNode(
             type,
             VariableResolverFactory.getResolver(config.getAttribute("src", null), this.manager),
             VariableResolverFactory.getResolver(config.getAttribute("mime-type", null), this.manager),
-            config.getAttributeAsInteger("status-code", -1)
+            VariableResolverFactory.getResolver(config.getAttribute("status-code", null),
this.manager)
         );
         this.node.setPipelineHints(this.pipelineHints);
         return this.treeBuilder.setupNode(node, config);

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=586256&r1=586255&r2=586256&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Oct 18 21:06:50 2007
@@ -182,6 +182,9 @@
 
   <changes>
   <release version="2.1.11" date="TBD">
+    <action dev="JH" type="add" fixes-bug="COCOON-1354" due-to="Jochen Seifarth" due-to-email="jochen.seifarth@web.de">
+      &lt;map:serialize status-code=&quot;{}&quot;/&gt; supports variable
resolution.
+    </action>
     <action dev="VG" type="fix">
       XMLDB Block: Fix collection URLs in XMLDBSource. Fixes URL resolution and 'Mount DB'
sample.
     </action>



Mime
View raw message