You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2001/11/18 21:58:45 UTC

cvs commit: xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap ActNode.java ActNodeBuilder.java GenerateNode.java GenerateNodeBuilder.java MatchNode.java MatchNodeBuilder.java PreparableMatchNode.java ReadNode.java ReadNodeBuilder.java RedirectToNodeBuilder.java RedirectToURINode.java SerializeNode.java SerializeNodeBuilder.java TransformNode.java TransformNodeBuilder.java ComponentsNodeBuilder.java PipelineNode.java PipelineNodeBuilder.java PipelinesNode.java PipelinesNodeBuilder.java SitemapNodeBuilder.java ActionNode.java GeneratorNode.java GeneratorNodeBuilder.java

sylvain     01/11/18 12:58:45

  Modified:    scratchpad/src/org/apache/cocoon/treeprocessor
                        AbstractParentProcessingNode.java
                        AbstractParentProcessingNodeBuilder.java
                        ListOfMapsResolver.java TreeBuilder.java
                        TreeProcessor.java treeprocessor.xconf
               scratchpad/src/org/apache/cocoon/treeprocessor/sitemap
                        ComponentsNodeBuilder.java PipelineNode.java
                        PipelineNodeBuilder.java PipelinesNode.java
                        PipelinesNodeBuilder.java SitemapNodeBuilder.java
  Added:       scratchpad/src/org/apache/cocoon/treeprocessor NullNode.java
                        NullNodeBuilder.java
                        SimpleParentProcessingNode.java
                        SimpleSelectorProcessingNode.java
               scratchpad/src/org/apache/cocoon/treeprocessor/sitemap
                        ActNode.java ActNodeBuilder.java GenerateNode.java
                        GenerateNodeBuilder.java MatchNode.java
                        MatchNodeBuilder.java PreparableMatchNode.java
                        ReadNode.java ReadNodeBuilder.java
                        RedirectToNodeBuilder.java RedirectToURINode.java
                        SerializeNode.java SerializeNodeBuilder.java
                        TransformNode.java TransformNodeBuilder.java
  Removed:     scratchpad/src/org/apache/cocoon/treeprocessor/sitemap
                        ActionNode.java GeneratorNode.java
                        GeneratorNodeBuilder.java
  Log:
  Starts working ! Many features still to implement (search for 'NullNode' in treeprocessor.xconf).
  "/" doesn't match (??) : need to request "welcome" to see the welcome page
  
  Revision  Changes    Path
  1.3       +10 -2     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/AbstractParentProcessingNode.java
  
  Index: AbstractParentProcessingNode.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/AbstractParentProcessingNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractParentProcessingNode.java	2001/11/12 18:07:43	1.2
  +++ AbstractParentProcessingNode.java	2001/11/18 20:58:44	1.3
  @@ -8,7 +8,8 @@
   
   package org.apache.cocoon.treeprocessor;
   
  -import org.apache.avalon.framework.logger.AbstractLoggable;
  +
  +import org.apache.log.Logger;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
  @@ -19,11 +20,17 @@
   /**
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
    */
   
   public abstract class AbstractParentProcessingNode extends AbstractProcessingNode {
   
  +    private static Logger logger;
  +    
  +    public static void setStaticLogger(Logger log) {
  +        logger = log;
  +    }
  +
       /**
        * Invoke all nodes of a node array in order, until one succeeds.
        *
  @@ -59,6 +66,7 @@
         throws Exception {
           
           for (int i = 0; i < nodes.length; i++) {
  +            logger.debug("Invoking node " + nodes[i] + " at " + nodes[i].getLocation());
               if (nodes[i].invoke(env, pipeline, eventPipeline, listOfMaps)) {
                   return true;
               }
  
  
  
  1.3       +32 -23    xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/AbstractParentProcessingNodeBuilder.java
  
  Index: AbstractParentProcessingNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/AbstractParentProcessingNodeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractParentProcessingNodeBuilder.java	2001/11/12 18:07:43	1.2
  +++ AbstractParentProcessingNodeBuilder.java	2001/11/18 20:58:44	1.3
  @@ -22,7 +22,7 @@
    * children nodes.
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
    */
   
   
  @@ -55,28 +55,36 @@
           for (int i = 0; i < children.length; i++) {
               
               Configuration child = children[i];
  -            checkNamespace(child);
               String name = child.getName();
  -            
  -            // Is this element to be ignored ?
  -            if (ignoredChildren != null && ignoredChildren.contains(name)) {
  -                getLogger().debug("Element '" + name + "' is ignored for building children of element '" +
  -                    config.getName() + "'");
  -
  -                continue;
  +            try {
  +                checkNamespace(child);
  +                
  +                // Is this element to be ignored ?
  +                if (ignoredChildren != null && ignoredChildren.contains(name)) {
  +                    getLogger().debug("Element '" + name + "' is ignored for building children of element '" +
  +                        config.getName() + "'");
  +    
  +                    continue;
  +                }
  +                
  +                // Is it allowed ?
  +                if ( (allowedChildren != null && !allowedChildren.contains(name)) ||
  +                     (forbiddenChildren != null && forbiddenChildren.contains(name)) ) {
  +                    throw new ConfigurationException("Element '" + name + "' is not allowed at " +
  +                        child.getLocation());
  +                }
  +                
  +                // OK : get a builder.
  +                ProcessingNodeBuilder childBuilder = this.treeBuilder.createNodeBuilder(child);
  +                childBuilder.buildNode(child, buildModel);
  +                result.add(childBuilder);
  +                
  +            } catch(ConfigurationException ce) {
  +                throw ce;
  +            } catch(Exception e) {
  +                throw new ConfigurationException("Error while creating node '" + name +
  +                    "' at " + child.getLocation(), e);
               }
  -            
  -            // Is it allowed ?
  -            if ( (allowedChildren != null && !allowedChildren.contains(name)) ||
  -                 (forbiddenChildren != null && forbiddenChildren.contains(name)) ) {
  -                throw new ConfigurationException("Element '" + name + "' is not allowed at " +
  -                    child.getLocation());
  -            }
  -            
  -            // OK : get a builder.
  -            ProcessingNodeBuilder childBuilder = this.treeBuilder.createNodeBuilder(child);
  -            childBuilder.buildNode(child, buildModel);
  -            result.add(childBuilder);
           }
           
           return result;
  @@ -110,14 +118,15 @@
       }
       
       /**
  -     * Splits the value of a Configuration in a Collection of Strings.
  +     * Splits the value of a Configuration in a Collection of Strings. Splitting
  +     * occurs at space characters (incl. line breaks) and comma.
        *
        * @return a collection of Strings, or null if <code>config</code> has no value.
        */
       private Collection getStringCollection(Configuration config) {
           String s = config.getValue(null);
           
  -        return (s == null) ? null : Arrays.asList(StringUtils.split(s, ", "));
  +        return (s == null) ? null : Arrays.asList(StringUtils.split(s, ", \t\n\r"));
       }
   
   }
  
  
  
  1.3       +18 -7     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/ListOfMapsResolver.java
  
  Index: ListOfMapsResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/ListOfMapsResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ListOfMapsResolver.java	2001/11/12 18:07:43	1.2
  +++ ListOfMapsResolver.java	2001/11/18 20:58:44	1.3
  @@ -8,7 +8,6 @@
   
   package org.apache.cocoon.treeprocessor;
   
  -import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.parameters.Parameters;
   
   import org.apache.cocoon.sitemap.PatternException;
  @@ -21,10 +20,10 @@
    * Utility class for handling {...} pattern substitutions from a List of Maps.
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
    */
   
  -public abstract class ListOfMapsResolver extends AbstractLoggable {
  +public abstract class ListOfMapsResolver {
       
       /**
        * An empty <code>Parameters</code> object, returned by <code>buildParameters()</code>
  @@ -137,14 +136,20 @@
        * No-op resolver for expressions that don't need to be resolved.
        */
       private static class NullResolver extends ListOfMapsResolver {
  +        private String originalExpr;
           private String expression = null;
   
           public NullResolver(String expression) {
               if (expression != null) {
  +                this.originalExpr = expression;
                   this.expression = this.unescape(expression);
               }
           }
           
  +        public String toString() {
  +            return this.originalExpr;
  +        }
  +        
           public String resolve(List listOfMaps) {
               return this.expression;
           }
  @@ -158,12 +163,18 @@
   // TODO : for now, just borrowed from AbstractSitemap, but the
   // pattern should be precompiled for faster substitution.
       private static class RealResolver extends ListOfMapsResolver {
  +        private String originalExpr;
           private String expression;
           
           public RealResolver(String expression) throws PatternException {
  +            this.originalExpr = expression;
               this.expression = expression;
           }
           
  +        public String toString() {
  +            return this.originalExpr;
  +        }
  +
           public String resolve(List listOfMaps) throws PatternException {
               if (expression == null) {
                   return null;
  @@ -198,9 +209,9 @@
                       Object value = ((Map)listOfMaps.get(k)).get(s);
                       if (value != null){
                           result.append(value.toString());
  -                        getLogger().debug("Substitute evaluated value for " + s + " as " + value);
  +                        //getLogger().debug("Substitute evaluated value for " + s + " as " + value);
                       }else{
  -                        getLogger().warn("Substitute: value not found for " + s + " while evaluating " + expression);
  +                        //getLogger().warn("Substitute: value not found for " + s + " while evaluating " + expression);
                       }
                   }
                   if (ii < expression.length()) {
  @@ -208,9 +219,9 @@
                   }
                   return (result.toString());
               } catch (Exception e) {
  -                getLogger().error("AbstractSitemap:substitute()", e);
  +                //getLogger().error("AbstractSitemap:substitute()", e);
                   throw new PatternException("error occurred during evaluation of expression \"" + expression + "\" at position " +
  -                    (i + 1) + "\n" + e.getMessage());
  +                    (i + 1) + " : " + e.getMessage(), e);
               }
           }
       }
  
  
  
  1.3       +13 -16    xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeBuilder.java
  
  Index: TreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TreeBuilder.java	2001/11/12 18:07:43	1.2
  +++ TreeBuilder.java	2001/11/18 20:58:44	1.3
  @@ -34,15 +34,17 @@
   
   import java.util.HashMap;
   import java.util.Map;
  +import org.apache.avalon.excalibur.component.RoleManageable;
  +import org.apache.avalon.excalibur.component.RoleManager;
   
   /**
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
    */
   
   public class TreeBuilder extends AbstractLoggable implements
  -  Composable, Configurable, Contextualizable, LogKitManageable {
  +  Composable, Configurable, Contextualizable, LogKitManageable, RoleManageable {
       
       /**
        * The categories of node Maps.
  @@ -62,12 +64,12 @@
   
       private ComponentManager parentManager;
       
  +    private RoleManager roleManager;
  +    
       private TreeBuilderComponentManager manager;
       
       private ExcaliburComponentSelector builderSelector;
       
  -    private DefaultRoleManager emptyRoleManager;
  -    
       private String namespace;
       
       private String languageName;
  @@ -85,26 +87,20 @@
       public void compose(ComponentManager manager) throws ComponentException {
           this.parentManager = manager;
           
  -        // Setup role manager for the component manager
  -        // FIXME : what roles should we put here ? Pipelines and Connector roles from sitemap.roles ?
  -        this.emptyRoleManager = new DefaultRoleManager();
  -        this.emptyRoleManager.setLogger(getLogger());
  -        try {
  -            this.emptyRoleManager.configure(new DefaultConfiguration("role-list", "-"));
  -        } catch(ConfigurationException ce) {
  -            throw new ComponentException("Cannot configure Builder role manager", ce);
  -        }
  -        
           // Create the new component manager
           this.manager = new TreeBuilderComponentManager(this.parentManager);
           this.manager.setLogger(getLogger());
           this.manager.contextualize(this.context);
  -        this.manager.setRoleManager(this.emptyRoleManager);
  +        this.manager.setRoleManager(this.roleManager);
           this.manager.setLogKitManager(this.logKit);
           // this.manager.configure( - no configuration - );
           // initialize() is called later. In the meanwhile, only parent components will be visible.
       }
   
  +    public void setRoleManager(RoleManager rm) {
  +        this.roleManager = rm;
  +    }
  +
       public void configure(Configuration config) throws ConfigurationException {
           
           this.languageName = config.getAttribute("name");
  @@ -117,7 +113,7 @@
               ExcaliburComponentSelector selector = new ExcaliburComponentSelector();
               selector.setLogger(getLogger());
               selector.contextualize(this.context);
  -            selector.setRoleManager(this.emptyRoleManager);
  +            selector.setRoleManager(this.roleManager);
               selector.setLogKitManager(logKit);
               selector.compose(this.manager);
               //selector.configure(new DefaultConfiguration("node-builders","-"));
  @@ -261,4 +257,5 @@
           // And get the tree
           return rootBuilder.getNode();
       }
  +
   }
  
  
  
  1.3       +35 -3     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TreeProcessor.java	2001/11/12 18:07:43	1.2
  +++ TreeProcessor.java	2001/11/18 20:58:44	1.3
  @@ -8,6 +8,8 @@
   
   package org.apache.cocoon.treeprocessor;
   
  +import org.apache.avalon.excalibur.component.DefaultRoleManager;
  +import org.apache.avalon.excalibur.component.RoleManager;
   import org.apache.avalon.excalibur.logger.LogKitManageable;
   import org.apache.avalon.excalibur.logger.LogKitManager;
   
  @@ -45,13 +47,14 @@
    * Interpreted tree-traversal implementation of the a Processor language.
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
    */
   
   public class TreeProcessor extends AbstractLoggable implements ThreadSafe, Processor,
     Composable, Configurable, LogKitManageable, Initializable, Contextualizable {
       
       private static final String XCONF_URL = "resource://org/apache/cocoon/treeprocessor/treeprocessor.xconf";
  +    private static final String ROLES_URL = "resource://org/apache/cocoon/sitemap/sitemap.roles";
       
       /** The parent TreeProcessor, if any */
       protected TreeProcessor parent;
  @@ -127,6 +130,8 @@
               return;
           }
           
  +        AbstractParentProcessingNode.setStaticLogger(getLogger());
  +
           Configuration rootLangConfig = config.getChild("root-language", false);
           if (rootLangConfig != null) {
               this.language = rootLangConfig.getAttribute("name");
  @@ -198,10 +203,11 @@
           }
           
           this.sourceName = fileConfig.getAttribute("name");
  +
       }
       
       public boolean process(Environment environment) throws Exception {
  -        return process(environment, null, null);        
  +        return process(environment, null, null);
       }
   
       public boolean process(Environment environment, StreamPipeline pipeline, EventPipeline eventPipeline) throws Exception {
  @@ -244,7 +250,7 @@
           TreeBuilder builder = new TreeBuilder();
           builder.setLogger(getLogger());
           builder.contextualize(this.context);
  -        // builder.setRoleManager( - none - );
  +        builder.setRoleManager(getRoleManager());
           builder.setLogKitManager(this.logKit);
           builder.compose(this.manager);
           builder.configure(this.currentLanguage);
  @@ -252,4 +258,30 @@
           
           this.rootNode = builder.build(treeConfig);
       }
  +    
  +    
  +    private RoleManager getRoleManager() throws Exception {
  +
  +        Configuration rolesConfig;
  +        
  +        URLFactory factory = (URLFactory)this.manager.lookup(URLFactory.ROLE);
  +        URLSource source = new URLSource(factory.getURL(ROLES_URL), this.manager);
  +        try {
  +            SAXConfigurationHandler handler = new SAXConfigurationHandler();
  +            source.toSAX(handler);
  +            rolesConfig = handler.getConfiguration();
  +        } finally {
  +            this.manager.release((Component)factory);
  +            if (source != null) {
  +                source.recycle();
  +            }
  +        }
  +    
  +        DefaultRoleManager sitemapRoleManager = new DefaultRoleManager();
  +        sitemapRoleManager.setLogger(getLogger());
  +        sitemapRoleManager.configure(rolesConfig);
  +        
  +        return sitemapRoleManager;
  +    }
  +
   }
  
  
  
  1.3       +39 -9     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/treeprocessor.xconf
  
  Index: treeprocessor.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/treeprocessor.xconf,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- treeprocessor.xconf	2001/11/12 18:07:43	1.2
  +++ treeprocessor.xconf	2001/11/18 20:58:44	1.3
  @@ -9,7 +9,7 @@
    *****************************************************************************
   
    @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:44 $
   -->
   
   <tree-processor>
  @@ -26,9 +26,7 @@
         <!-- Note : for now, names are prefixed, but they'll be removed with the namespace-aware Configuration-->
         <!-- Sitemap root node -->
         <node name="map:sitemap" builder="org.apache.cocoon.treeprocessor.sitemap.SitemapNodeBuilder">
  -        <allowed-children>map:pipelines, map:components</allowed-children>
  -        <!-- the children below will be allowed when implemented :) -->
  -        <ignored-children>map:views, map:resources, map:action-sets</ignored-children>
  +        <allowed-children>map:components, map:views, map:action-sets, map:resources, map:pipelines</allowed-children>
         </node>
       
         <!-- Components definition : fills selectors on the TreeProcessor -->
  @@ -53,15 +51,47 @@
           <allowed-children>map:pipeline</allowed-children>
         </node>
         
  +      <node name="map:views" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +      
  +      <node name="map:resources" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +      
  +      <node name="map:action-sets" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +
         <node name="map:pipeline" builder="org.apache.cocoon.treeprocessor.sitemap.PipelineNodeBuilder">
           <forbidden-children>map:sitemap, map:components, map:pipelines</forbidden-children>
         </node>
         
  -      <!--node name="map:action" builder="org.apache.cocoon.treeprocessor.sitemap.ActionNodeBuilder">
  -        <forbidden-children>sitemap, components, pipeline, error-handler</forbidden-children>
  -      </node-->
  -      
  -      <node name="map:generate" builder="org.apache.cocoon.treeprocessor.sitemap.GeneratorNodeBuilder"/>
  +      <node name="map:match" builder="org.apache.cocoon.treeprocessor.sitemap.MatchNodeBuilder">
  +        <forbidden-children>sitemap, components, pipeline, handle-errors</forbidden-children>
  +        <ignored-children>map:parameter</ignored-children>
  +      </node>
  +
  +      <node name="map:select" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +
  +      <node name="map:act" builder="org.apache.cocoon.treeprocessor.sitemap.ActNodeBuilder">
  +        <forbidden-children>sitemap, components, pipeline, handle-errors</forbidden-children>
  +        <ignored-children>map:parameter</ignored-children>
  +      </node>
  +
  +      <node name="map:redirect-to" builder="org.apache.cocoon.treeprocessor.sitemap.RedirectToNodeBuilder"/>
  +
  +      <node name="map:mount" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +
  +      <node name="map:read" builder="org.apache.cocoon.treeprocessor.sitemap.ReadNodeBuilder">
  +      </node>
  +
  +      <node name="map:aggregate" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +
  +      <node name="map:generate" builder="org.apache.cocoon.treeprocessor.sitemap.GenerateNodeBuilder">
  +      </node>
  +
  +      <node name="map:transform" builder="org.apache.cocoon.treeprocessor.sitemap.TransformNodeBuilder"/>
  +
  +      <node name="map:serialize" builder="org.apache.cocoon.treeprocessor.sitemap.SerializeNodeBuilder"/>
  +
  +      <node name="map:handle-errors" builder="org.apache.cocoon.treeprocessor.NullNodeBuilder"/>
  +
  +
       </nodes>
       
     </language>
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/NullNode.java
  
  Index: NullNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor;
  
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.environment.Environment;
  
  import java.util.*;
  
  /**
   * A no-op node to stub not yet implemented features.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:44 $
   */
  
  public class NullNode extends AbstractProcessingNode {
      public boolean invoke(
          Environment env,
          StreamPipeline pipeline,
          EventPipeline eventPipeline,
          List listOfMaps
      ) throws Exception {
          
          getLogger().debug("Invoke on NullNode at " + getLocation());
          return false;
          
      }  
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/NullNodeBuilder.java
  
  Index: NullNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:44 $
   */
  
  public class NullNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private NullNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          this.node = new NullNode();
          this.node.setLogger(getLogger());
          this.node.setLocation(config.getLocation());
      }
      
      public ProcessingNode getNode() throws Exception {
          return this.node;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/SimpleParentProcessingNode.java
  
  Index: SimpleParentProcessingNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor;
  
  import org.apache.cocoon.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:44 $
   */
  
  public abstract class SimpleParentProcessingNode extends AbstractParentProcessingNode {
  
      /** The childrens of this matcher */
      protected ProcessingNode[] children;
  
      /** The node component name (e.g. action name, selector name, etc) */
      protected String componentName;
      
      public SimpleParentProcessingNode(String name) {
          this.componentName = name;
      }
      
      public void setChildren(ProcessingNode[] children) {
          this.children = children;
      }
      
      public void dispose() {
          this.disposeNodes(this.children);
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/SimpleSelectorProcessingNode.java
  
  Index: SimpleSelectorProcessingNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:44 $
   */
  
  public abstract class SimpleSelectorProcessingNode extends AbstractParentProcessingNode {
  
      /** The childrens of this matcher */
      protected ProcessingNode[] children;
  
      /** The node component name (e.g. action name, selector name, etc) */
      protected String componentName;
      
      /** Selector where to get components from */
      protected ComponentSelector selector;
  
      public SimpleSelectorProcessingNode(String componentName) {
          this.componentName = componentName;
      }
      
      public void setSelector(ComponentSelector selector) throws Exception {
          this.selector = selector;
      }
          
      public void setChildren(ProcessingNode[] children) {
          this.children = children;
      }
      
      public void dispose() {
          this.disposeNodes(this.children);
      }
      
      /**
       * Tests is the component designated by this node using the selector and component name
       * is <code>ThreadSafe</code>, and return it if true.
       * <p>
       * Note : this method must be called <i>after</i> <code>setSelector()</code>.
       */
      protected Component getThreadSafeComponent() throws ComponentException {
          Component component = this.selector.select(this.componentName);
          if (component instanceof ThreadSafe) {
              return component;
          } else {
              this.selector.release(component);
              return null;
          }
      }
  }
  
  
  1.3       +35 -6     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ComponentsNodeBuilder.java
  
  Index: ComponentsNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ComponentsNodeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentsNodeBuilder.java	2001/11/12 18:07:43	1.2
  +++ ComponentsNodeBuilder.java	2001/11/18 20:58:45	1.3
  @@ -31,6 +31,7 @@
   
   import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
   import org.apache.cocoon.treeprocessor.ProcessingNode;
  +import org.apache.cocoon.treeprocessor.TreeBuilder;
   
   import org.apache.cocoon.util.ClassUtils;
   
  @@ -42,7 +43,7 @@
    * but creates <code>ComponentSelectors</code> that are made available to other nodes.
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:45 $
    */
   
   public class ComponentsNodeBuilder extends AbstractProcessingNodeBuilder implements
  @@ -68,7 +69,7 @@
       
       /** Association of role names to section names */
       protected Map sectionRoles = new HashMap();
  -    
  +        
       public void contextualize(Context context) {
           this.context = context;
       }
  @@ -134,7 +135,11 @@
               if (defaultElement == null) {
                   getLogger().debug("Component section '" + sectionName + "' has no default");
               } else {
  -                this.treeBuilder.setAttribute(DEFAULT_PREFIX + elementName, defaultElement);
  +                // FIXME : for now configs have a qualified name. Remove it
  +                int pos = elementName.indexOf(':');
  +                String localName = (pos == -1) ? elementName : elementName.substring(pos + 1);
  +                getLogger().debug("Setting default " + localName + " type to " + defaultElement);
  +                this.treeBuilder.setAttribute(DEFAULT_PREFIX + localName, defaultElement );
               }
   
               // Create the selector for this section
  @@ -149,13 +154,16 @@
                   throw new ComponentException("Cannot configure role manager", ce);
               }
               
  +            String role = (String)this.sectionRoles.get(sectionName);
               SitemapComponentSelector selector = new SitemapComponentSelector();
               selector.setLogger(getLogger());
               selector.contextualize(this.context);
               selector.setRoleManager(emptyRoleManager);
               selector.setLogKitManager(this.logKit);
               selector.compose(this.manager);
  -            // selector.configure( - no configuration - );
  +            DefaultConfiguration selectorConfig = new DefaultConfiguration("component", "-");
  +            selectorConfig.setAttribute("role", role);
  +            selector.configure(selectorConfig);
               
               // Iterate on all components
               Configuration[] elements = section.getChildren();
  @@ -187,7 +195,12 @@
                   String mimeType = element.getAttribute("mime-type", null);
                   
                   // Register the component
  -                selector.addComponent(name, clazz, element);
  +                getLogger().debug("Adding " + elementName + " '" + name + "' class=" + clazz.getName());
  +                if (mimeType == null) {                
  +                    selector.addComponent(name, clazz, element);
  +                } else {
  +                    selector.addSitemapComponent(name, clazz, element, mimeType);
  +                }
                   
                   if (name.equals(defaultElement)) {
                       // Clear default to mark it as found
  @@ -202,7 +215,6 @@
               }
               
               // Chain with parent processor selector, if any
  -            String role = (String)this.sectionRoles.get(sectionName);
               try {
                   SitemapComponentSelector parentSelector =
                       (SitemapComponentSelector)this.manager.lookup(role);
  @@ -228,5 +240,22 @@
       public ProcessingNode getNode() {
           // Nothing to do at runtime.
           return null;
  +    }
  +    
  +    public static final String getComponentType(String component, Configuration config, TreeBuilder treeBuilder)
  +      throws ConfigurationException {
  +        
  +        String type = config.getAttribute("type", null);
  +        if (type == null) {
  +            type = (String)treeBuilder.getAttribute(DEFAULT_PREFIX + component);
  +        }
  +        
  +        if (type == null) {
  +            throw new ConfigurationException(
  +                "There is no default " + component + " defined. Cannot create " +
  +                component + " at " + config.getLocation());
  +        }
  +        
  +        return type;
       }
   }
  
  
  
  1.3       +6 -5      xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelineNode.java
  
  Index: PipelineNode.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelineNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PipelineNode.java	2001/11/12 18:07:43	1.2
  +++ PipelineNode.java	2001/11/18 20:58:45	1.3
  @@ -29,7 +29,7 @@
    * 
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:45 $
    */
   
   public class PipelineNode extends AbstractParentProcessingNode {
  @@ -54,9 +54,9 @@
           this.manager = manager;
       }
       
  -    public void setChildren(ProcessingNode[] node)
  +    public void setChildren(ProcessingNode[] nodes)
       {
  -        this.children = children;
  +        this.children = nodes;
       }
       
       public void set404Handler(ProcessingNode node)
  @@ -91,7 +91,7 @@
               }
               
           } catch(ResourceNotFoundException rnfe) {
  -            getLogger().debug("Not found while processing pipeline", rnfe);
  +            getLogger().debug("Resource not found in pipeline at " + getLocation(), rnfe);
               
               if (error404 != null) {
                   
  @@ -99,7 +99,8 @@
                   return false;
                   
               } else {
  -                throw rnfe;
  +return false;
  +//                throw rnfe;
               }
           } catch(Exception e) {
               getLogger().debug("Error while processing pipeline", e);
  
  
  
  1.2       +12 -2     xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelineNodeBuilder.java
  
  Index: PipelineNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelineNodeBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PipelineNodeBuilder.java	2001/11/12 18:07:43	1.1
  +++ PipelineNodeBuilder.java	2001/11/18 20:58:45	1.2
  @@ -16,26 +16,35 @@
   import org.apache.cocoon.treeprocessor.ProcessingNodeBuilder;
   
   import java.util.*;
  +import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.ComponentException;
   
   /**
    * Builds a &lt;map:pipeline&gt;
    
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/11/18 20:58:45 $
    */
   
  -public class PipelineNodeBuilder extends AbstractParentProcessingNodeBuilder {
  +public class PipelineNodeBuilder extends AbstractParentProcessingNodeBuilder implements Composable {
   
  +    private ComponentManager manager;
       private PipelineNode node;
       private List builders;
       private ProcessingNodeBuilder error404Builder;
       private ProcessingNodeBuilder error500Builder;
       
  +    public void compose(ComponentManager manager) throws ComponentException {
  +        this.manager = manager;
  +    }
  +    
       public void buildNode(Configuration config, Map buildModel) throws Exception {
           
           this.node = new PipelineNode();
           this.node.setLocation(config.getLocation());
           this.node.setLogger(getLogger());
  +        this.node.compose(this.manager);
   
           this.node.setInternalOnly(config.getAttributeAsBoolean("internal-only", false));
           
  @@ -85,4 +94,5 @@
           
           return this.node;
       }
  +
   }
  
  
  
  1.2       +5 -5      xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelinesNode.java
  
  Index: PipelinesNode.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelinesNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PipelinesNode.java	2001/11/12 18:07:43	1.1
  +++ PipelinesNode.java	2001/11/18 20:58:45	1.2
  @@ -26,27 +26,27 @@
    * Handles &lt;map:pipelines&gt;
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/11/18 20:58:45 $
    */
   
   public final class PipelinesNode extends AbstractParentProcessingNode {
   
       private ProcessingNode[] children;
       
  -    public void setChildren(ProcessingNode[] node)
  +    public void setChildren(ProcessingNode[] nodes)
       {
  -        this.children = children;
  +        this.children = nodes;
       }
       
       public final boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
         throws Exception {
           
  -        return invokeNodes(children, env, pipeline, eventPipeline, listOfMaps);
  +        return invokeNodes(this.children, env, pipeline, eventPipeline, listOfMaps);
       }
       
       public final void dispose() {
           
  -        disposeNodes(children);
  +        disposeNodes(this.children);
       }
       
   }
  
  
  
  1.2       +3 -3      xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelinesNodeBuilder.java
  
  Index: PipelinesNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PipelinesNodeBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PipelinesNodeBuilder.java	2001/11/12 18:07:43	1.1
  +++ PipelinesNodeBuilder.java	2001/11/18 20:58:45	1.2
  @@ -21,7 +21,7 @@
    * Buildes a &lt;map:pipelines&gt;
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/11/18 20:58:45 $
    */
   
   public class PipelinesNodeBuilder extends AbstractParentProcessingNodeBuilder {
  @@ -36,7 +36,7 @@
           this.node.setLogger(getLogger());
   
           
  -        // Get all children but the error handlers
  +        // Get all children
           this.builders = createChildBuilders(config, buildModel);
           
           if (this.builders.size() == 0) {
  @@ -47,7 +47,7 @@
       
       public ProcessingNode getNode() throws Exception {
           
  -        this.node.setChildren(this.getNodes(builders));
  +        this.node.setChildren(getNodes(this.builders));
                   
           return this.node;
       }
  
  
  
  1.3       +3 -2      xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SitemapNodeBuilder.java
  
  Index: SitemapNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SitemapNodeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SitemapNodeBuilder.java	2001/11/12 18:07:43	1.2
  +++ SitemapNodeBuilder.java	2001/11/18 20:58:45	1.3
  @@ -22,7 +22,7 @@
   /**
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/12 18:07:43 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/11/18 20:58:45 $
    */
   
   public class SitemapNodeBuilder extends AbstractParentProcessingNodeBuilder implements Composable {
  @@ -46,8 +46,9 @@
           node.setLogger(getLogger());
           node.compose(this.manager);
           
  +        // FIXME : should we make the assumption that map:components comes first in the sitemap ?
  +        // if not, default component types will not be set up properly for use by other NodeBuilder.
           this.childBuilders = createChildBuilders(config, buildModel);
  -        
       }
       
       public ProcessingNode getNode() throws Exception {
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ActNode.java
  
  Index: ActNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.sitemap.SitemapRedirector;
  
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  import org.apache.cocoon.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  import java.util.Map;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class ActNode extends AbstractParentProcessingNode {
      
      /** The childrens of this action */
      protected ProcessingNode[] children;
  
      /** The action name */
      protected String actionName;
      
      /** The 'src' attribute */
      protected ListOfMapsResolver source;
  
      /** Selector where to get Actions from */
      protected ComponentSelector selector;
      
      /** Pre-selected action, if it's ThreadSafe */
      protected Action threadSafeAction;
  
      public ActNode(String name, String source) throws PatternException {
          this.actionName = name;
          this.source = ListOfMapsResolver.getResolver(source);
      }
      
      public void setChildren(ProcessingNode[] children) {
          this.children = children;
      }
      
      public void setSelector(ComponentSelector selector) throws ComponentException {
          
          this.selector = selector;
          
          // Is it a ThreadSafe action ?
          Action action = (Action)selector.select(actionName);
          if (action instanceof ThreadSafe) {
              // Yes : keep it.
              this.threadSafeAction = action;
          } else {
              this.threadSafeAction = null;
              selector.release(action);
          }
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          // Prepare data needed by the action
          Map               objectModel    = env.getObjectModel();
          SitemapRedirector redirector     = SitemapNode.getRedirector(env);
          SourceResolver    resolver       = getSourceResolver(objectModel);
          String            resolvedSource = source.resolve(listOfMaps);
          Parameters        resolvedParams = ListOfMapsResolver.buildParameters(this.parameters, listOfMaps);
          
          Map actionResult;
          
          // If action is ThreadSafe, avoid select() and try/catch block (faster !)
          if (this.threadSafeAction != null) {
              actionResult = this.threadSafeAction.act(
                  redirector, resolver, objectModel, resolvedSource, resolvedParams );
              
          } else {
              Action action = (Action)this.selector.select(this.actionName);
              try {
                  actionResult = action.act(
                  redirector, resolver, objectModel, resolvedSource, resolvedParams );
                  
              } finally {
                  this.selector.release(action);
              }
          }
          
          if (redirector.hasRedirected()) {
              return true;
          }
          
          if (actionResult == null) {
              // Action failed
              return false;
              
          } else {
              // Action succeeded : process children if there are some, with the action result
              if (this.children != null) {
                  return this.invokeNodes(this.children, env, pipeline, eventPipeline, listOfMaps, actionResult);
              } else {
                  return true;
              }
          }
      }
      
      public void dispose() {
          disposeNodes(children);
          if (this.threadSafeAction != null) {
              this.selector.release(this.threadSafeAction);
          }
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ActNodeBuilder.java
  
  Index: ActNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.NullNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class ActNodeBuilder extends AbstractParentProcessingNodeBuilder implements Composable {
  
      private ComponentManager manager;
      private ActNode actNode;
      private NullNode setNode;
      private List builders;
  
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          String source = config.getAttribute("src", null);
          
          // Is it an action-set call ?
          String set = config.getAttribute("set", null);
          if (set == null) {
              String type = ComponentsNodeBuilder.getComponentType("action", config, this.treeBuilder);
              this.actNode = new ActNode(type, source);
              this.actNode.setLogger(getLogger());
              this.actNode.setLocation(config.getLocation());
              this.actNode.setParameters(getParameters(config));
              // Selector is set in getNode()
              
              // Get all children
              this.builders = createChildBuilders(config, buildModel);
              
          } else {
              getLogger().warn("action sets not yet implemented");
              this.setNode = new NullNode();
              this.setNode.setLogger(getLogger());
              this.setNode.setLocation(config.getLocation());
          }
      }
      
      public ProcessingNode getNode() throws Exception {
          if (this.actNode != null) {
              // Get the selector (it's now visible in the manager)
              ComponentSelector selector = (ComponentSelector)manager.lookup(Action.ROLE + "Selector");
              this.actNode.setSelector(selector);
              
              this.actNode.setChildren(getNodes(this.builders));
              
              return this.actNode;
              
          } else {
              return this.setNode;
          }
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/GenerateNode.java
  
  Index: GenerateNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class GenerateNode extends AbstractProcessingNode {
  
      private String generatorName;
      
      private ListOfMapsResolver source;
      
      public GenerateNode(String name, String source) throws PatternException {
          this.generatorName = name;
          this.source = ListOfMapsResolver.getResolver(source);
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          eventPipeline.setGenerator(
              this.generatorName,
              source.resolve(listOfMaps),
              ListOfMapsResolver.buildParameters(this.parameters, listOfMaps)
          );
          
          // Return false to contine sitemap invocation
          return false;
      }
      
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/GenerateNodeBuilder.java
  
  Index: GenerateNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class GenerateNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private GenerateNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          String type = ComponentsNodeBuilder.getComponentType("generator", config, this.treeBuilder);
          
          this.node = new GenerateNode(type, config.getAttribute("src", null));
          this.node.setLogger(getLogger());
          this.node.setLocation(config.getLocation());
          
          this.node.setParameters(getParameters(config));
          
      }
      
      public ProcessingNode getNode() {
          return this.node;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/MatchNode.java
  
  Index: MatchNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.SimpleSelectorProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  import org.apache.cocoon.matching.Matcher;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class MatchNode extends SimpleSelectorProcessingNode {
      
      /** The 'pattern' attribute */
      private ListOfMapsResolver pattern;
      
      /** The matcher, if it's ThreadSafe */
      private Matcher threadSafeMatcher;
      
      public MatchNode(String name, String pattern) throws PatternException {
          super(name);
          this.pattern = ListOfMapsResolver.getResolver(pattern);
      }
      
      public void setSelector(ComponentSelector selector) throws Exception {
          super.setSelector(selector);
          this.threadSafeMatcher = (Matcher)this.getThreadSafeComponent();
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          String resolvedPattern = pattern.resolve(listOfMaps);
          Map objectModel = env.getObjectModel();
          Parameters resolvedParams = ListOfMapsResolver.buildParameters(this.parameters, listOfMaps);
          
          Map result = null;
          
          if (this.threadSafeMatcher != null) {
              // Avoid select() and try/catch block (faster !)
              result = this.threadSafeMatcher.match(resolvedPattern, objectModel, resolvedParams);
                  
          } else {
              // Get matcher from selector
              Matcher matcher = (Matcher)this.selector.select(this.componentName);
              try {
                  result = matcher.match(resolvedPattern, objectModel, resolvedParams);
                      
              } finally {
                  this.selector.release(matcher);
              }
          }
          
          if (result != null) {
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("Matcher '" + this.componentName + "' matched pattern '" + this.pattern + "'");
              }
              
              // Invoke children with the matcher results
              return this.invokeNodes(children, env, pipeline, eventPipeline, listOfMaps, result);
              
          } else {
              // Matcher failed
              return false;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/MatchNodeBuilder.java
  
  Index: MatchNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.matching.Matcher;
  import org.apache.cocoon.matching.PreparableMatcher;
  import org.apache.cocoon.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  import org.apache.cocoon.treeprocessor.SimpleSelectorProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class MatchNodeBuilder extends AbstractParentProcessingNodeBuilder implements Composable {
  
      private ComponentManager manager;
      private SimpleSelectorProcessingNode node;
      private List builders;
      private Configuration config;
  
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          this.config = config;
          
          // Actual creation of node is deferred to getNode() since we need the Selector
          
          // Get all children
          this.builders = createChildBuilders(config, buildModel);
          
          if (this.builders.size() == 0) {
              throw new ConfigurationException("There must be at least one child in match at " +
                  config.getLocation());
          }
          
      }
      
      public ProcessingNode getNode() throws Exception {
          // Protect against multiple calls (shouldn't normally occur)
          if (this.node == null) {
              
              String type = ComponentsNodeBuilder.getComponentType("matcher", config, this.treeBuilder);
          
              String pattern = this.config.getAttribute("pattern", null);
              
              // Get the selector
              ComponentSelector selector = (ComponentSelector)manager.lookup(Matcher.ROLE + "Selector");
  
              // Get a matcher instance and check if its a PreparableMatcher
              Matcher matcher = (Matcher)selector.select(type);
              boolean preparable;
              try {
                  // Prepared matchers are only prepared if pattern doesn't need
                  // request-time resolution.
                  preparable =
                     (matcher instanceof PreparableMatcher) && !ListOfMapsResolver.needsResolve(pattern);
              } finally {
                  selector.release(matcher);
              }
              
              // Instanciate corresponding node
              if (preparable) {
                  this.node = new PreparableMatchNode(type, pattern);
              } else {
                  this.node = new MatchNode(type, pattern);
              }
              
              this.node.setLogger(getLogger());
              this.node.setLocation(config.getLocation());
              
              this.node.setSelector(selector);
              this.node.setParameters(getParameters(config));
              
              this.node.setChildren(getNodes(this.builders));
          }
                  
          return this.node;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/PreparableMatchNode.java
  
  Index: PreparableMatchNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.SimpleSelectorProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  import org.apache.cocoon.matching.PreparableMatcher;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class PreparableMatchNode extends SimpleSelectorProcessingNode {
      
      /** The 'pattern' attribute */
      private String pattern;
      
      private Object preparedPattern;
      
      /** The matcher, if it's ThreadSafe */
      private PreparableMatcher threadSafeMatcher;
      
      public PreparableMatchNode(String name, String pattern) throws PatternException {
          super(name);
          this.pattern = pattern;
      }
      
      public void setSelector(ComponentSelector selector) throws Exception {
          super.setSelector(selector);
          
          // Prepare the pattern, and keep matcher if ThreadSafe
          PreparableMatcher matcher = (PreparableMatcher)selector.select(componentName);
          
          if (matcher instanceof ThreadSafe) {
              this.threadSafeMatcher = matcher;
          }
          
          try {
              this.preparedPattern = matcher.preparePattern(ListOfMapsResolver.unescape(this.pattern));
  
          } finally {
              if (this.threadSafeMatcher == null) {
                  selector.release(matcher);
              }
          }
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          Map objectModel = env.getObjectModel();
          Parameters resolvedParams = ListOfMapsResolver.buildParameters(this.parameters, listOfMaps);
          
          Map result = null;
          
          if (this.threadSafeMatcher != null) {
              // Avoid select() and try/catch block (faster !)
              result = this.threadSafeMatcher.preparedMatch(preparedPattern, objectModel, resolvedParams);
                  
          } else {
              // Get matcher from selector
              PreparableMatcher matcher = (PreparableMatcher)this.selector.select(this.componentName);
              try {
                  result = matcher.preparedMatch(preparedPattern, objectModel, resolvedParams);
                      
              } finally {
                  this.selector.release(matcher);
              }
          }
          
          if (result != null) {
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("Matcher '" + this.componentName + "' matched prepared pattern '" + this.pattern + "'");
              }
              
              // Invoke children with the matcher results
              return this.invokeNodes(children, env, pipeline, eventPipeline, listOfMaps, result);
              
          } else {
              // Matcher failed
              return false;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ReadNode.java
  
  Index: ReadNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class ReadNode extends AbstractProcessingNode {
  
      private String readerName;
      
      private ListOfMapsResolver source;
      
      private String mimeType;
      
      private int statusCode;
      
      /**
       * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
       *
       * @param name the name of the serializer to use.
       * @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 ReadNode(String name, String source, String mimeType, int statusCode) throws PatternException {
          this.readerName = name;
          this.source = ListOfMapsResolver.getResolver(source);
          this.mimeType = mimeType;
          this.statusCode = statusCode;
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          if (this.mimeType == null) {
              // No mime-type set on node
              pipeline.setReader(
                  this.readerName,
                  source.resolve(listOfMaps),
                  ListOfMapsResolver.buildParameters(this.parameters, listOfMaps)
              );
              
          } else {
              // mime-type set on node
              pipeline.setReader(
                  this.readerName,
                  source.resolve(listOfMaps),
                  ListOfMapsResolver.buildParameters(this.parameters, listOfMaps),
                  this.mimeType
              );
          }
          
          // Set status code if there is one
          if (this.statusCode >= 0) {
              env.setStatus(this.statusCode);
          }
          
          if (! SitemapNode.isInternalRequest(env)) {
              // Process pipeline
              return pipeline.process(env);
              
          } else {
              // Return true : pipeline is finished.
              return true;
          }
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/ReadNodeBuilder.java
  
  Index: ReadNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class ReadNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private ReadNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          String type = ComponentsNodeBuilder.getComponentType("reader", config, this.treeBuilder);
          
          this.node = new ReadNode(
              type,
              config.getAttribute("src", null),
              config.getAttribute("mime-type", null),
              config.getAttributeAsInteger("status-code", -1)
          );
  
          this.node.setLogger(getLogger());
          this.node.setLocation(config.getLocation());
          
          // No parameters on a serializer
      }
      
      public ProcessingNode getNode() {
          return this.node;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/RedirectToNodeBuilder.java
  
  Index: RedirectToNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  import org.apache.cocoon.treeprocessor.NullNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class RedirectToNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private AbstractProcessingNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          // Is it a redirect to resource ?
          String uri = config.getAttribute("uri", null);
          if (uri == null) {
              this.node = new RedirectToURINode(uri, config.getAttributeAsBoolean("session", false));
              this.node.setLogger(getLogger());
              this.node.setLocation(config.getLocation());
              
          } else {
              getLogger().warn("redirect to resource not yet implemented");
              this.node = new NullNode();
              this.node.setLogger(getLogger());
              this.node.setLocation(config.getLocation());
          }
      }
      
      public ProcessingNode getNode() throws Exception {
          
          return this.node;
  
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/RedirectToURINode.java
  
  Index: RedirectToURINode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.sitemap.SitemapRedirector;
  
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  import java.util.Map;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class RedirectToURINode extends AbstractProcessingNode {
          
      /** The 'uri' attribute */
      private ListOfMapsResolver uri;
      
      private boolean keepSession;
  
      public RedirectToURINode(String uri, boolean keepSession) throws PatternException {
          this.uri = ListOfMapsResolver.getResolver(uri);
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          String resolvedURI = uri.resolve(listOfMaps);
          
          if (getLogger().isDebugEnabled()) {
              getLogger().debug("Sitemap: session='" + this.keepSession + "', redirecting to " + resolvedURI);
          }
  
          env.redirect (this.keepSession, resolvedURI);
  
          return true;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SerializeNode.java
  
  Index: SerializeNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class SerializeNode extends AbstractProcessingNode {
  
      private String serializerName;
      
      private String mimeType;
      
      private int statusCode;
      
      /**
       * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
       *
       * @param name the name of the serializer to use.
       * @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, String mimeType, int statusCode) throws PatternException {
          this.serializerName = name;
          this.mimeType = mimeType;
          this.statusCode = statusCode;
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          if (this.mimeType == null) {
              // No mime-type set on node
              pipeline.setSerializer(
                  this.serializerName,
                  null,
                  ListOfMapsResolver.EMPTY_PARAMETERS // No parameters on serializers
              );
              
          } else {
              // mime-type set on node
              pipeline.setSerializer(
                  this.serializerName,
                  null,
                  ListOfMapsResolver.EMPTY_PARAMETERS,
                  this.mimeType
              );
          }
          
          // Set status code if there is one
          if (this.statusCode >= 0) {
              env.setStatus(this.statusCode);
          }
          
          if (! SitemapNode.isInternalRequest(env)) {
              // Process pipeline
              return pipeline.process(env);
              
          } else {
              // Return true : pipeline is finished.
              return true;
          }
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SerializeNodeBuilder.java
  
  Index: SerializeNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class SerializeNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private SerializeNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          String type = ComponentsNodeBuilder.getComponentType("serializer", config, this.treeBuilder);
          
          this.node = new SerializeNode(
              type,
              config.getAttribute("mime-type", null),
              config.getAttributeAsInteger("status-code", -1)
          );
          
          this.node.setLogger(getLogger());
          this.node.setLocation(config.getLocation());
          
          // No parameters on a serializer
      }
      
      public ProcessingNode getNode() {
          return this.node;
      }
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/TransformNode.java
  
  Index: TransformNode.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.treeprocessor.ListOfMapsResolver;
  
  import java.util.List;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class TransformNode extends AbstractProcessingNode {
  
      private String transformerName;
      
      private ListOfMapsResolver source;
      
      public TransformNode(String name, String source) throws PatternException {
          this.transformerName = name;
          this.source = ListOfMapsResolver.getResolver(source);
      }
      
      public boolean invoke(Environment env, StreamPipeline pipeline, EventPipeline eventPipeline, List listOfMaps)
        throws Exception {
          
          eventPipeline.addTransformer(
              this.transformerName,
              source.resolve(listOfMaps),
              ListOfMapsResolver.buildParameters(this.parameters, listOfMaps)
          );
          
          // Return false to contine sitemap invocation
          return false;
      }
      
  }
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/TransformNodeBuilder.java
  
  Index: TransformNodeBuilder.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.treeprocessor.ProcessingNode;
  
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/18 20:58:45 $
   */
  
  public class TransformNodeBuilder extends AbstractProcessingNodeBuilder {
  
      private TransformNode node;
  
      public void buildNode(Configuration config, Map buildModel) throws Exception {
          
          String type = ComponentsNodeBuilder.getComponentType("transformer", config, this.treeBuilder);
          
          this.node = new TransformNode(type, config.getAttribute("src", null));
          this.node.setLogger(getLogger());
          this.node.setLocation(config.getLocation());
          
          this.node.setParameters(getParameters(config));
          
      }
      
      public ProcessingNode getNode() {
          return this.node;
      }
  }
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org