cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: xml-cocoon2/src/webapp cocoon.xconf
Date Tue, 05 Mar 2002 08:26:24 GMT
sylvain     02/03/05 00:26:24

  Modified:    src/scratchpad/src/org/apache/cocoon/treeprocessor
                        TreeProcessor.java
               src/webapp cocoon.xconf
  Added:       src/java/org/apache/cocoon/components/treeprocessor
                        AbstractParentProcessingNode.java
                        AbstractParentProcessingNodeBuilder.java
                        AbstractProcessingNode.java
                        AbstractProcessingNodeBuilder.java
                        CategoryNode.java CategoryNodeBuilder.java
                        ContainerNode.java ContainerNodeBuilder.java
                        EnvironmentSourceResolver.java InvokeContext.java
                        LinkedProcessingNodeBuilder.java
                        MapStackResolver.java NamedContainerNode.java
                        NamedContainerNodeBuilder.java
                        NamedProcessingNode.java NullNode.java
                        NullNodeBuilder.java
                        ParameterizableProcessingNode.java
                        ProcessingNode.java ProcessingNodeBuilder.java
                        SimpleParentProcessingNode.java
                        SimpleSelectorProcessingNode.java TreeBuilder.java
                        TreeProcessor.java package.html
                        treeprocessor-builtins.xml
               src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        ActNodeBuilder.java ActSetNode.java
                        ActTypeNode.java ActionSetNode.java
                        ActionSetNodeBuilder.java AggregateNode.java
                        AggregateNodeBuilder.java CallNode.java
                        CallNodeBuilder.java ComponentsNodeBuilder.java
                        ComponentsSelector.java GenerateNode.java
                        GenerateNodeBuilder.java HandleErrorsNode.java
                        HandleErrorsNodeBuilder.java MatchNode.java
                        MatchNodeBuilder.java MountNode.java
                        MountNodeBuilder.java PipelineNode.java
                        PipelineNodeBuilder.java PipelinesNode.java
                        PipelinesNodeBuilder.java PreparableMatchNode.java
                        ReadNode.java ReadNodeBuilder.java
                        RedirectToNodeBuilder.java RedirectToURINode.java
                        SelectNode.java SelectNodeBuilder.java
                        SerializeNode.java SerializeNodeBuilder.java
                        SitemapLanguage.java SitemapNode.java
                        SitemapNodeBuilder.java TransformNode.java
                        TransformNodeBuilder.java ViewNodeBuilder.java
                        package.html
  Removed:     src/java/org/apache/cocoon/components/processor package.html
               src/java/org/apache/cocoon/components/processor/treeprocessor
                        AbstractParentProcessingNode.java
                        AbstractParentProcessingNodeBuilder.java
                        AbstractProcessingNode.java
                        AbstractProcessingNodeBuilder.java
                        CategoryNode.java CategoryNodeBuilder.java
                        ContainerNode.java ContainerNodeBuilder.java
                        EnvironmentSourceResolver.java InvokeContext.java
                        LinkedProcessingNodeBuilder.java
                        MapStackResolver.java NamedContainerNode.java
                        NamedContainerNodeBuilder.java
                        NamedProcessingNode.java NullNode.java
                        NullNodeBuilder.java
                        ParameterizableProcessingNode.java
                        ProcessingNode.java ProcessingNodeBuilder.java
                        SimpleParentProcessingNode.java
                        SimpleSelectorProcessingNode.java TreeBuilder.java
                        TreeProcessor.java package.html
                        treeprocessor-builtins.xml
               src/java/org/apache/cocoon/components/processor/treeprocessor/sitemap
                        ActNodeBuilder.java ActSetNode.java
                        ActTypeNode.java ActionSetNode.java
                        ActionSetNodeBuilder.java AggregateNode.java
                        AggregateNodeBuilder.java CallNode.java
                        CallNodeBuilder.java ComponentsNodeBuilder.java
                        ComponentsSelector.java GenerateNode.java
                        GenerateNodeBuilder.java HandleErrorsNode.java
                        HandleErrorsNodeBuilder.java MatchNode.java
                        MatchNodeBuilder.java MountNode.java
                        MountNodeBuilder.java PipelineNode.java
                        PipelineNodeBuilder.java PipelinesNode.java
                        PipelinesNodeBuilder.java PreparableMatchNode.java
                        ReadNode.java ReadNodeBuilder.java
                        RedirectToNodeBuilder.java RedirectToURINode.java
                        SelectNode.java SelectNodeBuilder.java
                        SerializeNode.java SerializeNodeBuilder.java
                        SitemapLanguage.java SitemapNode.java
                        SitemapNodeBuilder.java TransformNode.java
                        TransformNodeBuilder.java ViewNodeBuilder.java
                        package.html
  Log:
  Changed my mind and moved the treeprocessor one level up in the hierarchy : it's a framework on its own that deserves a better visibility (and class names become soooo long).
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java
  
  Index: AbstractParentProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AbstractParentProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class AbstractParentProcessingNode extends AbstractProcessingNode {
  
      /**
       * Invoke all nodes of a node array in order, until one succeeds.
       *
       * @parameter currentMap the <code>Map<code> of parameters produced by this node,
       *            which is added to <code>listOfMap</code>.
       */
      protected final boolean invokeNodes(
          ProcessingNode[] nodes,
          Environment env,
          InvokeContext context,
          Map currentMap)
        throws Exception {
  
          context.pushMap(currentMap);
  
          for (int i = 0; i < nodes.length; i++) {
              if (nodes[i].invoke(env, context)) {
                  // Success
                  context.popMap();
                  return true;
              }
          }
  
          // No success
          context.popMap();
          return false;
      }
  
      /**
       * Invoke all nodes of a node array in order, until one succeeds.
       */
      protected final boolean invokeNodes (
          ProcessingNode[] nodes,
          Environment env,
          InvokeContext context)
        throws Exception {
  
          for (int i = 0; i < nodes.length; i++) {
              if (nodes[i].invoke(env, context)) {
                  return true;
              }
          }
  
          return false;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
  
  Index: AbstractParentProcessingNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  
  import org.apache.cocoon.util.StringUtils;
  
  import java.util.*;
  
  /**
   * Base class for parent <code>ProcessingNodeBuilders</code>, providing services for parsing
   * children nodes.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AbstractParentProcessingNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class AbstractParentProcessingNodeBuilder extends AbstractProcessingNodeBuilder implements Configurable {
  
      protected Collection allowedChildren;
  
      protected Collection forbiddenChildren;
  
      protected Collection ignoredChildren;
  
      /**
       * Configure the sets of allowed, forbidden and ignored children nodes.
       */
      public void configure(Configuration config) throws ConfigurationException {
          this.allowedChildren   = getStringCollection(config.getChild("allowed-children"));
          this.forbiddenChildren = getStringCollection(config.getChild("forbidden-children"));
          this.ignoredChildren   = getStringCollection(config.getChild("ignored-children"));
      }
  
      /**
       * Checks if a child element and is allowed, and if not throws a <code>ConfigurationException</code>.
       *
       * @param child the child configuration to check.
       * @return <code>true</code> if this child should be considered or <code>false</code>
       *         if it should be ignored.
       * @throws ConfigurationException if this child isn't allowed.
       */
      protected boolean isChild(Configuration child) throws ConfigurationException {
  
          checkNamespace(child);
  
          String name = child.getName();
  
          // Is this a parameter of a parameterizable node builder ?
          if (isParameter(child)) {
              return false;
          }
  
          // Is this element to be ignored ?
          if (ignoredChildren != null && ignoredChildren.contains(name)) {
              getLogger().debug("Element '" + name + "' is ignored for building children of element '" +
                  child.getName() + "'");
  
              return false;
          }
  
          // Is it allowed ?
          if ( (allowedChildren != null && !allowedChildren.contains(name)) ||
               (forbiddenChildren != null && forbiddenChildren.contains(name)) ) {
              String msg = "Element '" + name + "' is not allowed at " + child.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          return true;
      }
  
      protected boolean isParameter(Configuration config) throws ConfigurationException {
          String name = config.getName();
          if (name.equals(this.treeBuilder.getParameterName())) {
              if (this.hasParameters()) {
                  return true;
              } else {
                  String msg = "Element '" + name + "' has no parameters at " + config.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
          }
          return false;
      }
  
      /**
       * Create the <code>ProcessingNode</code>s for the children of a given node.
       * Child nodes are controlled to be actually allowed in this node.
       */
      protected List buildChildNodesList(Configuration config) throws Exception {
  
          Configuration[] children = config.getChildren();
          List result = new ArrayList();
  
          for (int i = 0; i < children.length; i++) {
  
              Configuration child = children[i];
              try {
                   if (isChild(child)) {
                      // OK : get a builder.
                      ProcessingNodeBuilder childBuilder = this.treeBuilder.createNodeBuilder(child);
                      result.add(childBuilder.buildNode(child));
                  }
  
              } catch(ConfigurationException ce) {
                  throw ce;
              } catch(Exception e) {
                  String msg = "Error while creating node '" + child.getName() + "' at " + child.getLocation();
                  getLogger().error(msg, e);
                  throw new ConfigurationException(msg, e);
              }
          }
  
          return result;
      }
  
      protected ProcessingNode[] buildChildNodes(Configuration config) throws Exception {
          return toNodeArray(buildChildNodesList(config));
      }
  
      /**
       * Convenience function that converts a <code>List</code> of <code>ProcessingNode</code>s
       * to an array.
       */
      public static ProcessingNode[] toNodeArray(List list) {
          return (ProcessingNode[])list.toArray(new ProcessingNode[list.size()]);
      }
  
      /**
       * 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, ", \t\n\r"));
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java
  
  Index: AbstractProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  
  import org.apache.cocoon.environment.SourceResolver;
  
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AbstractProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class AbstractProcessingNode extends AbstractLoggable implements ProcessingNode {
  
      protected String location = "unknown location";
  
      /**
       * Get the <code>SourceResolver</code> in an object model.
       */
      protected static final SourceResolver getSourceResolver(Map objectModel) {
          return (SourceResolver)objectModel.get(OBJECT_SOURCE_RESOLVER);
      }
  
      /**
       * Get the location of this node.
       */
      public String getLocation() {
          return this.location;
      }
  
      /**
       * Set the location of this node.
       */
      public void setLocation(String location) {
          this.location = location;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
  
  Index: AbstractProcessingNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AbstractProcessingNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  
  public abstract class AbstractProcessingNodeBuilder extends AbstractLoggable
    implements ProcessingNodeBuilder {
  
      protected TreeBuilder treeBuilder;
  
      public void setBuilder(TreeBuilder treeBuilder) {
          this.treeBuilder = treeBuilder;
      }
  
      /**
       * Does this node accept parameters ? Default is true : if a builder that doesn't
       * have parameters doesn't override this method, erroneous parameters will be silently
       * ignored.
       */
      protected boolean hasParameters() {
          return true;
      }
  
      /**
       * Get &lt;xxx:parameter&gt; elements as a <code>Map</code> of </code>ListOfMapResolver</code>s,
       * that can be turned into parameters using <code>ListOfMapResolver.buildParameters()</code>.
       *
       * @return the Map of ListOfMapResolver, or <code>null</code> if there are no parameters.
       */
      protected Map getParameters(Configuration config) throws ConfigurationException {
          Configuration[] children = config.getChildren("parameter");
  
          if (children.length == 0) {
              return null;
          }
  
          Map params = new HashMap();
          for (int i = 0; i < children.length; i++) {
              Configuration child = children[i];
              if (true) { // FIXME : check namespace
                  String value = child.getAttribute("value");
                  try {
                      params.put(child.getAttribute("name"), MapStackResolver.getResolver(value));
                  } catch(PatternException pe) {
                      String msg = "Invalid pattern '" + value + " at " + child.getLocation();
                      getLogger().error(msg, pe);
                      throw new ConfigurationException(msg, pe);
                  }
              }
          }
  
          return params;
      }
  
      /**
       * Check if the namespace URI of the given configuraition is the same as the
       * one given by the builder.
       */
      protected void checkNamespace(Configuration config) throws ConfigurationException {
          if (!this.treeBuilder.getNamespace().equals(config.getNamespace()))
          {
              String msg = "Invalid namespace '" + config.getNamespace() + "' at " + config.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java
  
  Index: CategoryNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.ProcessingException;
  
  import java.util.*;
  
  /**
   * A generic container node that just invokes its children.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: CategoryNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public final class CategoryNode extends AbstractParentProcessingNode {
  
      /** The name of this category */
      private String categoryName;
  
      /** The Map of named nodes in this category */
      private Map nodes;
  
      public void setCategory(String categoryName, Map nodes) {
          this.categoryName = categoryName;
          this.nodes = (nodes != null) ? nodes : new HashMap(0);
      }
  
      public final boolean invoke(Environment env, InvokeContext context) throws Exception {
          String msg = "Cannot invoke " + this.categoryName + " at " + getLocation();
          getLogger().error(msg);
          throw new ProcessingException(msg);
      }
  
      public final ProcessingNode getNodeByName(String name) throws Exception {
          ProcessingNode node = (ProcessingNode)nodes.get(name);
          if (node == null) {
              String msg = "Unknown " + this.categoryName + " named '" + name + "' at " + getLocation();
              getLogger().error(msg);
              throw new ProcessingException(msg);
          }
  
          return node;
      }
  
      public final boolean invokeByName(String name, Environment env, InvokeContext context)
        throws Exception {
  
          return getNodeByName(name).invoke(env, context);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java
  
  Index: CategoryNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import java.util.*;
  
  /**
   * Builds a generic container node.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: CategoryNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class CategoryNodeBuilder extends AbstractParentProcessingNodeBuilder
    implements Configurable, ThreadSafe {
  
      // Prefix used for registering as a TreeBuilder attribute
      private static String PREFIX = CategoryNodeBuilder.class.getName() + "/";
  
      protected String name;
  
      /**
       * The category name is the value of the "category-name" child, or if not
       * present, the name of the configuration element.
       */
      public void configure(Configuration config) throws ConfigurationException {
          super.configure(config);
          this.name = config.getChild("category-name").getValue(config.getAttribute("name"));
      }
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          CategoryNode node = new CategoryNode();
          this.treeBuilder.setupNode(node, config);
  
          // Get all children and associate them to their name
          Map category = new HashMap();
  
          List children = buildChildNodesList(config);
          Iterator iter = children.iterator();
          while(iter.hasNext()) {
              NamedProcessingNode child = (NamedProcessingNode)iter.next();
              category.put(child.getName(), child);
          }
  
          node.setCategory(this.name, category);
  
          // Register node to allow lookup by other nodes
          this.treeBuilder.registerNode(PREFIX + this.name, node);
  
          return node;
      }
  
      public static CategoryNode getCategoryNode(TreeBuilder builder, String categoryName) {
          return (CategoryNode)builder.getRegisteredNode(PREFIX + categoryName);
      }
  
      public static ProcessingNode getNamedNode(TreeBuilder builder, String categoryName, String nodeName)
        throws Exception {
          CategoryNode category = getCategoryNode(builder, categoryName);
  
          return category.getNodeByName(nodeName);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java
  
  Index: ContainerNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  
  import java.util.*;
  
  /**
   * A generic container node that just invokes its children.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ContainerNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class ContainerNode extends SimpleParentProcessingNode {
  
      public final boolean invoke(Environment env, InvokeContext context) throws Exception {
  
          return invokeNodes(this.children, env, context);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java
  
  Index: ContainerNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import java.util.*;
  
  /**
   * Builds a generic container node.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ContainerNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class ContainerNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          ContainerNode node = new ContainerNode();
          setupNode(node, config);
  
          return node;
      }
  
      protected void setupNode(ContainerNode node, Configuration config)throws Exception {
  
          this.treeBuilder.setupNode(node, config);
  
          ProcessingNode[] children = buildChildNodes(config);
          if (children.length == 0) {
              String msg = "There must be at least one child at " + config.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          node.setChildren(children);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/EnvironmentSourceResolver.java
  
  Index: EnvironmentSourceResolver.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentManager;
  
  import org.apache.cocoon.components.source.SourceHandler;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.ProcessingException;
  
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.net.URL;
  
  /**
   * A <code>SourceResolver</code> that resolves URIs relative to an <code>Environment</code>.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: EnvironmentSourceResolver.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class EnvironmentSourceResolver implements SourceResolver, Disposable {
  
      private ComponentManager manager;
  
      private Source contextSource;
  
      private SourceHandler sourceHandler;
  
      public EnvironmentSourceResolver(ComponentManager manager, Environment env) throws Exception {
          this.manager = manager;
          this.contextSource = env.resolve("");
          this.sourceHandler = (SourceHandler)manager.lookup(SourceHandler.ROLE);
      }
  
      /**
       * Resolve an entity.
       */
      public Source resolve(String systemId) throws ProcessingException, SAXException, IOException {
          if (systemId == null) throw new SAXException("Cannot resolve a null system ID !");
  
          URL context = new URL(this.contextSource.getSystemId());
  
          if (systemId.length() == 0)
              return this.sourceHandler.getSource(null, context, systemId);
          if (systemId.indexOf(":") > 1)
              return this.sourceHandler.getSource(null, systemId);
          if (systemId.charAt(0) == '/')
              return this.sourceHandler.getSource(null, context.getProtocol() + ":" + systemId);
          return this.sourceHandler.getSource(null, context, systemId);
      }
  
      public void dispose() {
          if (contextSource != null)
          {
              contextSource.recycle();
          }
          manager.release(sourceHandler);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java
  
  Index: InvokeContext.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Recomposable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.framework.logger.Loggable;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.log.Logger;
  
  import java.util.*;
  
  /**
   * The invocation context of <code>ProcessingNode</code>s.
   * <p>
   * This class serves two purposes :
   * <ul><li>Avoid explicit enumeration of all needed parameters in
   *         {@link ProcessingNode#invoke(Environment, InvokeContext)},
   *         thus allowing easier addition of new parameters,
   *     <li>Hold pipelines, and provide "just in time" lookup for them.
   * </ul>
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: InvokeContext.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class InvokeContext implements Recomposable, Disposable, Loggable {
  
      private List mapStack = new ArrayList();
  
      private StreamPipeline streamPipeline;
  
      private EventPipeline eventPipeline;
  
      private boolean isInternalRequest;
  
      /** The current component manager, as set by the last call to compose() or recompose() */
      private ComponentManager currentManager;
  
      /** The component manager that was used to get the pipelines */
      private ComponentManager pipelinesManager;
  
      /** Logger that we will log any messages to */
      private Logger logger;
  
      /**
       * Create an <code>InvokeContext</code> without existing pipelines. This also means
       * the current request is external.
       */
      public InvokeContext() {
          this.isInternalRequest = false;
      }
  
      /**
       * Create an <code>InvokeContext</code> with existing pipelines. This also means
       * the current request is internal.
       */
      public InvokeContext(StreamPipeline pipeline, EventPipeline eventPipeline) {
          this.isInternalRequest = true;
          this.streamPipeline = pipeline;
          this.eventPipeline = eventPipeline;
      }
  
      public void setLogger(Logger logger)
      {
          this.logger = logger;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
          this.currentManager = manager;
      }
  
      public void recompose(ComponentManager manager) throws ComponentException {
  
          this.currentManager = manager;
  
          // Recompose pipelines, if any.
          if (this.streamPipeline != null) {
              this.streamPipeline.recompose(manager);
              this.eventPipeline.recompose(manager);
          }
      }
  
      /**
       * Get the <code>EventPipeline</code>. If none already exists, a set of new
       * pipelines is looked up.
       */
      public final EventPipeline getEventPipeline() throws Exception {
          if (this.eventPipeline == null) {
              setupPipelines();
          }
          return this.eventPipeline;
      }
  
      /**
       * Get the <code>StreamPipeline</code>. If none already exists, a set of new
       * pipelines is looked up.
       */
      public final StreamPipeline getStreamPipeline() throws Exception {
          if (this.streamPipeline == null) {
              setupPipelines();
          }
          return this.streamPipeline;
      }
  
      private final void setupPipelines() throws Exception {
          // Keep current manager for proper release
          this.pipelinesManager = this.currentManager;
  
          // Lookup pipelines
          this.eventPipeline  = (EventPipeline)this.pipelinesManager.lookup(EventPipeline.ROLE);
          this.streamPipeline = (StreamPipeline)this.pipelinesManager.lookup(StreamPipeline.ROLE);
          this.streamPipeline.setEventPipeline(this.eventPipeline);
  
          // Immediately recompose them to the current manager : pipelines are created
          // by a parent of the current manager, but need to select component in this one,
          // and not its parent.
          this.eventPipeline.recompose(this.pipelinesManager);
          this.streamPipeline.recompose(this.pipelinesManager);
      }
  
      /**
       * Is this an internal request ?
       */
      public final boolean isInternalRequest() {
          return this.isInternalRequest;
      }
  
      /**
       * Get the current Map stack used to resolve expressions.
       */
      public final List getMapStack() {
          return this.mapStack;
      }
  
      /**
       * Push a Map on top of the current Map stack.
       */
      public final void pushMap(Map map) {
          mapStack.add(map);
  
          if (this.logger.isDebugEnabled()) {
              dumpParameters(getMapStack());
          }
      }
  
      /**
       * Dumps all sitemap parameters to log
       */
      protected void dumpParameters(List list)
      {
          if (!list.isEmpty()) {
              StringBuffer sb = new StringBuffer();
  
              sb.append("\nCurrent Sitemap Parameters:\n");
              String path = "";
  
              for (int i = list.size() - 1; i >= 0; i--) {
                  Map map = (Map) list.get(i);
                  Iterator keys = map.keySet().iterator();
  
                  while (keys.hasNext()) {
                      String key = (String) keys.next();
                      sb.append("PARAM: '").append(path).append(key);
                      sb.append("' VALUE: '").append(map.get(key)).append("'\n");
                  }
  
                  path = "../" + path;
              }
  
              this.logger.debug(sb.toString());
          }
      }
  
  
      /**
       * Pop the topmost element of the current Map stack.
       */
      public final void popMap() {
          mapStack.remove(mapStack.size() - 1);
      }
  
      /**
       * Release the pipelines, if any, if they were looked up by this context.
       */
      public void dispose() {
          // Release pipelines, if any
          if (!this.isInternalRequest && this.pipelinesManager != null) {
  
              this.pipelinesManager.release(this.eventPipeline);
              this.pipelinesManager.release(this.streamPipeline);
  
              this.pipelinesManager = null;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/LinkedProcessingNodeBuilder.java
  
  Index: LinkedProcessingNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  /**
   * A <code>ProcessingNode</code> builder that links its node to
   * other nodes in the hierarchy. This allows to turn the node tree
   * into a directed graph.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: LinkedProcessingNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public interface LinkedProcessingNodeBuilder extends ProcessingNodeBuilder {
  
      /**
       * Resolve the links needed by the node built by this builder.
       */
      void linkNode() throws Exception;
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/MapStackResolver.java
  
  Index: MapStackResolver.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import java.util.*;
  
  /**
   * Utility class for handling {...} pattern substitutions from a List of Maps.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: MapStackResolver.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class MapStackResolver {
  
      public static final Map EMPTY_MAP = Collections.unmodifiableMap(new java.util.HashMap(0));
  
      /**
       * Resolve all {...} patterns using the values given in the list of maps.
       */
      public abstract String resolve(List mapStack) throws PatternException;
  
      /**
       * Does an expression need resolving (i.e. contain {...} patterns) ?
       */
      public static boolean needsResolve(String expression) {
          if (expression == null || expression.length() == 0) {
              return false;
          }
  
          // Is the first char a '{' ?
          if (expression.charAt(0) == '{') {
              return true;
          }
  
          if (expression.length() < 2) {
              return false;
          }
  
          // Is there any unescaped '{' ?
          int pos = 1;
          while ( (pos = expression.indexOf('{', pos)) != -1) {
              // Found a '{' : is it escaped ?
              if (expression.charAt(pos - 1) != '\\') {
                  // No : need to resolve
                  return true;
              }
              pos++;
          }
          // Nothing found...
          return false;
      }
  
      /**
       * Unescape an expression that doesn't need to be resolved, but may contain
       * escaped '{' characters.
       *
       * @param expression the expression to unescape.
       * @return the unescaped result, or <code>expression</code> if unescaping isn't necessary.
       */
      public static String unescape(String expression) {
          // Does it need escaping ?
          if (expression == null || expression.indexOf("\\{") == -1) {
              return expression;
          }
  
          StringBuffer buf = new StringBuffer();
          for (int i = 0; i < expression.length(); i++) {
              char ch = expression.charAt(i);
              if (ch != '\\' || i >= (expression.length() - 1) || expression.charAt(i+1) != '{') {
                  buf.append(ch);
              }
          }
  
          return buf.toString();
      }
  
      /**
       * Get a resolver for a given expression. Chooses the most efficient implementation
       * depending on <code>expression</code>.
       */
      public static MapStackResolver getResolver(String expression) throws PatternException {
          if (needsResolve(expression)) {
  //            return new RealResolver(expression);
              return new CompiledResolver(expression);
          } else {
              return new NullResolver(expression);
          }
      }
  
      /**
       * Build a <code>Parameters</code> object from a Map of named <code>ListOfMapResolver</code>s and
       * a list of Maps used for resolution.
       *
       * @return a fully resolved <code>Parameters</code>.
       */
      public static Parameters buildParameters(Map expressions, List mapStack) throws PatternException {
          if (expressions == null || expressions.size() == 0) {
              return Parameters.EMPTY_PARAMETERS;
          }
  
          Parameters result = new Parameters();
  
          Iterator iter = expressions.entrySet().iterator();
          while (iter.hasNext()) {
              Map.Entry entry = (Map.Entry)iter.next();
              String value = ((MapStackResolver)entry.getValue()).resolve(mapStack);
              result.setParameter((String)entry.getKey(), value);
          }
  
          return result;
      }
  
      /**
       * Resolve all values of a <code>Map</code> from a Map of named <code>ListOfMapResolver</code>s and
       * a list of Maps used for resolution.
       *
       * @return a fully resolved <code>Map</code>.
       */
      public static Map resolveMap(Map expressions, List mapStack) throws PatternException {
          int size;
          if (expressions == null || (size = expressions.size()) == 0) {
              return EMPTY_MAP;
          }
  
          Map result = new HashMap(size);
  
          Iterator iter = expressions.entrySet().iterator();
          while (iter.hasNext()) {
              Map.Entry entry = (Map.Entry)iter.next();
              String value = ((MapStackResolver)entry.getValue()).resolve(mapStack);
              result.put(entry.getKey(), value);
          }
  
          return result;
      }
  
      //-------------------------------------------------------------------------
      /**
       * No-op resolver for expressions that don't need to be resolved.
       */
      private static class NullResolver extends MapStackResolver {
          private String originalExpr = null;
          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 final String resolve(List mapStack) {
              return this.expression;
          }
      }
  
      //-------------------------------------------------------------------------
  
      /**
       * Compiled form for faster substitution
       */
      private static class CompiledResolver extends MapStackResolver {
          private String originalExpr;
  
          private String[] strings;
          private int[] levels;
  
          public CompiledResolver(String expression) throws PatternException {
              this.originalExpr = expression;
              compile(expression);
          }
  
          public String toString() {
              return this.originalExpr;
          }
  
          private void compile(String expr) throws PatternException {
              // We're sure here that expr *contains* some substitutions
  
              List stringList = new ArrayList();
              List levelList  = new ArrayList();
  
              int length = expr.length();
              int prev = 0; // position after last closing brace
  
              comp : while(prev < length) {
                  // find next unescaped '{'
                  int pos = prev;
                  while(pos < length &&
                        (pos = expr.indexOf('{', pos)) != -1 &&
                        (pos != 0 && expr.charAt(pos - 1) == '\\')) {
                      pos++;
                  }
  
                  if (pos >= length || pos == -1) {
                      // no more braces
                      if (prev < length) {
                          stringList.add(this.unescape(expr.substring(prev)));
                          levelList.add(new Integer(-1));
                      }
                      break comp;
                  }
  
                  // Pass closing brace
                  pos++;
  
                  // Add litteral strings between closing and next opening brace
                  if (prev < pos-1) {
                      stringList.add(this.unescape(expr.substring(prev, pos - 1)));
                      levelList.add(new Integer(-1));
                  }
  
                  // Determine subst level
                  int level = 1; // Start at 1 since it will be substracted from list.size()
                  while(expr.startsWith("../", pos)) {
                      level++;
                      pos += "../".length();
                  }
  
                  int end = expr.indexOf('}', pos);
                  if (end == -1) {
                      throw new PatternException("Unmatched '{' in " + expr);
                  }
  
                  stringList.add(expr.substring(pos, end));
                  levelList.add(new Integer(level));
  
                  prev = end + 1;
              }
  
              this.strings = new String[stringList.size()];
              this.levels = new int[stringList.size()];
              for (int i = 0; i < strings.length; i++) {
                  this.strings[i] = (String)stringList.get(i);
                  this.levels[i] = ((Integer)levelList.get(i)).intValue();
              }
          }
  
          public final String resolve(List mapStack) throws PatternException {
              StringBuffer result = new StringBuffer();
              int stackSize = mapStack.size();
  
              for (int i = 0; i < this.strings.length; i++) {
                  int level = this.levels[i];
                  if (level == -1) {
                      result.append(this.strings[i]);
  
                  } else {
                      if (level > stackSize) {
                          throw new PatternException("Error while evaluating '" + this.originalExpr +
                              "' : not so many levels");
                      }
  
                      Object value = ((Map)mapStack.get(stackSize - level)).get(this.strings[i]);
                      if (value != null) {
                          result.append(value);
                      }
                  }
              }
  
              return result.toString();
          }
  
  //        public void dump() {
  //            System.out.println(this.originalExpr + " compiled in :");
  //            for (int i = 0; i < this.strings.length; i++) {
  //                System.out.print("[" + this.levels[i] + ":'" + this.strings[i] + "'] ");
  //            }
  //            System.out.println();
  //            System.out.println();
  //        }
      }
  
  //    public static void main(String [] args) throws Exception {
  //
  //        new CompiledResolver("&{../../blah}").dump();
  //        new CompiledResolver("{t1}tt{t2}x").dump();
  //        new CompiledResolver("\\{t1}tt{t2}xx").dump();
  //        new CompiledResolver("{t1}tt\\{t2}xx").dump();
  //        new CompiledResolver("{t1}tt{t2}xx").dump();
  //        new CompiledResolver("xx{../t1}{../../../t2}zz").dump();
  //        new CompiledResolver("xx{../t1}\\{../../../t2}zz").dump();
  //
  //    }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/NamedContainerNode.java
  
  Index: NamedContainerNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  
  /**
   * A named container node that just invokes its children.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: NamedContainerNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class NamedContainerNode extends ContainerNode implements NamedProcessingNode {
  
      private String name;
  
      public NamedContainerNode(String name) {
          this.name = name;
      }
  
      public String getName() {
          return this.name;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/NamedContainerNodeBuilder.java
  
  Index: NamedContainerNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Builds a generic named container node.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: NamedContainerNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class NamedContainerNodeBuilder extends ContainerNodeBuilder implements Configurable {
  
      private String nameAttr;
  
      public void configure(Configuration config) throws ConfigurationException {
          super.configure(config);
          this.nameAttr = config.getChild("name-attribute").getValue("name");
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          NamedContainerNode node = new NamedContainerNode(config.getAttribute(this.nameAttr));
          this.setupNode(node, config);
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/NamedProcessingNode.java
  
  Index: NamedProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  /**
   * A <code>ProcessingNode</code> that has a name. This is primarily used by
   * <code>CategoryNode</code> to access its children.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: NamedProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public interface NamedProcessingNode extends ProcessingNode {
  
      String getName();
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/NullNode.java
  
  Index: NullNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.environment.Environment;
  
  /**
   * A no-op node to stub not yet implemented features.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: NullNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class NullNode extends AbstractProcessingNode {
  
      public final boolean invoke(Environment env, InvokeContext context) throws Exception {
  
          getLogger().debug("Invoke on NullNode at " + getLocation());
          return false;
  
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/NullNodeBuilder.java
  
  Index: NullNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: NullNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class NullNodeBuilder extends AbstractProcessingNodeBuilder {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
          return this.treeBuilder.setupNode(new NullNode(), config);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/ParameterizableProcessingNode.java
  
  Index: ParameterizableProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import java.util.Map;
  
  /**
   * A <code>ProcessingNode</code> that has parameters.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ParameterizableProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public interface ParameterizableProcessingNode extends ProcessingNode {
  
      /**
       * Set the parameters of this node as a <code>Map</code> of <code>MapStackResolver</code>s
       * that will be resolved at process-time.
       */
      void setParameters(Map parameterMap);
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/ProcessingNode.java
  
  Index: ProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.Environment;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public interface ProcessingNode extends ThreadSafe {
  
      /**
       * The key of the <code>SourceResolver</code> in the object model.
       */
      String OBJECT_SOURCE_RESOLVER = "source-resolver";
  
      /**
       * Process environment.
       */
      boolean invoke(Environment env, InvokeContext context) throws Exception;
  
      /**
       * Get the location of this node.
       */
      String getLocation();
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/ProcessingNodeBuilder.java
  
  Index: ProcessingNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import java.util.Map;
  
  /**
   * A <code>ProcessingNode</code> builder.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ProcessingNodeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public interface ProcessingNodeBuilder extends Component {
  
      /**
       * Set the builder for which we are building.
       */
      void setBuilder(TreeBuilder builder);
  
      /**
       * Build the {@link ProcessingNode} and its children from the given
       * <code>Configuration</code>, and optionnaly register it in the {@link Builder}
       * for lookup by other <code>LinkedProcessingNodeBuilder</code>s.
       */
      ProcessingNode buildNode(Configuration config) throws Exception;
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/SimpleParentProcessingNode.java
  
  Index: SimpleParentProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SimpleParentProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class SimpleParentProcessingNode extends AbstractParentProcessingNode {
  
      /** The childrens of this matcher */
      protected ProcessingNode[] children;
  
      public void setChildren(ProcessingNode[] children) {
          this.children = children;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/SimpleSelectorProcessingNode.java
  
  Index: SimpleSelectorProcessingNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.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.components.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SimpleSelectorProcessingNode.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public abstract class SimpleSelectorProcessingNode extends SimpleParentProcessingNode {
  
      /** 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 ComponentException {
          this.selector = selector;
      }
  
      /**
       * 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 {
          return getThreadSafeComponent(this.componentName);
      }
  
      /**
       * 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(String name) throws ComponentException {
          Component component = this.selector.select(name);
          if (component instanceof ThreadSafe) {
              return component;
          } else {
              this.selector.release(component);
              return null;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java
  
  Index: TreeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.excalibur.component.DefaultRoleManager;
  import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
  import org.apache.avalon.excalibur.component.RoleManageable;
  import org.apache.avalon.excalibur.component.RoleManager;
  import org.apache.avalon.excalibur.logger.LogKitManageable;
  import org.apache.avalon.excalibur.logger.LogKitManager;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentSelector;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.ContextException;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  
  import org.apache.cocoon.components.ExtendedComponentSelector;
  import org.apache.cocoon.components.LifecycleHelper;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.util.ClassUtils;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: TreeBuilder.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class TreeBuilder extends AbstractLoggable implements
    Composable, Configurable, Contextualizable, LogKitManageable, RoleManageable, Disposable {
  
      /**
       * The tree processor that we're building.
       */
      protected TreeProcessor processor;
  
      //----- lifecycle-related objects ------
      protected Context context;
  
      protected LogKitManager logKit;
  
      /**
       * The parent component manager, set using <code>compose()</code> (implementation of
       * <code>Composable</code>).
       */
      protected ComponentManager parentManager;
  
      /**
       * The parent role manager, set using <code>setRoleManager</code> (implementation of
       * <code>createRoleManager</code>).
       */
      protected RoleManager parentRoleManager;
  
      protected Configuration configuration;
      // -------------------------------------
  
      /**
       * Component manager created by {@link #createComponentManager()}.
       */
      protected ComponentManager manager;
  
      /**
       * Role manager result created by {@link #createRoleManager()}.
       */
      protected RoleManager roleManager;
  
      /** Selector for ProcessingNodeBuilders */
      protected ComponentSelector builderSelector;
  
      protected LifecycleHelper lifecycle;
  
      protected String namespace;
  
      protected String parameterElement;
  
      protected String languageName;
  
      /** Nodes gone through setupNode() that implement Initializable */
      private List initializableNodes = new ArrayList();
  
      /** Nodes gone through setupNode() that implement Disposable */
      private List disposableNodes = new ArrayList();
  
      /** NodeBuilders created by createNodeBuilder() that implement LinkedProcessingNodeBuilder */
      private List linkedBuilders = new ArrayList();
  
      /** Are we in a state that allows to get registered nodes ? */
      private boolean canGetNode = false;
  
      /** Nodes registered using registerNode() */
      private Map registeredNodes = new HashMap();
  
      /** Attributes set using setAttribute() */
      private Map attributes = new HashMap();
  
  
      public void contextualize(Context context) throws ContextException {
          this.context = context;
      }
  
      public void setLogKitManager(LogKitManager logKit) {
          this.logKit = logKit;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
          this.parentManager = manager;
      }
  
      public void setRoleManager(RoleManager rm) {
          this.parentRoleManager = rm;
      }
  
      public void configure(Configuration config) throws ConfigurationException {
          this.configuration = config;
  
          this.languageName = config.getAttribute("name");
          getLogger().debug("Configuring Builder for language : " + this.languageName);
  
          this.namespace = config.getChild("namespace").getAttribute("uri", "");
  
          this.parameterElement = config.getChild("parameter").getAttribute("element", "parameter");
      }
  
      /**
       * Create a role manager that will be used by all <code>RoleManageable</code>
       * components. The default here is to create a role manager with the contents of
       * the &lt;roles&gt; element of the configuration.
       * <p>
       * Subclasses can redefine this method to create roles from other sources than
       * the one used here.
       *
       * @return the role manager
       */
      protected RoleManager createRoleManager() throws Exception
      {
          RoleManager roles = new DefaultRoleManager();
  
          LifecycleHelper.setupComponent(roles,
              getLogger(),
              this.context,
              this.manager,
              this.parentRoleManager,
              this.logKit,
              this.configuration.getChild("roles")
          );
  
          return roles;
      }
  
      /**
       * Create a component manager that will be used for all <code>Composable</code>
       * <code>ProcessingNodeBuilder</code>s and <code>ProcessingNode</code>s.
       * <p>
       * The default here is to simply return the manager set by <code>compose()</code>,
       * i.e. the component manager set by the calling <code>TreeProcessor</code>.
       * <p>
       * Subclasses can redefine this method to create a component manager local to a tree,
       * such as for sitemap's &lt;map:components&gt;.
       *
       * @return a component manager
       */
      protected ComponentManager createComponentManager(Configuration tree) throws Exception
      {
          return this.parentManager;
      }
  
      /**
       * Create a <code>ComponentSelector</code> for <code>ProcessingNodeBuilder</code>s.
       * It creates a selector with the contents of the "node" element of the configuration.
       *
       * @return a selector for node builders
       */
      protected ComponentSelector createBuilderSelector() throws Exception {
  
          // Create the NodeBuilder selector.
          ExcaliburComponentSelector selector = new ExtendedComponentSelector() {
              protected String getComponentInstanceName() {
                  return "node";
              }
  
              protected String getClassAttributeName() {
                  return "builder";
              }
          };
  
          // Automagically initialize the selector
          LifecycleHelper.setupComponent(selector,
              getLogger(),
              this.context,
              this.manager,
              this.roleManager,
              this.logKit,
              this.configuration.getChild("nodes")
          );
  
          return selector;
      }
  
      public void setProcessor(TreeProcessor processor) {
          this.processor = processor;
      }
  
      public TreeProcessor getProcessor() {
          return this.processor;
      }
  
      /**
       * Returns the language that is being built (e.g. "sitemap").
       */
      public String getLanguage() {
          return this.languageName;
      }
  
      /**
       * Returns the name of the parameter element.
       */
      public String getParameterName() {
          return this.parameterElement;
      }
  
      /**
       * Register a <code>ProcessingNode</code> under a given name.
       * For example, <code>ResourceNodeBuilder</code> stores here the <code>ProcessingNode</code>s
       * it produces for use by sitemap pipelines. This allows to turn the tree into a graph.
       */
      public void registerNode(String name, ProcessingNode node) {
          this.registeredNodes.put(name, node);
      }
  
      public ProcessingNode getRegisteredNode(String name) {
          if (this.canGetNode) {
              return (ProcessingNode)this.registeredNodes.get(name);
          } else {
              throw new IllegalArgumentException("Categories are only available during buildNode()");
          }
      }
  
      public void setAttribute(String name, Object value) {
          this.attributes.put(name, value);
      }
  
      public Object getAttribute(String name) {
          return this.attributes.get(name);
      }
  
      public ProcessingNodeBuilder createNodeBuilder(Configuration config) throws Exception {
          //FIXME : check namespace
          String nodeName = config.getName();
  
          getLogger().debug("Creating node builder for " + nodeName);
  
          ProcessingNodeBuilder builder;
          try {
              builder = (ProcessingNodeBuilder)this.builderSelector.select(nodeName);
  
          } catch(ComponentException ce) {
              // Is it because this element is unknown ?
              if (this.builderSelector.hasComponent(nodeName)) {
                  // No : rethrow
                  throw ce;
              } else {
                  // Throw a more meaningfull exception
                  String msg = "Unkown element '" + nodeName + "' at " + config.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
          }
  
          builder.setBuilder(this);
  
          if (builder instanceof LinkedProcessingNodeBuilder) {
              this.linkedBuilders.add(builder);
          }
  
          return builder;
      }
  
      /**
       * Create the tree once component manager and node builders have been set up.
       * Can be overriden by subclasses to perform pre/post tree creation operations.
       */
      protected ProcessingNode createTree(Configuration tree) throws Exception {
          // Create a node builder from the top-level element
          ProcessingNodeBuilder rootBuilder = createNodeBuilder(tree);
  
          // Build the whole tree (with an empty buildModel)
          return rootBuilder.buildNode(tree);
      }
  
      /**
       * Resolve links : call <code>linkNode()</code> on all
       * <code>LinkedProcessingNodeBuilder</code>s.
       * Can be overriden by subclasses to perform pre/post resolution operations.
       */
      protected void linkNodes() throws Exception {
          // Resolve links
          Iterator iter = this.linkedBuilders.iterator();
          while(iter.hasNext()) {
              ((LinkedProcessingNodeBuilder)iter.next()).linkNode();
          }
      }
  
      /**
       * Get the namespace URI that builders should use to find their nodes.
       */
      public String getNamespace() {
          return this.namespace;
      }
  
      /**
       * Build a processing tree from a <code>Configuration</code>.
       */
      public ProcessingNode build(Configuration tree) throws Exception {
  
          this.roleManager = createRoleManager();
  
          this.manager = createComponentManager(tree);
  
          // Create a helper object to setup components
          this.lifecycle = new LifecycleHelper(getLogger(),
              this.context,
              this.manager,
              this.roleManager,
              this.logKit,
              null // configuration
          );
  
          this.builderSelector = createBuilderSelector();
  
          // Calls to getRegisteredNode() are forbidden
          this.canGetNode = false;
  
          ProcessingNode result = createTree(tree);
  
          // Calls to getRegisteredNode() are now allowed
          this.canGetNode = true;
  
          linkNodes();
  
          // Initialize all Initializable nodes
          Iterator iter = this.initializableNodes.iterator();
          while(iter.hasNext()) {
              ((Initializable)iter.next()).initialize();
          }
  
          // And that's all !
          return result;
      }
  
      /**
       * Return the list of <code>ProcessingNodes</code> part of this tree that are
       * <code>Disposable</code>. Care should be taken to properly dispose them before
       * trashing the processing tree.
       */
      public List getDisposableNodes() {
          return this.disposableNodes;
      }
  
      /**
       * Setup a <code>ProcessingNode</code> by setting its location, calling all
       * the lifecycle interfaces it implements and giving it the parameter map if
       * it's a <code>ParameterizableNode</code>.
       * <p>
       * As a convenience, the node is returned by this method to allow constructs
       * like <code>return treeBuilder.setupNode(new MyNode(), config)</code>.
       */
      public ProcessingNode setupNode(ProcessingNode node, Configuration config)
        throws Exception {
          if (node instanceof AbstractProcessingNode) {
              ((AbstractProcessingNode)node).setLocation(config.getLocation());
          }
  
          this.lifecycle.setupComponent(node, false);
  
          if (node instanceof ParameterizableProcessingNode) {
              Map params = getParameters(config);
              ((ParameterizableProcessingNode)node).setParameters(params);
          }
  
          if (node instanceof Initializable) {
              this.initializableNodes.add(node);
          }
  
          if (node instanceof Disposable) {
              this.disposableNodes.add(node);
          }
  
          return node;
      }
  
      /**
       * Get &lt;xxx:parameter&gt; elements as a <code>Map</code> of </code>ListOfMapResolver</code>s,
       * that can be turned into parameters using <code>ListOfMapResolver.buildParameters()</code>.
       *
       * @return the Map of ListOfMapResolver, or <code>null</code> if there are no parameters.
       */
      protected Map getParameters(Configuration config) throws ConfigurationException {
  
          Configuration[] children = config.getChildren(this.parameterElement);
  
          if (children.length == 0) {
              return null;
          }
  
          Map params = new HashMap();
          for (int i = 0; i < children.length; i++) {
              Configuration child = children[i];
              if (true) { // FIXME : check namespace
                  String value = child.getAttribute("value");
                  try {
                      params.put(child.getAttribute("name"), MapStackResolver.getResolver(value));
                  } catch(PatternException pe) {
                      String msg = "Invalid pattern '" + value + "' at " + child.getLocation();
                      getLogger().error(msg, pe);
                      throw new ConfigurationException(msg, pe);
                  }
              }
          }
  
          return params;
      }
  
      /**
       * Get the type for a statement : it returns the 'type' attribute if present,
       * and otherwhise the default hint of the <code>ExtendedSelector</code> designated by
       * role <code>role</code>.
       *
       * @throws ConfigurationException if the default type could not be found.
       */
      public String getTypeForStatement(Configuration statement, String role) throws ConfigurationException {
  
          String type = statement.getAttribute("type", null);
  
          ComponentSelector selector;
  
          try {
              selector = (ComponentSelector)this.manager.lookup(role);
          } catch(ComponentException ce) {
              String msg = "Cannot get component selector for '" + statement.getName() + "' at " +
                  statement.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          if (type == null && selector instanceof ExtendedComponentSelector) {
              type = ((ExtendedComponentSelector)selector).getDefaultHint();
          }
  
          if (type == null) {
              String msg = "No default type exists for '" + statement.getName() + "' at " +
                  statement.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          if (!selector.hasComponent(type)) {
              String msg = "Type '" + type + "' is not defined for '" + statement.getName() + "' at " +
                  statement.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          this.manager.release(selector);
  
          return type;
      }
  
      public void dispose() {
          LifecycleHelper.dispose(this.builderSelector);
  
          // Don't dispose manager or roles : they are used by the built tree
          // and thus must live longer than the builder.
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor;
  
  import org.apache.avalon.excalibur.component.RoleManageable;
  import org.apache.avalon.excalibur.component.RoleManager;
  import org.apache.avalon.excalibur.logger.LogKitManageable;
  import org.apache.avalon.excalibur.logger.LogKitManager;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  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.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.NamespacedSAXConfigurationHandler;
  import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.Processor;
  import org.apache.cocoon.components.CocoonComponentManager;
  import org.apache.cocoon.components.LifecycleHelper;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.components.source.CocoonSourceFactory;
  import org.apache.cocoon.components.source.DelayedRefreshSourceWrapper;
  import org.apache.cocoon.components.source.SourceHandler;
  import org.apache.cocoon.components.source.URLSource;
  import org.apache.cocoon.components.url.URLFactory;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Source;
  
  import java.io.InputStream;
  import java.util.*;
  
  /**
   * Interpreted tree-traversal implementation of a pipeline assembly language.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: TreeProcessor.java,v 1.1 2002/03/05 08:26:22 sylvain Exp $
   */
  
  public class TreeProcessor extends AbstractLoggable implements ThreadSafe, Processor,
    Composable, Configurable, LogKitManageable, RoleManageable, Initializable, Contextualizable, Disposable {
  
      private static final String XCONF_URL =
      	"resource://org/apache/cocoon/components/treeprocessor/treeprocessor-builtins.xml";
  
      /** The parent TreeProcessor, if any */
      protected TreeProcessor parent;
  
      /** The context */
      protected Context context;
  
      /** The component manager */
      protected ComponentManager manager;
  
      /** The logkit manager to get Loggers */
      protected LogKitManager logKit;
  
      /** The role manager */
      protected RoleManager roleManager;
  
      /** The language used by this processor */
      protected String language;
  
      /** The configuration for each language */
      protected Map languageConfigs;
  
      /** The root node of the processing tree */
      protected ProcessingNode rootNode;
  
      /** The list of processing nodes that should be disposed when disposing this processor */
      protected List disposableNodes;
  
      /** Last modification time */
      protected long lastModified = 0;
  
      /** The relative file name of the tree definition */
      protected String sourceName;
  
      /** The source of the tree definition */
      protected Source source;
  
      /** Delay for <code>sourceLastModified</code>. */
      protected long lastModifiedDelay;
  
      /** The current language configuration */
      protected Configuration currentLanguage;
  
      protected SourceHandler sourceHandler;
  
      protected Class treeBuilderClass;
  
      /**
       * Create a TreeProcessor.
       */
      public TreeProcessor() {
          // Language can be overriden in the configuration.
          this.language = "sitemap";
      }
  
      /**
       * Create a child processor for a given language
       */
      protected TreeProcessor(TreeProcessor parent, ComponentManager manager, String language) {
          this.parent = parent;
          this.language = (language == null) ? parent.language : language;
  
          // Copy all that can be copied from the parent
          this.context = parent.context;
          this.logKit = parent.logKit;
          this.languageConfigs = parent.languageConfigs;
  
          // We have our own CM
          this.manager = manager;
  
          // Other fields are setup in initialize()
      }
  
      /**
       * Create a new child of this processor (used for mounting submaps).
       *
       * @param manager the component manager to be used by the child processor.
       * @param language the language to be used by the child processor.
       * @return a new child processor.
       */
      public TreeProcessor createChildProcessor(
          ComponentManager manager,
          String language,
          Source source)
        throws Exception {
          
          TreeProcessor child = new TreeProcessor(this, manager, language);
          child.setLogger(getLogger());
          child.initialize();
          // FIXME : make the delay configurable
          child.source = new DelayedRefreshSourceWrapper(source, 1000L);
          return child;
      }
  
      public void contextualize(Context context) throws ContextException {
          this.context = context;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
          this.manager = manager;
      }
  
      public void setLogKitManager(LogKitManager logKit) {
          this.logKit = logKit;
      }
  
      public void setRoleManager(RoleManager rm) {
          this.roleManager = rm;
      }
  
  
  /*
    <processor>
      <reload delay="10"/>
      <root-language name="sitemap"/>
      <language>...</language>
    </processor>
  */
      public void configure(Configuration config) throws ConfigurationException {
  
          Configuration rootLangConfig = config.getChild("root-language", false);
          if (rootLangConfig != null) {
              this.language = rootLangConfig.getAttribute("name");
          }
  
          // Reload check delay. Default is 1 second.
          this.lastModifiedDelay = config.getChild("reload").getAttributeAsLong("delay", 1000L);
  
          // Read the builtin languages definition file
          Configuration builtin;
  
          try {
              URLFactory factory = (URLFactory)this.manager.lookup(URLFactory.ROLE);
              URLSource source = new URLSource(factory.getURL(XCONF_URL), this.manager);
              try {
                  SAXConfigurationHandler handler = new SAXConfigurationHandler();
                  source.toSAX(handler);
                  builtin = handler.getConfiguration();
              } finally {
                  this.manager.release((Component)factory);
                  if (source != null) {
                      source.recycle();
                  }
              }
          } catch(Exception e) {
              String msg = "Error while reading treeprocessor.xconf : " + e.getMessage();
              getLogger().error(msg, e);
              throw new ConfigurationException(msg, e);
          }
  
          this.languageConfigs = new HashMap();
  
          // Add builtin languages
          addLanguages("builtin", builtin.getChildren("language"));
  
          // Add additional languages from the configuration
          addLanguages("additional", config.getChildren("language"));
      }
  
      private void addLanguages(String type, Configuration[] languages)
        throws ConfigurationException {
  
          for (int i = 0; i < languages.length; i++) {
  
              String name = languages[i].getAttribute("name");
  
              if (this.languageConfigs.containsKey(name)) {
                  getLogger().info("Redefining language '" + name + "' in " + type + " configuration.");
              } else {
                  getLogger().debug("Adding " + type + " language '" + name + "'");
              }
  
              this.languageConfigs.put(name, languages[i]);
          }
      }
  
      public void initialize() throws Exception {
  
          this.currentLanguage = (Configuration)this.languageConfigs.get(this.language);
          if (this.currentLanguage == null) {
              throw new ConfigurationException("No configuration defined for language '" + this.language + "'");
          }
  
          Configuration fileConfig = this.currentLanguage.getChild("file", false);
          if (fileConfig == null) {
              throw new ConfigurationException("Missing 'file' configuration for language '" + this.language + "', at " +
                  this.currentLanguage.getLocation());
          }
  
          this.sourceName = fileConfig.getAttribute("name");
  
          // Get a new Source handler
          this.sourceHandler = (SourceHandler)this.manager.lookup(SourceHandler.ROLE);
  
          // and add the special "cocoon:" source factory
          this.sourceHandler.addFactory("cocoon", new CocoonSourceFactory(this, this.manager));
  
          // Get the TreeBuider class
          String builderClassName =
              this.currentLanguage.getAttribute("class", TreeBuilder.class.getName());
  
          try {
              this.treeBuilderClass = Thread.currentThread().getContextClassLoader().loadClass(builderClassName);
          } catch(Exception e) {
              String msg = "Cannot create class '" + builderClassName + "' at " +
                  this.currentLanguage.getLocation();
              getLogger().error(msg, e);
              throw new ConfigurationException(msg, e);
          }
      }
  
      public boolean process(Environment environment) throws Exception {
          InvokeContext context = new InvokeContext();
  
          context.setLogger(getLogger());
  
          try {
              return process(environment, context);
          } finally {
              context.dispose();
          }
      }
  
      public boolean process(Environment environment, StreamPipeline pipeline, EventPipeline eventPipeline)
        throws Exception {
          InvokeContext context = new InvokeContext(pipeline, eventPipeline);
  
          context.setLogger(getLogger());
  
          try {
              return process(environment, context);
          } finally {
              context.dispose();
          }
      }
  
      protected boolean process(Environment environment, InvokeContext context)
        throws Exception {
  
          SourceHandler oldSourceHandler = environment.getSourceHandler();
          CocoonComponentManager.enterEnvironment(environment, environment.getObjectModel());
  
          try {
              environment.setSourceHandler(this.sourceHandler);
              if (this.rootNode == null || this.source.getLastModified() > this.lastModified) {
                  setupRootNode(environment);
              }
              return this.rootNode.invoke(environment, context);
          } finally {
              CocoonComponentManager.leaveEnvironment();
              environment.setSourceHandler(oldSourceHandler);
          }
      }
  
      protected synchronized void setupRootNode(Environment env) throws Exception {
  
          // Now that we entered the synchronized area, recheck what's already
          // been checked in process().
          if (this.rootNode != null && source.getLastModified() <= this.lastModified) {
              // Nothing changed
              return;
          }
  
          long startTime = System.currentTimeMillis();
  
          if (this.source == null) {
              // Root Processor : create source
              // FIXME : make the delay configurable
              this.source = new DelayedRefreshSourceWrapper(env.resolve(this.sourceName), 1000L);
  
          } else {
              // Dispose existing tree, we will build a new one.
              disposeTree();
          }
  
          // Read the tree definition file as a Configuration
          getLogger().debug("Building " + this.language + " from " + source.getSystemId());
  
          // Build a namespace-aware configuration object
          SAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler();
          source.toSAX(handler);
          Configuration treeConfig = handler.getConfiguration();
  
          TreeBuilder treeBuilder = (TreeBuilder)this.treeBuilderClass.newInstance();
          LifecycleHelper.setupComponent(treeBuilder,
              getLogger(),
              this.context,
              this.manager,
              this.roleManager,
              this.logKit,
              this.currentLanguage);
  
          treeBuilder.setProcessor(this);
  
          // Build the tree
          ProcessingNode root;
          try {
              root = treeBuilder.build(treeConfig);
          } catch(Exception e) {
              getLogger().debug("Failed to build processing tree from " + source.getSystemId(), e);
              throw e;
          }
  
          LifecycleHelper.decommission(treeBuilder);
  
          this.lastModified = System.currentTimeMillis();
  
          if (getLogger().isDebugEnabled()) {
              double time = (this.lastModified - startTime) / 1000.0;
              getLogger().debug("TreeProcessor built in " + time + " secs from " + source.getSystemId());
              //System.out.println("TreeProcessor built in " + time + " secs from " + source.getSystemId());
          }
  
          // Finished
          this.rootNode = root;
      }
  
      public void dispose() {
          disposeTree();
          this.manager.release(this.sourceHandler);
      }
  
      /**
       * Dispose all nodes in the tree that are disposable
       */
      protected void disposeTree() {
          if (this.disposableNodes != null) {
              Iterator iter = this.disposableNodes.iterator();
              while (iter.hasNext()) {
                  ((Disposable)iter.next()).dispose();
              }
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head><title>package description</title></head>
  <body>
    Evaluation tree based implementation of the <code>Processor</code> interface.
  </body>
    
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/treeprocessor-builtins.xml
  
  Index: treeprocessor-builtins.xml
  ===================================================================
  <tree-processor>
    <!-- The sitemap language -->
    <language name="sitemap" class="org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage">
    
      <!-- Namespace for this language -->
      <namespace uri="http://apache.org/cocoon/sitemap/1.0"/>
    
      <!-- File name for files in this language, relative to the environment prefix -->
      <file name="sitemap.xmap"/>
      
      <!-- Description of the element for nodes parameters -->
      <parameter element="parameter"/>
      
      <!-- roles for the sitemap language -->
      <roles>
        <role name="org.apache.cocoon.acting.ActionSelector"
              shorthand="actions"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
        
        <role name="org.apache.cocoon.selection.SelectorSelector"
              shorthand="selectors"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
        
        <role name="org.apache.cocoon.matching.MatcherSelector"
              shorthand="matchers"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  
          <hint shorthand="regexp-uri-matcher"
                class="org.apache.cocoon.matching.RegexpURIMatcher"/>
  
          <hint shorthand="wildcard-uri-matcher"
                class="org.apache.cocoon.matching.WildcardURIMatcher"/>
  
        </role>
        
        <role name="org.apache.cocoon.generation.GeneratorSelector"
              shorthand="generators"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  
          <hint shorthand="file-generator"
                class="org.apache.cocoon.generation.FileGenerator"/>
  
          <hint shorthand="XSP-generator"
                class="org.apache.cocoon.generation.ServerPagesGenerator"/>
        </role>
        
        <role name="org.apache.cocoon.transformation.TransformerSelector"
              shorthand="transformers"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  
          <hint shorthand="XSLT-transformer"
                class="org.apache.cocoon.transformation.TraxTransformer"/>
  
          <hint shorthand="cinclude-transformer"
                class="org.apache.cocoon.transformation.CIncludeTransformer"/>
  
        </role>
        
        <role name="org.apache.cocoon.serialization.SerializerSelector"
              shorthand="serializers"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
        
        <role name="org.apache.cocoon.reading.ReaderSelector"
              shorthand="readers"
              default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
            
        <role name="org.apache.cocoon.components.notification.NotifyingBuilder"
              shorthand="notifying-builder"
              default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder"/>  
  
      </roles>
      
      <!-- node definitions for the sitemap language -->
      <nodes>
        <!-- All node names are given as local names in the above namespace (no prefix) -->
        
        <!-- Sitemap root node -->
        <node name="sitemap" builder="org.apache.cocoon.components.treeprocessor.sitemap.SitemapNodeBuilder">
          <allowed-children>components, views, action-sets, resources, pipelines</allowed-children>
        </node>
      
        <!-- Components definition : parse view info associated to components
             (actual components creation is done by SitemapLanguage) -->
        <node name="components" builder="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsNodeBuilder"/>
        
        <node name="pipelines" builder="org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNodeBuilder">
          <allowed-children>pipeline</allowed-children>
        </node>
        
        <node name="views" builder="org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder"/>
        
        <node name="view" builder="org.apache.cocoon.components.treeprocessor.sitemap.ViewNodeBuilder"/>
        
        <node name="resources" builder="org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder"/>
        
        <node name="resource" builder="org.apache.cocoon.components.treeprocessor.NamedContainerNodeBuilder"/>
        
        <node name="action-sets" builder="org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder"/>
        
        <node name="action-set" builder="org.apache.cocoon.components.treeprocessor.sitemap.ActionSetNodeBuilder"/>
  
        <node name="pipeline" builder="org.apache.cocoon.components.treeprocessor.sitemap.PipelineNodeBuilder">
          <forbidden-children>sitemap, components, pipelines</forbidden-children>
        </node>
        
        <node name="match" builder="org.apache.cocoon.components.treeprocessor.sitemap.MatchNodeBuilder">
          <forbidden-children>sitemap, components, pipeline, handle-errors</forbidden-children>
        </node>
  
        <node name="select" builder="org.apache.cocoon.components.treeprocessor.sitemap.SelectNodeBuilder"/>
  
        <node name="act" builder="org.apache.cocoon.components.treeprocessor.sitemap.ActNodeBuilder">
          <forbidden-children>sitemap, components, pipeline, handle-errors</forbidden-children>
        </node>
  
        <node name="redirect-to" builder="org.apache.cocoon.components.treeprocessor.sitemap.RedirectToNodeBuilder"/>
        
        <node name="call" builder="org.apache.cocoon.components.treeprocessor.sitemap.CallNodeBuilder"/>
  
        <node name="mount" builder="org.apache.cocoon.components.treeprocessor.sitemap.MountNodeBuilder"/>
  
        <node name="read" builder="org.apache.cocoon.components.treeprocessor.sitemap.ReadNodeBuilder"/>
  
        <node name="aggregate" builder="org.apache.cocoon.components.treeprocessor.sitemap.AggregateNodeBuilder"/>
  
        <node name="generate" builder="org.apache.cocoon.components.treeprocessor.sitemap.GenerateNodeBuilder"/>
  
        <node name="transform" builder="org.apache.cocoon.components.treeprocessor.sitemap.TransformNodeBuilder"/>
  
        <node name="serialize" builder="org.apache.cocoon.components.treeprocessor.sitemap.SerializeNodeBuilder"/>
  
        <node name="handle-errors" builder="org.apache.cocoon.components.treeprocessor.sitemap.HandleErrorsNodeBuilder"/>
  
      </nodes>
      
    </language>
  
  </tree-processor>
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActNodeBuilder.java
  
  Index: ActNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.acting.Action;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ActNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ActNodeBuilder extends AbstractParentProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private ActSetNode  actSetNode;
      private String      actSetName;
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          // Is it an action-set call ?
          this.actSetName = config.getAttribute("set", null);
          if (actSetName == null) {
  
              String source = config.getAttribute("src", null);
              String type = this.treeBuilder.getTypeForStatement(config, Action.ROLE + "Selector");
  
              ActTypeNode actTypeNode = new ActTypeNode(type, source);
              this.treeBuilder.setupNode(actTypeNode, config);
  
              actTypeNode.setChildren(buildChildNodes(config));
  
              return actTypeNode;
  
          } else {
  
              // Action set call
              if (config.getAttribute("src", null) != null) {
                  getLogger().warn("The 'src' attribute is ignored for action-set call at " + config.getLocation());
              }
              this.actSetNode = new ActSetNode();
              this.treeBuilder.setupNode(this.actSetNode, config);
  
              this.actSetNode.setChildren(buildChildNodes(config));
  
              return this.actSetNode;
          }
      }
  
      public void linkNode() throws Exception {
  
          if (this.actSetNode != null) {
              // Link action-set call to the action set
              this.actSetNode.setActionSet(
                  (ActionSetNode)CategoryNodeBuilder.getNamedNode(
                      this.treeBuilder, "action-sets", this.actSetName)
              );
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActSetNode.java
  
  Index: ActSetNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentSelector;
  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.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.SimpleParentProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   * Handles &lt;map:act type="..."&gt; (action-sets calls are handled by {@link ActSetNode}).
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ActSetNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ActSetNode extends SimpleParentProcessingNode
    implements ParameterizableProcessingNode {
  
      /** The parameters of this node */
      private Map parameters;
  
      /** The action set to call */
      private ActionSetNode actionSet;
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void setActionSet(ActionSetNode actionSet) {
          this.actionSet = actionSet;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          List       mapStack = context.getMapStack();
          Parameters resolvedParams = MapStackResolver.buildParameters(this.parameters, mapStack);
  
          Map result = this.actionSet.call(env, context, resolvedParams);
  
          if (PipelinesNode.getRedirector(env).hasRedirected()) {
              return true;
  
          } else if (result == null) {
              return false;
  
          } else if (this.children == null) {
              return true;
  
          } else {
              return this.invokeNodes(this.children, env, context, result);
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActTypeNode.java
  
  Index: ActTypeNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.SourceResolver;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.sitemap.SitemapRedirector;
  
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
  
  import java.util.*;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  
  /**
   * Handles &lt;map:act type="..."&gt; (action-sets calls are handled by {@link ActSetNode}).
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ActTypeNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ActTypeNode extends SimpleSelectorProcessingNode
    implements ParameterizableProcessingNode, Disposable, Composable {
  
      /** The parameters of this node */
      private Map parameters;
  
      /** The 'src' attribute */
      protected MapStackResolver source;
  
      /** Pre-selected action, if it's ThreadSafe */
      protected Action threadSafeAction;
  
      public ActTypeNode(String name, String source) throws PatternException {
          super(name);
          this.source = MapStackResolver.getResolver(source);
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
  
          setSelector((ComponentSelector)manager.lookup(Action.ROLE + "Selector"));
  
          // Get the action, if it's thread safe
          this.threadSafeAction = (Action)this.getThreadSafeComponent();
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Prepare data needed by the action
          Map               objectModel    = env.getObjectModel();
          SitemapRedirector redirector     = PipelinesNode.getRedirector(env);
          SourceResolver    resolver       = getSourceResolver(objectModel);
          List              mapStack       = context.getMapStack();
          String            resolvedSource = source.resolve(mapStack);
          Parameters        resolvedParams = MapStackResolver.buildParameters(this.parameters, mapStack);
  
          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.componentName);
              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, context, actionResult);
  
              } else {
                  // Return false to continue sitemap invocation
                  return false;
              }
          }
      }
  
      public void dispose() {
          if (this.threadSafeAction != null) {
              this.selector.release(this.threadSafeAction);
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActionSetNode.java
  
  Index: ActionSetNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.SourceResolver;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.sitemap.SitemapRedirector;
  
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.NamedProcessingNode;
  import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ActionSetNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ActionSetNode extends SimpleSelectorProcessingNode
    implements Disposable, NamedProcessingNode, Composable {
  
      /** The action types */
      private String[] types;
  
      /** The 'action' attribute for each action */
      private String[] actionNames;
  
      /** The actions that are ThreadSafe, to avoid lookups */
      private Action[] threadSafeActions;
      
      /** The src for each action */
      private MapStackResolver[] sources;
  
      public ActionSetNode(String name, String[] types, String[] actionNames, MapStackResolver[] sources) {
          super(name);
          this.types = types;
          this.actionNames = actionNames;
          this.sources = sources;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
  
          setSelector((ComponentSelector)manager.lookup(Action.ROLE + "Selector"));
  
          // Get all actions that are thread safe
          this.threadSafeActions = new Action[types.length];
  
          for (int i = 0; i < this.types.length; i++) {
              this.threadSafeActions[i] = (Action)this.getThreadSafeComponent(this.types[i]);
          }
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
          String msg = "An action-set cannot be invoked, at " + this.getLocation();
          getLogger().error(msg);
          throw new UnsupportedOperationException(msg);
      }
  
      /**
       * Call the actions composing the action-set and return the combined result of
       * these actions.
       */
      public final Map call(Environment env, InvokeContext context, Parameters params) throws Exception {
  
          // Prepare data needed by the actions
          Map               objectModel    = env.getObjectModel();
          SitemapRedirector redirector     = PipelinesNode.getRedirector(env);
          SourceResolver    resolver       = getSourceResolver(objectModel);
          List              mapStack       = context.getMapStack();
  
          String cocoonAction = env.getAction();
  
          Map result = null;
  
          // Call each action that either has no cocoonAction, or whose cocoonAction equals
          // the one from the environment.
  
          for (int i = 0; i < types.length; i++) {
  
              Map actionResult;
              Action action;
  
              String actionName = actionNames[i];
              String source = sources[i].resolve(mapStack);
              if (actionName == null || actionName.equals(cocoonAction)) {
  
                  // If action is ThreadSafe, avoid select() and try/catch block (faster !)
                  if ((action = this.threadSafeActions[i]) != null) {
  
                      actionResult = action.act(
                          redirector, resolver, objectModel, source, params);
  
                  } else {
  
                      action = (Action)this.selector.select(this.types[i]);
                      try {
                          actionResult = action.act(
                              redirector, resolver, objectModel, source, params);
                      } finally {
                          this.selector.release(action);
                      }
                  }
  
                  if (actionResult != null) {
                      // Merge the result in the global result, creating it if necessary.
                      if (result == null) {
                          result = new HashMap(actionResult);
                      } else {
                          result.putAll(actionResult);
                      }
                  }
              } // if (actionName...
          } // for (int i...
  
          return result;
      }
  
      public void dispose() {
          // Dispose all ThreadSafe actions
          for (int i = 0; i < this.threadSafeActions.length; i++) {
              this.selector.release(this.threadSafeActions[i]);
          }
      }
  
      /**
       * Implementation of <code>NamedProcessingNode</code>.
       */
  
      public String getName() {
          return this.componentName;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActionSetNodeBuilder.java
  
  Index: ActionSetNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.acting.Action;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ActionSetNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ActionSetNodeBuilder extends AbstractProcessingNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String actionSetName = config.getAttribute("name");
  
          // Lists of action types, names and sources for each map:act
          List actionTypes  = new ArrayList();
          List actionNames  = new ArrayList();
          List actionSources = new ArrayList();
  
          Configuration[] childrenConfig = config.getChildren();
          for (int i = 0; i < childrenConfig.length; i++) {
  
              Configuration childConfig = childrenConfig[i];
              String name = childConfig.getName();
  
              if ("act".equals(name)) {
  
                  checkNamespace(childConfig);
                  String type = this.treeBuilder.getTypeForStatement(childConfig, Action.ROLE + "Selector");
  
                  actionTypes.add(type);
                  actionNames.add(childConfig.getAttribute("action", null));
                  actionSources.add(MapStackResolver.getResolver(childConfig.getAttribute("src", null)));
  
              } else {
                  // Unknown element
                  String msg = "Unknown element " + name + " in action-set at " + childConfig.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
          }
  
          String[] types   = (String[])actionTypes.toArray(new String[actionTypes.size()]);
          String[] actions = (String[])actionNames.toArray(new String[actionNames.size()]);
          MapStackResolver[] sources =
              (MapStackResolver[])actionSources.toArray(new MapStackResolver[actionSources.size()]);
  
          ActionSetNode node = new ActionSetNode(actionSetName, types, actions, sources);
          this.treeBuilder.setupNode(node, config);
  
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/AggregateNode.java
  
  Index: AggregateNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  
  import org.apache.cocoon.sitemap.PatternException;
  import org.apache.cocoon.sitemap.ContentAggregator;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * View-handling in aggregation :
   * <ul>
   * <li>map:aggregate can have a label, but doesn't match view from-position="first" like generators
   * </li>
   * <li>each map:part can have a label
   * </li>
   * <li>if at least one of the parts has a label matching the current view, only parts matching
   *     this view are added. Otherwise, all parts are added.
   * </li>
   * </ul>
   * For more info on aggregation and views, see the mail archive
   * <a href="http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=100525751417953">here</a> or
   * <a href="http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=100517130418424">here</a>.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AggregateNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class AggregateNode extends AbstractProcessingNode {
  
      private String element;
      private String nsURI;
      private String nsPrefix;
  
      /** All parts */
      private Part[] allParts;
      
      /** Pre-filtered Part[] for views that have a matching label in any of the parts */
      private Map viewParts;
  
      /** View nodes to jump to */
      private Map viewNodes;
  
      public AggregateNode(String element, String nsURI, String nsPrefix) {
          this.element = element;
          this.nsURI = nsURI;
          this.nsPrefix = nsPrefix;
      }
  
      public void setParts(Part[] allParts, Map viewParts) {
          this.allParts = allParts;
          this.viewParts = viewParts;
      }
  
      public void setViewNodes(Map viewNodes) {
          this.viewNodes = viewNodes;
      }
  
      public boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          boolean infoEnabled = getLogger().isInfoEnabled();
  
          List mapStack = context.getMapStack();
  
          // Setup aggregator
          EventPipeline eventPipeline = context.getEventPipeline();
  
          eventPipeline.setGenerator("!content-aggregator!", null, Parameters.EMPTY_PARAMETERS);
  
          ContentAggregator aggregator = (ContentAggregator)eventPipeline.getGenerator();
          aggregator.setRootElement(this.element, this.nsURI, this.nsPrefix);
  
          // Get actual parts, potentially filtered by the view
          Part[] actualParts;
          
          String cocoonView = env.getView();
          if (cocoonView == null) {
              // Keep all parts
              actualParts = this.allParts;
  
          } else {
              // Are there some parts that match this view ?
              actualParts = (Part[])this.viewParts.get(cocoonView);
              
              // If not, keep all parts
              if (actualParts == null) {
                  actualParts = this.allParts;
              }
          }
  
          // Add parts
          for (int i = 0; i < actualParts.length; i++) {
              Part part = actualParts[i];
              if (part != null) {
                  // FIXME : update ContentAggregator to accept boolean for stripRoot
                  aggregator.addPart(part.source.resolve(mapStack),
                      part.element, part.nsURI, String.valueOf(part.stripRoot), part.nsPrefix
                  );
              }
          }
  
          // Check aggregate-level view
          if (cocoonView != null && this.viewNodes != null) {
              ProcessingNode viewNode = (ProcessingNode)this.viewNodes.get(cocoonView);
              if (viewNode != null) {
                  if (infoEnabled) {
                      getLogger().info("Jumping to view '" + cocoonView + "' from aggregate at " + this.getLocation());
                  }
                  return viewNode.invoke(env, context);
              }
          }
  
          // Return false to continue sitemap invocation
          return false;
      }
  
      public static class Part {
          public Part(String source, String element, String nsURI, String nsPrefix, boolean stripRoot)
            throws PatternException {
              this.source = MapStackResolver.getResolver(source);
              this.element = element;
              this.nsURI = nsURI;
              this.nsPrefix = nsPrefix;
              this.stripRoot = stripRoot;
          }
  
          private MapStackResolver source;
          private String element;
          private String nsURI;
          private String nsPrefix;
          private boolean stripRoot;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/AggregateNodeBuilder.java
  
  Index: AggregateNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: AggregateNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class AggregateNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      /** The views for the aggregate element */
      private Collection views;
  
      /** The built node */
      private AggregateNode node;
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          // Get root node data
          this.node = new AggregateNode(
              config.getAttribute("element"),
              config.getAttribute("ns", ""),
              config.getAttribute("prefix", "")
          );
          this.treeBuilder.setupNode(this.node, config);
  
          this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement("", "", config);
          
          // The sitemap builder
          SitemapLanguage sitemap = (SitemapLanguage)this.treeBuilder;
  
          // All parts of the aggregate
          List allParts = new ArrayList();
     
          // For each view that a part matches, the list of all parts that match it
          Map viewParts = new HashMap();
          
          Configuration[] childConfigs = config.getChildren();
          for (int i = 0; i < childConfigs.length; i++) {
              Configuration childConfig = childConfigs[i];
  
              if (!"part".equals(childConfig.getName())) {
                  String msg = "Unknown element '" + childConfig.getName() + " in aggregate ' at " +
                      childConfig.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
  
              checkNamespace(childConfig);
  
              AggregateNode.Part currentPart = new AggregateNode.Part(
                  childConfig.getAttribute("src"),
                  childConfig.getAttribute("element", ""),
                  childConfig.getAttribute("ns", ""),
                  childConfig.getAttribute("prefix", ""),
                  childConfig.getAttributeAsBoolean("strip-root", false)
              );
              
              allParts.add(currentPart);
              
              // Get the views for this part
              Collection viewsForPart = sitemap.getViewsForStatement("", "", childConfig);
              
              // Associate this part to all the views it belongs to
              if (viewsForPart != null) {
                  Iterator iter = viewsForPart.iterator();
                  while(iter.hasNext()) {
                      String currentView = (String)iter.next();
                      
                      // Get collection of parts for current view
                      Collection currentViewParts = (Collection)viewParts.get(currentView);
                      if (currentViewParts == null) {
                          // None for now : create the collection
                          currentViewParts = new ArrayList();
                          viewParts.put(currentView, currentViewParts);
                      }
                      
                      // Add the current part to the parts list of the view
                      currentViewParts.add(currentPart);
                  }
              }
          }
  
          if (allParts.size() == 0) {
              String msg = "There must be at least one part in map:aggregate at " + config.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          // Now convert all Collections to Array for faster traversal
          AggregateNode.Part[] allPartsArray = (AggregateNode.Part[])allParts.toArray(
              new AggregateNode.Part[allParts.size()]);
              
          Iterator iter = viewParts.entrySet().iterator();
          while(iter.hasNext()) {
              Map.Entry entry = (Map.Entry)iter.next();
              
              // Get collection of parts for this entry
              Collection coll = (Collection)entry.getValue();
  
              // Convert to array and replace the entry value
              entry.setValue(
                  coll.toArray(new AggregateNode.Part[coll.size()])
              );
          }
  
          node.setParts(allPartsArray, viewParts);
  
          return node;
  
      }
  
      public void linkNode() throws Exception {
  
          // Give the AggregateNode a Node for each view
          SitemapLanguage sitemap = (SitemapLanguage)this.treeBuilder;
          
          this.node.setViewNodes(sitemap.getViewNodes(this.views));
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNode.java
  
  Index: CallNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Initializable;
  
  import org.apache.cocoon.environment.Environment;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: CallNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class CallNode extends AbstractProcessingNode
      implements Initializable, ParameterizableProcessingNode {
  
      /** The parameters of this node */
      private Map parameters;
  
      /** The 'resource' attribute */
      private String resourceName;
  
      private MapStackResolver resourceResolver;
  
      /** The category node */
      private CategoryNode resources;
  
      private ProcessingNode resourceNode;
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void setResource(CategoryNode resources, String resourceName) throws Exception {
          this.resourceName = resourceName;
          this.resources = resources;
      }
  
      public void initialize() throws Exception {
          if (MapStackResolver.needsResolve(this.resourceName)) {
              // Will always be resolved at invoke time
              this.resourceResolver = MapStackResolver.getResolver(this.resourceName);
          } else {
              // Static name : get it now
              this.resourceNode = this.resources.getNodeByName(MapStackResolver.unescape(this.resourceName));
          }
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Resolve parameters
          if (this.parameters != null) {
              // In redirect-to a level is added to the map stack *only* if the
              // 'target' attribute is present.
              Map params = MapStackResolver.resolveMap(this.parameters, context.getMapStack());
              context.pushMap(params);
          }
  
          boolean result;
  
          if (this.resourceNode != null) {
              // Static resource name
                  result = this.resourceNode.invoke(env, context);
  
          } else {
              // Resolved resource name
              String name = this.resourceResolver.resolve(context.getMapStack());
  
              if (getLogger().isInfoEnabled()) {
                  getLogger().info("Calling resource " + name);
              }
  
              result = this.resources.invokeByName(name, env, context);
          }
  
          if (this.parameters != null) {
              context.popMap();
          }
          return result;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNodeBuilder.java
  
  Index: CallNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.CategoryNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: CallNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class CallNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private CallNode node;
      private String resourceName;
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          this.resourceName = config.getAttribute("resource");
          this.node = new CallNode();
          this.treeBuilder.setupNode(this.node, config);
  
          return this.node;
      }
  
      public void linkNode() throws Exception {
          CategoryNode resources = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "resources");
  
          if (resources == null) {
              String msg = "This sitemap contains no resources. Cannot call at " + this.node.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          this.node.setResource(
              resources,
              this.resourceName
          );
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java
  
  Index: ComponentsNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   * Handles &lt;map:components&gt;. It doesn't actually create a <code>ProcessingNode</code>.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ComponentsNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ComponentsNodeBuilder extends AbstractProcessingNodeBuilder {
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          // Nothing more here. To be removed ;)
          return null;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
  
  Index: ComponentsSelector.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  
  import org.apache.cocoon.components.pipeline.OutputComponentSelector;
  import org.apache.cocoon.components.ExtendedComponentSelector;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.generation.Generator;
  import org.apache.cocoon.matching.Matcher;
  import org.apache.cocoon.reading.Reader;
  import org.apache.cocoon.selection.Selector;
  import org.apache.cocoon.serialization.Serializer;
  import org.apache.cocoon.sitemap.SitemapComponentSelector;
  import org.apache.cocoon.transformation.Transformer;
  
  import java.util.*;
  
  /**
   * Component selector for sitemap components.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ComponentsSelector.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ComponentsSelector extends ExtendedComponentSelector implements OutputComponentSelector, SitemapComponentSelector {
  
      public static final int UNKNOWN     = -1;
      public static final int GENERATOR   = 0;
      public static final int TRANSFORMER = 1;
      public static final int SERIALIZER  = 2;
      public static final int READER      = 3;
      public static final int MATCHER     = 4;
      public static final int SELECTOR    = 5;
      public static final int ACTION      = 6;
  
      public static final String[] SELECTOR_ROLES = {
          Generator.ROLE   + "Selector",
          Transformer.ROLE + "Selector",
          Serializer.ROLE  + "Selector",
          Reader.ROLE      + "Selector",
          Matcher.ROLE     + "Selector",
          Selector.ROLE    + "Selector",
          Action.ROLE      + "Selector"
      };
  
      public static final String[] COMPONENT_NAMES = {
          "generator",
          "transformer",
          "serializer",
          "reader",
          "matcher",
          "selector",
          "action"
      };
  
      /** The role as an integer */
      private int roleId;
  
      /** The mime-type for hints */
      private Map hintMimeTypes;
  
      /** The labels for hints */
      private Map hintLabels;
  
      /** The set of known hints, used to add standard components (see ensureExists) */
      private Set knownHints = new HashSet();
  
      /** The parent selector, if it's of the current class */
      private SitemapComponentSelector parentSitemapSelector;
  
      public void setParentSelector(ComponentSelector selector) {
          super.setParentSelector(selector);
  
          if (selector instanceof SitemapComponentSelector) {
              this.parentSitemapSelector = (SitemapComponentSelector)selector;
          }
      }
  
      /**
       * Return the component instance name according to the selector role
       * (e.g. "action" for "org.apache.cocoon.acting.Action").
       */
      protected String getComponentInstanceName() {
          return (this.roleId == UNKNOWN) ? null : COMPONENT_NAMES[this.roleId];
      }
  
      /**
       * Get the attribute for class names. This is "src" for known roles, and
       * "class" (the default) for other roles.
       */
      protected String getClassAttributeName() {
          return (this.roleId == UNKNOWN) ? "class" : "src";
      }
  
  
      public void configure(Configuration config) throws ConfigurationException {
  
          // How are we ?
          String role = getRoleName(config);
          this.roleId = UNKNOWN; // unknown
          for (int i = 0; i < SELECTOR_ROLES.length; i++) {
              if (SELECTOR_ROLES[i].equals(role)) {
                  this.roleId = i;
                  break;
              }
          }
  
          if (getLogger().isDebugEnabled()) {
              getLogger().debug("Setting up sitemap component selector for " +
                  role + " (role id = " + this.roleId + ")");
          }
  
          // Only matchers and serializers can have a MIME type
          if (this.roleId == SERIALIZER || this.roleId == READER) {
              this.hintMimeTypes = new HashMap();
          }
          
          this.hintLabels = new HashMap();
  
          super.configure(config);
      }
  
      /**
       * Add a component in this selector. If needed, also register it's MIME type.
       */
      public void addComponent(Object hint, Class clazz, Configuration config) throws ComponentException {
  
          super.addComponent(hint, clazz, config);
  
          // Add to known hints
          this.knownHints.add(hint);
  
          if (this.roleId == SERIALIZER || this.roleId == READER) {
              // Get mime-type
              String mimeType = config.getAttribute("mime-type", null);
              if (mimeType != null) {
                  this.hintMimeTypes.put(hint, mimeType);
              }
          }
          
          String label = config.getAttribute("label", null);
          if (label != null) {
              // Empty '' attribute will result in empty array,
              // overriding all labels on the component declared in the parent.
              StringTokenizer st = new StringTokenizer(label, " ,", false);
              String[] labels = new String[st.countTokens()];
              for (int i = 0; i < labels.length; i++) {
                  labels[i] = st.nextToken();
              }
              this.hintLabels.put(hint, labels);
          }
      }
  
      /**
       * Ensure system-defined components exist (e.g. !content-aggregator!) and initialize
       * the selector.
       */
      public void initialize() /*throws Exception*/ {
  
      // FIXME : need to catch exceptions since ECS doesn't propagate the throws clause of Initializable
      try {
  
          Configuration emptyConfig = new DefaultConfiguration("", "");
  
          // Ensure all system-defined hints exist.
          // NOTE : checking this here means they can be user-defined in the sitemap
          switch(this.roleId) {
              case GENERATOR :
                  ensureExists("!notifying-generator!",
                      org.apache.cocoon.sitemap.NotifyingGenerator.class, emptyConfig);
  
                  ensureExists("!content-aggregator!",
                      org.apache.cocoon.sitemap.ContentAggregator.class, emptyConfig);
              break;
  
              case TRANSFORMER :
                  ensureExists("!link-translator!",
                      org.apache.cocoon.sitemap.LinkTranslator.class, emptyConfig);
              break;
          }
  
          super.initialize();
  
          // Don't keep known hints (they're no more needed)
          this.knownHints = null;
  
      } catch(Exception e) {
          throw new CascadingRuntimeException("Cannot setup default components", e);
      }
  
      }
  
      /**
       * Ensure a component exists or add it otherwhise. We cannot simply call hasComponent()
       * since it requires to be initialized, and we want to add components, and this must
       * be done before initialization.
       */
      private void ensureExists(Object hint, Class clazz, Configuration config) throws ComponentException {
  
          if (! this.knownHints.contains(hint)) {
              this.addComponent(hint, clazz, config);
          }
      }
  
      /**
       * Get the MIME type for a given hint.
       */
      public String getMimeTypeForHint(Object hint) {
  
          if (this.hintMimeTypes == null) {
              return null;
  
          } else {
              String mimeType = (String)this.hintMimeTypes.get(hint);
  
              if (mimeType != null) {
                  return mimeType;
  
              } else if (this.parentSitemapSelector != null) {
                  return this.parentSitemapSelector.getMimeTypeForHint(hint);
  
              } else {
                  return null;
              }
          }
      }
  
      public boolean hasLabel(Object hint, String label) {
          String[] labels = (String[])this.hintLabels.get(hint);
          if (labels != null) {
              for (int i = 0; i < labels.length; i++) {
                  if (labels[i].equals(label))
                      return true;
              }
          } else if (parentSitemapSelector != null) {
              return parentSitemapSelector.hasLabel(hint, label);
          }
          return false;
      }
  
      public String[] getLabels(Object hint) {
          String[] labels = (String[])this.hintLabels.get(hint);
          // Labels can be inherited or completely overrided
          if (labels == null && parentSitemapSelector != null) {
              return parentSitemapSelector.getLabels(hint);
          }
          return labels;
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/GenerateNode.java
  
  Index: GenerateNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: GenerateNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class GenerateNode extends AbstractProcessingNode implements ParameterizableProcessingNode {
  
      private String generatorName;
  
      private MapStackResolver source;
  
      private Map parameters;
  
      private Map views;
  
      /** The category node */
      private CategoryNode viewsNode;
  
      public GenerateNode(String name, String source) throws PatternException {
          this.generatorName = name;
          this.source = MapStackResolver.getResolver(source);
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void setViews(Map views) {
          this.views = views;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          List mapStack = context.getMapStack();
  
          context.getEventPipeline().setGenerator(
              this.generatorName,
              source.resolve(mapStack),
              MapStackResolver.buildParameters(this.parameters, mapStack)
          );
  
          // Check view
          if (this.views != null) {
  
              String cocoonView = env.getView();
              if (cocoonView != null) {
  
                  // Get view node
                  ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
  
                  if (viewNode != null) {
                      if (getLogger().isInfoEnabled()) {
                          getLogger().info("Jumping to view " + cocoonView + " from generator at " + this.getLocation());
                      }
                      return viewNode.invoke(env, context);
                  }
              }
          }
  
          // Return false to contine sitemap invocation
          return false;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/GenerateNodeBuilder.java
  
  Index: GenerateNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.cocoon.generation.Generator;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: GenerateNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class GenerateNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private GenerateNode node;
  
      private Collection views;
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String type = this.treeBuilder.getTypeForStatement(config, Generator.ROLE + "Selector");
  
          this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Generator.ROLE, type, config);
  
          this.node = new GenerateNode(type, config.getAttribute("src", null));
          return this.treeBuilder.setupNode(this.node, config);
      }
  
      public void linkNode() throws Exception {
          this.node.setViews(
              ((SitemapLanguage)this.treeBuilder).getViewNodes(this.views)
          );
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/HandleErrorsNode.java
  
  Index: HandleErrorsNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.ResourceNotFoundException;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   * Handles &lt;map:handle-errors&gt;
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: HandleErrorsNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public final class HandleErrorsNode extends AbstractParentProcessingNode {
  
      private ProcessingNode[] children;
      private int statusCode;
  
      public HandleErrorsNode(int statusCode) {
          this.statusCode = statusCode;
      }
  
      public int getStatusCode() {
          return this.statusCode;
      }
  
      public void setChildren(ProcessingNode[] nodes)
      {
          this.children = nodes;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          if (getLogger().isInfoEnabled()) {
              getLogger().info("Processing handle-errors at " + getLocation());
          }
  
          context.getEventPipeline().setGenerator("!notifying-generator!", "", Parameters.EMPTY_PARAMETERS);
  
          return invokeNodes(this.children, env, context);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/HandleErrorsNodeBuilder.java
  
  Index: HandleErrorsNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   * Builds a &lt;map:handle-errors&gt;
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: HandleErrorsNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class HandleErrorsNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          HandleErrorsNode node = new HandleErrorsNode(config.getAttributeAsInteger("type", 500));
          this.treeBuilder.setupNode(node, config);
  
          // Get all children
          node.setChildren(buildChildNodes(config));
  
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNode.java
  
  Index: MatchNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.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.components.treeprocessor.SimpleSelectorProcessingNode;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  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 org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import java.util.Map;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: MatchNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class MatchNode extends SimpleSelectorProcessingNode implements ParameterizableProcessingNode, Composable {
  
      /** The 'pattern' attribute */
      private MapStackResolver pattern;
  
      /** The matcher, if it's ThreadSafe */
      private Matcher threadSafeMatcher;
  
      private Map parameters;
  
      public MatchNode(String name, String pattern) throws PatternException {
          super(name);
          this.pattern = MapStackResolver.getResolver(pattern);
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
  
          super.setSelector((ComponentSelector)manager.lookup(Matcher.ROLE + "Selector"));
  
          // Get matcher if it's ThreadSafe
          this.threadSafeMatcher = (Matcher)this.getThreadSafeComponent();
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          List mapStack = context.getMapStack();
  
          String resolvedPattern = pattern.resolve(mapStack);
          Map objectModel = env.getObjectModel();
          Parameters resolvedParams = MapStackResolver.buildParameters(this.parameters, mapStack);
  
          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().isInfoEnabled()) {
                  getLogger().info("Matcher '" + this.componentName + "' matched pattern '" + this.pattern +
                      "' at " + this.getLocation());
              }
  
              // Invoke children with the matcher results
              return this.invokeNodes(children, env, context, result);
  
          } else {
              // Matcher failed
              return false;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNodeBuilder.java
  
  Index: MatchNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.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.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: MatchNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class MatchNodeBuilder extends AbstractParentProcessingNodeBuilder
    implements Composable {
  
      private static final String SELECTOR_ROLE = Matcher.ROLE + "Selector";
  
      private ComponentManager manager;
  
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String pattern = config.getAttribute("pattern", null);
  
          String type = this.treeBuilder.getTypeForStatement(config, SELECTOR_ROLE);
  
          // Get the type and class for this matcher
          ComponentsSelector selector = (ComponentsSelector)this.manager.lookup(SELECTOR_ROLE);
  
          // Find matcher class
          Matcher matcher = (Matcher)selector.select(type);
          Class clazz = matcher.getClass();
          selector.release(matcher);
  
          // PreparableMatcher are only prepared if pattern doesn't need request-time resolution.
          boolean preparable =
              PreparableMatcher.class.isAssignableFrom(clazz) &&
              !MapStackResolver.needsResolve(pattern);
  
          // Instanciate appropriate node
          SimpleSelectorProcessingNode node;
  
          if (preparable) {
              node = new PreparableMatchNode(type, pattern);
          } else {
              node = new MatchNode(type, pattern);
          }
  
          this.treeBuilder.setupNode(node, config);
  
          // Get all children
          ProcessingNode[] children = buildChildNodes(config);
  
          node.setChildren(children);
  
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java
  
  Index: MountNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.ComponentManager;
  
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.TreeProcessor;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentException;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: MountNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class MountNode extends AbstractProcessingNode implements Composable {
  
      /** The 'uri-prefix' attribute */
      private MapStackResolver prefix;
  
      /** The 'src' attribute */
      private MapStackResolver source;
  
      /** Processors for sources */
      private Map processors = new HashMap();
  
      /** The processor for this node */
      private TreeProcessor parentProcessor;
  
      /** The language for the mounted processor */
      private String language;
  
      /** The component manager to be used by the mounted processor */
      private ComponentManager manager;
  
      public MountNode(String prefix, String source, String language, TreeProcessor parentProcessor)
        throws PatternException {
          this.prefix = MapStackResolver.getResolver(prefix);
          this.source = MapStackResolver.getResolver(source);
          this.language = language;
          this.parentProcessor = parentProcessor;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
          this.manager = manager;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          List mapStack = context.getMapStack();
  
          String resolvedSource = this.source.resolve(mapStack);
          TreeProcessor processor = (TreeProcessor)processors.get(resolvedSource);
          if (processor == null) {
              processor = getProcessor(env, resolvedSource);
          }
  
          String resolvedPrefix = this.prefix.resolve(mapStack);
  
          String oldPrefix = env.getURIPrefix();
          String oldURI    = env.getURI();
          try {
              env.changeContext(resolvedPrefix, resolvedSource);
  
              if (context.isInternalRequest()) {
                  // Propagate pipelines
                  return processor.process(env, context.getStreamPipeline(), context.getEventPipeline());
              } else {
                  // Processor will create its own pipelines
                  return processor.process(env);
              }
  
          } finally {
              // Restore context
              env.setContext(oldPrefix, oldURI);
  
              // Recompose pipelines which may have been recomposed by subsitemap
              context.recompose(this.manager);
          }
      }
  
      private synchronized TreeProcessor getProcessor(Environment env, String source) throws Exception {
          
          TreeProcessor processor = (TreeProcessor)processors.get(source);
  
          if (processor == null) {
              
              if (source.charAt(source.length() - 1) == '/') {
                  source = source + "sitemap.xmap";
              }
  
              processor = this.parentProcessor.createChildProcessor(
                  this.manager, this.language, env.resolve(source));
  
              processors.put(source, processor);
          }
  
          return processor;
      }
  
      public void dispose() {
          Iterator iter = this.processors.values().iterator();
          while(iter.hasNext()) {
              ((TreeProcessor)iter.next()).dispose();
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNodeBuilder.java
  
  Index: MountNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: MountNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class MountNodeBuilder extends AbstractProcessingNodeBuilder implements ThreadSafe {
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          MountNode node = new MountNode(
              config.getAttribute("uri-prefix"),
              config.getAttribute("src"),
              config.getAttribute("language", null),
              this.treeBuilder.getProcessor()
          );
          return (this.treeBuilder.setupNode(node, config));
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java
  
  Index: PipelineNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.ConnectionResetException;
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.ResourceNotFoundException;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.components.notification.Notifying;
  import org.apache.cocoon.components.notification.NotifyingBuilder;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  
  /**
   *
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: PipelineNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class PipelineNode extends AbstractParentProcessingNode implements Composable {
  
      // TODO : handle a 'fail-hard' environment attribute
      // can be useful to stop off-line generation when there's an error
  
      private ProcessingNode[] children;
  
      private ProcessingNode error404;
  
      private ProcessingNode error500;
  
      private ComponentManager manager;
  
      private boolean internalOnly = false;
  
      /** Is it the last <pipeline> in the enclosing <pipelines> ? */
      private boolean isLast = false;
  
      /**
       * The component manager is used to create error pipelines
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      public void setChildren(ProcessingNode[] nodes)
      {
          this.children = nodes;
      }
  
      public void setLast(boolean isLast) {
          this.isLast = isLast;
      }
  
      public void set404Handler(ProcessingNode node)
      {
          this.error404 = node;
      }
  
      public void set500Handler(ProcessingNode node)
      {
          this.error500 = node;
      }
  
      public void setInternalOnly(boolean internalOnly) {
          this.internalOnly = internalOnly;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Always fail on external resquests if internal only.
          if (this.internalOnly && !context.isInternalRequest()) {
              return false;
          }
  
          try {
  
              if (invokeNodes(children, env, context)) {
                  return true;
              } else if (this.isLast) {
                  String msg = "No pipeline matched request: " + env.getURIPrefix() + '/' + env.getURI();
                  getLogger().info(msg);
                  throw new ResourceNotFoundException(msg);
              } else {
                  return false;
              }
  
          } catch (ConnectionResetException cre) {
              // Will be reported by CocoonServlet, rethrowing
              throw cre;
  
          } catch(ResourceNotFoundException rnfe) {
              getLogger().warn("Resource not found in pipeline at " + getLocation(), rnfe);
  
              if (error404 != null) {
                  // There's a handler
                  return invokeErrorHandler(error404, rnfe, env);
  
              } else {
                  // No handler : propagate
                  throw rnfe;
              }
  
          } catch(Exception e) {
  
              // Rethrow exception for internal requests
              if (error500 != null && !context.isInternalRequest()) {
  
                  getLogger().warn("Error while processing pipeline at " + getLocation(), e);
  
                  return invokeErrorHandler(error500, e, env);
  
              } else {
                  // No handler : propagate
  
                  getLogger().error("Error while processing pipeline at " + getLocation(), e);
                  throw e;
              }
          }
      }
  
      private boolean invokeErrorHandler(ProcessingNode node, Exception ex, Environment env)
        throws Exception {
  
          InvokeContext errorContext = null;
  
          try {
              // Try to reset the response to avoid mixing already produced output
              // and error page.
              env.tryResetResponse();
  
              // Build a new context
              errorContext = new InvokeContext();
              errorContext.setLogger(getLogger());
              errorContext.compose(this.manager);
  
              // Create a Notifying
              NotifyingBuilder notifyingBuilder= (NotifyingBuilder)this.manager.lookup(NotifyingBuilder.ROLE);
              Notifying currentNotifying = notifyingBuilder.build(this, ex);
              this.manager.release(notifyingBuilder);
  
              // Add it to the object model
              env.getObjectModel().put(Constants.NOTIFYING_OBJECT, currentNotifying );
  
              // notifying-generator is added in HandleErrorsNode
              return node.invoke(env, errorContext);
  
          } catch (Exception subEx) {
              getLogger().error("error notifier barfs", subEx);
              return false;
  
          } finally {
              if (errorContext != null) {
                  errorContext.dispose();
              }
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java
  
  Index: PipelineNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
  
  import java.util.*;
  
  /**
   * Builds a &lt;map:pipeline&gt;
  
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: PipelineNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class PipelineNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return true;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          PipelineNode node = new PipelineNode();
          this.treeBuilder.setupNode(node, config);
  
          node.setInternalOnly(config.getAttributeAsBoolean("internal-only", false));
  
          ProcessingNode error404Handler = null;
          ProcessingNode error500Handler = null;
  
          Configuration[] childConfigs = config.getChildren();
          List children = new ArrayList();
  
          childLoop : for (int i = 0; i < childConfigs.length; i++) {
              Configuration childConfig = childConfigs[i];
              if (!isChild(childConfig)) {
                  continue childLoop;
              }
  
              ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig);
  
              if (builder instanceof HandleErrorsNodeBuilder) {
                  // Error handler : check type
                  HandleErrorsNode handler = (HandleErrorsNode)builder.buildNode(childConfig);
                  int type = handler.getStatusCode();
  
                  if ( (type == 404 && error404Handler != null) ||
                       (type == 500 && error500Handler != null) ) {
                      String msg = "Duplicate handle-errors at " + handler.getLocation();
                      getLogger().error(msg);
                      throw new ConfigurationException(msg);
                  }
  
                  if (type == 404) {
                      error404Handler = handler;
                  } else if (type == 500) {
                      error500Handler = handler;
                  } else {
                      String msg = "Unkown handle-errors type (" + type + ") at " + handler.getLocation();
                      getLogger().error(msg);
                      throw new ConfigurationException(msg);
                  }
  
              } else {
                  // Regular builder
                  children.add(builder.buildNode(childConfig));
              }
          }
  
          node.setChildren(toNodeArray(children));
          node.set404Handler(error404Handler);
          node.set500Handler(error500Handler);
  
          return node;
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java
  
  Index: PipelinesNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.activity.Disposable;
  
  import org.apache.cocoon.ResourceNotFoundException;
  
  import org.apache.cocoon.sitemap.SitemapRedirector;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.components.treeprocessor.EnvironmentSourceResolver;
  import org.apache.cocoon.components.treeprocessor.SimpleParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  import org.apache.avalon.framework.component.ComponentException;
  
  /**
   * Handles &lt;map:pipelines&gt;
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: PipelinesNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public final class PipelinesNode extends SimpleParentProcessingNode
    implements Composable, Disposable {
  
      private static final String REDIRECTOR_ATTR = "sitemap:redirector";
  
      private ComponentManager manager;
  
      /**
       * Keep the component manager used everywhere in the tree so that we can
       * cleanly dispose it.
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      public void setChildren(ProcessingNode[] nodes)
      {
          // Mark the last pipeline so that it can throw a ResourceNotFoundException
          ((PipelineNode)nodes[nodes.length - 1]).setLast(true);
  
          super.setChildren(nodes);
      }
  
      public static SitemapRedirector getRedirector(Environment env) {
          return (SitemapRedirector)env.getAttribute(REDIRECTOR_ATTR);
      }
  
      /**
       * Process the environment. Also adds an <code>EnvironmentSourceResolver</code>
       * and a <code>Redirector</code> in the object model. The previous resolver and
       * redirector, if any, are restored before return.
       */
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Recompose context (and pipelines) to the local component manager
          context.recompose(this.manager);
  
          // Create the source resolver relative to the environment.
  
          // Design note : creating the SourceResolver could also have been done
          // in TreeProcessor.invoke(), but doing it here ensures we use the local
          // component manager used by all other nodes.
          EnvironmentSourceResolver resolver = new EnvironmentSourceResolver(this.manager, env);
          SitemapRedirector redirector = new SitemapRedirector(env);
  
          Map objectModel = env.getObjectModel();
  
          Object oldResolver = objectModel.get(OBJECT_SOURCE_RESOLVER);
          Object oldRedirector = env.getAttribute(REDIRECTOR_ATTR);
  
          objectModel.put(OBJECT_SOURCE_RESOLVER, resolver);
          env.setAttribute(REDIRECTOR_ATTR, redirector);
  
          try {
              // FIXME : is there any useful information that can be passed as top-level parameters,
              //         such as the URI of the mount point ?
  
              return invokeNodes(this.children, env, context);
  
          } finally {
  
              // Restore old redirector and resolver
              env.setAttribute(REDIRECTOR_ATTR, oldRedirector);
              objectModel.put(OBJECT_SOURCE_RESOLVER, oldResolver);
  
              // Dispose the resolver
              resolver.dispose();
          }
      }
  
      /**
       * Dispose the component manager.
       */
      public void dispose() {
          if (this.manager instanceof Disposable) {
              ((Disposable)this.manager).dispose();
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java
  
  Index: PipelinesNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.ContainerNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   * Builds a &lt;map:pipelines&gt;
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: PipelinesNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class PipelinesNodeBuilder extends ContainerNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
          PipelinesNode node = new PipelinesNode();
          this.treeBuilder.setupNode(node, config);
  
          ProcessingNode[] children = buildChildNodes(config);
          if (children.length == 0) {
              String msg = "There must be at least one pipeline at " + config.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          node.setChildren(children);
  
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java
  
  Index: PreparableMatchNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.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.components.treeprocessor.SimpleSelectorProcessingNode;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.matching.Matcher;
  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.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: PreparableMatchNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class PreparableMatchNode extends SimpleSelectorProcessingNode implements ParameterizableProcessingNode, Composable {
  
      /** The 'pattern' attribute */
      private String pattern;
  
      private Object preparedPattern;
  
      private Map parameters;
  
      /** The matcher, if it's ThreadSafe */
      private PreparableMatcher threadSafeMatcher;
  
      public PreparableMatchNode(String name, String pattern) throws PatternException {
          super(name);
          this.pattern = pattern;
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
  
      public void compose(ComponentManager manager) throws ComponentException {
  
          setSelector((ComponentSelector)manager.lookup(Matcher.ROLE + "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(MapStackResolver.unescape(this.pattern));
  
          } catch(PatternException pe) {
              String msg = "Invalid pattern '" + this.pattern + "' for matcher at " + this.getLocation();
              getLogger().error(msg, pe);
              throw new ComponentException(msg, pe);
  
          } finally {
              if (this.threadSafeMatcher == null) {
                  selector.release(matcher);
              }
          }
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          Map objectModel = env.getObjectModel();
          Parameters resolvedParams = MapStackResolver.buildParameters(this.parameters, context.getMapStack());
  
          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().isInfoEnabled()) {
                  getLogger().info("Matcher '" + this.componentName + "' matched prepared pattern '" +
                      this.pattern + "' at " + this.getLocation());
              }
  
              // Invoke children with the matcher results
              return this.invokeNodes(children, env, context, result);
  
          } else {
              // Matcher failed
              return false;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java
  
  Index: ReadNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ReadNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ReadNode extends AbstractProcessingNode implements ParameterizableProcessingNode {
  
      private String readerName;
  
      private MapStackResolver source;
  
      private String mimeType;
  
      private int statusCode;
  
      private Map parameters;
  
      /**
       * 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 = MapStackResolver.getResolver(source);
          this.mimeType = mimeType;
          this.statusCode = statusCode;
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public final boolean invoke(Environment env,  InvokeContext context)
        throws Exception {
  
          List mapStack = context.getMapStack();
  
          StreamPipeline pipeline = context.getStreamPipeline();
  
          if (this.mimeType == null) {
              // No mime-type set on node
              pipeline.setReader(
                  this.readerName,
                  source.resolve(mapStack),
                  MapStackResolver.buildParameters(this.parameters, mapStack)
              );
  
          } else {
              // mime-type set on node
              pipeline.setReader(
                  this.readerName,
                  source.resolve(mapStack),
                  MapStackResolver.buildParameters(this.parameters, mapStack),
                  this.mimeType
              );
          }
  
          // Set status code if there is one
          if (this.statusCode >= 0) {
              env.setStatus(this.statusCode);
          }
  
          if (! context.isInternalRequest()) {
              // Process pipeline
              return pipeline.process(env);
  
          } else {
              // Return true : pipeline is finished.
              return true;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java
  
  Index: ReadNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.reading.Reader;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ReadNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ReadNodeBuilder extends AbstractProcessingNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String type = this.treeBuilder.getTypeForStatement(config, Reader.ROLE + "Selector");
  
          ReadNode node = new ReadNode(
              type,
              config.getAttribute("src", null),
              config.getAttribute("mime-type", null),
              config.getAttributeAsInteger("status-code", -1)
          );
  
          return this.treeBuilder.setupNode(node, config);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java
  
  Index: RedirectToNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.CategoryNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: RedirectToNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class RedirectToNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private CallNode callNode;
      private String resourceName;
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
          
          // Is it a redirect to resource ?
          this.resourceName = config.getAttribute("resource", null);
          if (this.resourceName != null) {
              
              getLogger().warn("Redirect to resource is deprecated. Use map:call instead at " +
                  config.getLocation());
  
              this.callNode = new CallNode();
              this.treeBuilder.setupNode(this.callNode, config);
  
              String target = config.getAttribute("target", null);
              if (target != null) {
                  Map params = new HashMap(1);
                  params.put("target", MapStackResolver.getResolver(target));
                  this.callNode.setParameters(params);
              }
              return this.callNode;
              
          } else {
              ProcessingNode URINode = new RedirectToURINode(
                  config.getAttribute("uri"),
                  config.getAttributeAsBoolean("session", false)
              );
              return this.treeBuilder.setupNode(URINode, config);
  
          }
      }
  
      public void linkNode() throws Exception {
  
          if (this.callNode != null) {
              CategoryNode resources = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "resources");
  
              if (resources == null) {
                  String msg = "This sitemap contains no resources. Cannot redirect at " +
                      this.callNode.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
  
              this.callNode.setResource(
                  resources,
                  this.resourceName
              );
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java
  
  Index: RedirectToURINode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Redirector;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: RedirectToURINode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class RedirectToURINode extends AbstractProcessingNode {
  
      /** The 'uri' attribute */
      private MapStackResolver uri;
  
      private boolean keepSession;
  
      public RedirectToURINode(String uri, boolean keepSession) throws PatternException {
          this.uri = MapStackResolver.getResolver(uri);
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
          String resolvedURI = uri.resolve(context.getMapStack());
  
          if (getLogger().isInfoEnabled()) {
              getLogger().info("Redirecting to '" + resolvedURI + "' at " + this.getLocation());
          }
  
          env.redirect (this.keepSession, resolvedURI);
  
          return true;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java
  
  Index: SelectNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  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.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.Environment;
  
  import org.apache.cocoon.selection.Selector;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SelectNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SelectNode extends SimpleSelectorProcessingNode
    implements ParameterizableProcessingNode, Composable, Disposable {
  
      /** The parameters of this node */
      private Map parameters;
  
      /** Selector where to get Actions from */
      protected ComponentSelector componentSelector;
  
      /** Pre-selected selector, if it's ThreadSafe */
      protected Selector threadSafeSelector;
  
      private ProcessingNode[][] whenNodes;
  
      private MapStackResolver[] whenTests;
  
      private ProcessingNode[] otherwhiseNodes;
  
      public SelectNode(String name) throws PatternException {
          super(name);
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void setCases(ProcessingNode[][] whenNodes, MapStackResolver[] whenTests, ProcessingNode[] otherwhiseNodes) {
          this.whenNodes = whenNodes;
          this.whenTests = whenTests;
          this.otherwhiseNodes = otherwhiseNodes;
      }
  
      public void compose(ComponentManager manager) throws ComponentException {
  
          setSelector((ComponentSelector)manager.lookup(Selector.ROLE + "Selector"));
  
          // Get the selector, if it's ThreadSafe
          this.threadSafeSelector = (Selector)this.getThreadSafeComponent();
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Prepare data needed by the action
          Map objectModel = env.getObjectModel();
          List mapStack   = context.getMapStack();
          Parameters resolvedParams = MapStackResolver.buildParameters(this.parameters, mapStack);
  
          // If selector is ThreadSafe, avoid select() and try/catch block (faster !)
          if (this.threadSafeSelector != null) {
  
              for (int i = 0; i < this.whenTests.length; i++) {
                  if (this.threadSafeSelector.select(
                          whenTests[i].resolve(mapStack),
                          objectModel,
                          resolvedParams)) {
                      return invokeNodes(this.whenNodes[i], env, context);
                  }
              }
  
              if (this.otherwhiseNodes != null) {
                  return invokeNodes(this.otherwhiseNodes, env, context);
              }
  
              return false;
  
          } else {
              Selector selector = (Selector)this.componentSelector.select(this.componentName);
              try {
  
                  for (int i = 0; i < this.whenTests.length; i++) {
                      if (selector.select(
                              whenTests[i].resolve(mapStack),
                              objectModel,
                              resolvedParams)) {
                          return invokeNodes(this.whenNodes[i], env, context);
                      }
                  }
  
                  if (this.otherwhiseNodes != null) {
                      return invokeNodes(this.otherwhiseNodes, env, context);
                  }
  
                  return false;
              } finally {
                  this.componentSelector.release(selector);
              }
          }
      }
  
      public void dispose() {
          if (this.threadSafeSelector != null) {
              this.componentSelector.release(this.threadSafeSelector);
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java
  
  Index: SelectNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.selection.Selector;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SelectNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SelectNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String type = this.treeBuilder.getTypeForStatement(config, Selector.ROLE + "Selector");
  
          SelectNode node = new SelectNode(type);
          this.treeBuilder.setupNode(node, config);
  
          // Lists of ProcessingNode[] and test resolvers for each "when"
          List whenChildren = new ArrayList();
          List whenTests = new ArrayList();
  
          // Nodes for otherwise (if any)
          ProcessingNode[] otherwhiseNodes = null;
  
          Configuration[] childrenConfig = config.getChildren();
          for (int i = 0; i < childrenConfig.length; i++) {
  
              Configuration childConfig = childrenConfig[i];
              String name = childConfig.getName();
  
              if ("when".equals(name)) {
  
                  checkNamespace(childConfig);
                  whenTests.add(MapStackResolver.getResolver(childConfig.getAttribute("test")));
                  whenChildren.add(buildChildNodes(childConfig));
  
              } else if ("otherwise".equals(name)) {
  
                  checkNamespace(childConfig);
                  if (otherwhiseNodes != null) {
                      String msg = "Duplicate " + name + " (only one is allowed) at " + childConfig.getLocation();
                      getLogger().error(msg);
                      throw new ConfigurationException(msg);
                  }
  
                  otherwhiseNodes = buildChildNodes(childConfig);
  
              } else if (isParameter(childConfig)) {
                  // ignore it. It is handled automatically in setupNode()
  
              } else {
                  // Unknown element
                  String msg = "Unknown element '" + name + "' in select at " + childConfig.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
          }
  
          node.setCases(
              (ProcessingNode[][])whenChildren.toArray(new ProcessingNode[0][0]),
              (MapStackResolver[])whenTests.toArray(new MapStackResolver[whenTests.size()]),
              otherwhiseNodes
          );
  
          return node;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
  
  Index: SerializeNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SerializeNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SerializeNode extends AbstractProcessingNode {
  
      private String serializerName;
  
      private String mimeType;
  
      private int statusCode;
  
      private Map views;
  
      /**
       * 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 void setViews(Map views) {
          this.views = views;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Check view
          if (this.views != null) {
              String cocoonView = env.getView();
              if (cocoonView != null) {
  
                  // Get view node
                  ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
  
                  if (viewNode != null) {
                      if (getLogger().isInfoEnabled()) {
                          getLogger().info("Jumping to view " + cocoonView + " from serializer at " + this.getLocation());
                      }
                      return viewNode.invoke(env, context);
                  }
              }
          }
  
          // Perform link translation if requested
          if (env.getObjectModel().containsKey(Constants.LINK_OBJECT)) {
              context.getEventPipeline().addTransformer(
                  "!link-translator!", null, Parameters.EMPTY_PARAMETERS
              );
          }
  
          StreamPipeline pipeline = context.getStreamPipeline();
  
          if (this.mimeType == null) {
              // No mime-type set on node
              pipeline.setSerializer(
                  this.serializerName,
                  null,
                  Parameters.EMPTY_PARAMETERS // No parameters on serializers
              );
  
          } else {
              // mime-type set on node
              pipeline.setSerializer(
                  this.serializerName,
                  null,
                  Parameters.EMPTY_PARAMETERS,
                  this.mimeType
              );
          }
  
          // Set status code if there is one
          if (this.statusCode >= 0) {
              env.setStatus(this.statusCode);
          }
  
          if (! context.isInternalRequest()) {
              // Process pipeline
              return pipeline.process(env);
  
          } else {
              // Return true : pipeline is finished.
              return true;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
  
  Index: SerializeNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.serialization.Serializer;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SerializeNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SerializeNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private SerializeNode node;
  
      private Collection views;
  
      /** This builder has no parameters -- return <code>false</code> */
      protected boolean hasParameters() {
          return false;
      }
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String type = this.treeBuilder.getTypeForStatement(config, Serializer.ROLE + "Selector");
  
          this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Serializer.ROLE, type, config);
  
          this.node = new SerializeNode(
              type,
              config.getAttribute("mime-type", null),
              config.getAttributeAsInteger("status-code", -1)
          );
          return this.treeBuilder.setupNode(node, config);
      }
  
      public void linkNode() throws Exception {
          this.node.setViews(
              ((SitemapLanguage)this.treeBuilder).getViewNodes(this.views)
          );
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
  
  Index: SitemapLanguage.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  
  import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
  import org.apache.avalon.excalibur.component.RoleManager;
  
  import org.apache.cocoon.components.CocoonComponentManager;
  import org.apache.cocoon.components.ExtendedComponentSelector;
  import org.apache.cocoon.components.LifecycleHelper;
  
  import org.apache.cocoon.generation.Generator;
  import org.apache.cocoon.transformation.Transformer;
  import org.apache.cocoon.serialization.Serializer;
  import org.apache.cocoon.sitemap.SitemapComponentSelector;
  
  import org.apache.cocoon.components.treeprocessor.CategoryNode;
  import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.TreeBuilder;
  
  import org.apache.cocoon.util.StringUtils;
  
  import java.util.*;
  
  /**
   * The tree builder for the sitemap language.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SitemapLanguage.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SitemapLanguage extends TreeBuilder {
  
      private static final String ATTR_PREFIX = "org.apache.cocoon.components.treeprocessor.ViewNodeBuilder";
  
      /**
       * Build a component manager with the contents of the &lt;map:components&gt; element of
       * the tree.
       */
      protected ComponentManager createComponentManager(Configuration tree) throws Exception {
  
          // Get the map:component node
          // Don't check namespace here : this will be done by node builders
          Configuration config = tree.getChild("components", false);
  
          if (config == null) {
              getLogger().debug("Sitemap has no components definition at " + tree.getLocation());
              config = new DefaultConfiguration("", "");
          }
  
          ComponentManager manager = new CocoonComponentManager(this.parentManager);
  
          LifecycleHelper.setupComponent(manager,
              getLogger(),
              this.context,
              this.parentManager,
              this.roleManager,
              this.logKit,
              config
          );
  
          // Set parent of all selectors.
          if (this.parentManager != null) {
  
              for (int i = 0; i < ComponentsSelector.SELECTOR_ROLES.length; i++) {
  
                  String role = ComponentsSelector.SELECTOR_ROLES[i];
  
                  ComponentSelector parentSelector = null;
                  try {
                      parentSelector = (ComponentSelector)this.parentManager.lookup(role);
                  } catch(Exception e) {
                      // ignore and keep it null
                  }
  
                  if (parentSelector != null) {
  
                      ExtendedComponentSelector localSelector = null;
                      try {
                          localSelector = (ExtendedComponentSelector)manager.lookup(role);
  
                          if (localSelector != parentSelector) {
                              // local selector wasn't given by chaining to the parent manager
                              localSelector.setParentSelector(parentSelector);
                          }
                          manager.release(localSelector);
  
                      } catch(Exception e) {
                          // ignore
                      }
  
                      parentManager.release(parentSelector);
                  }
              }
          }
  
          return manager;
      }
  
      //---- Views management
  
      /** Collection of view names for each label */
      private Map labelViews = new HashMap();
  
      /** The views CategoryNode */
      private CategoryNode viewsNode;
  
      /** Are we currently building a view ? */
      private boolean isBuildingView = false;
  
      /**
       * Pseudo-label for views <code>from-position="first"</code> (i.e. generator).
       */
      public static final String FIRST_POS_LABEL = "!first!";
  
      /**
       * Pseudo-label for views <code>from-position="last"</code> (i.e. serializer).
       */
      public static final String LAST_POS_LABEL = "!last!";
  
      /**
       * Set to <code>true</code> while building the internals of a &lt;map:view&gt;
       */
      public void setBuildingView(boolean building) {
          this.isBuildingView = building;
      }
  
      /**
       * Are we currently building a view ?
       */
      public boolean isBuildingView() {
          return this.isBuildingView;
      }
  
      /**
       * Add a view for a label. This is used to register all views that start from
       * a given label.
       *
       * @parameter label the label (or pseudo-label) for the view
       * @parameter view the view name
       */
      public void addViewForLabel(String label, String view) {
          getLogger().debug("views:addViewForLabel(" + label + ", " + view + ")");
          Set views = (Set)this.labelViews.get(label);
          if (views == null) {
              views = new HashSet();
              this.labelViews.put(label, views);
          }
  
          views.add(view);
      }
  
      /**
       * Get the names of views for a given statement. If the cocoon view exists in the returned
       * collection, the statement can directly branch to the view-handling node.
       *
       * @param role the component role (e.g. <code>Generator.ROLE</code>)
       * @param hint the component hint, i.e. the 'type' attribute
       * @param statement the sitemap statement
       * @return the view names for this statement
       */
      public Collection getViewsForStatement(String role, String hint, Configuration statement) throws Exception {
  
          String statementLabels = statement.getAttribute("label", null);
  
          if (this.isBuildingView) {
              // Labels are forbidden inside view definition
              if (statementLabels != null) {
                  String msg = "Cannot put a 'label' attribute inside view definition at " + statement.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
  
              // We are currently building a view. Don't recurse !
              return null;
          }
  
          // Compute the views attached to this component
          Set views = null;
  
          // Build the set for all labels for this statement
          Set labels = new HashSet();
  
          // 1 - labels defined on the component
          try {
              SitemapComponentSelector selector = (SitemapComponentSelector)this.manager.lookup(role + "Selector");
              String[] compLabels = selector.getLabels(hint);
              if (compLabels != null) {
                  for (int i = 0; i < compLabels.length; i++) {
                      labels.add(compLabels[i]);
                  }
              }
          } catch(Exception e) {
              // Ignore (no selector for this role)
              getLogger().debug("No selector for role " + role);
          }
  
          // 2 - labels defined on this statement
          if (statementLabels != null) {
              labels.addAll(splitLabels(statementLabels));
          }
  
          // 3 - pseudo-label depending on the role
          if (role.equals(Generator.ROLE)) {
              labels.add("!first!");
          } else if (role.equals(Serializer.ROLE)) {
              labels.add("!last!");
          }
  
          // Build the set of views attached to these labels
          views = new HashSet();
  
          // Iterate on all labels for this statement
          Iterator labelIter = labels.iterator();
          while(labelIter.hasNext()) {
  
              // Iterate on all views for this labek
              Collection coll = (Collection)this.labelViews.get(labelIter.next());
              if (coll != null) {
                  Iterator viewIter = coll.iterator();
                  while(viewIter.hasNext()) {
                      String viewName = (String)viewIter.next();
  
                      views.add(viewName);
                  }
              }
          }
  
          // Don't keep empty result
          if (views.size() == 0) {
              views = null;
  
              getLogger().debug(statement.getName() + " has no views at " + statement.getLocation());
          } else {
              if (getLogger().isDebugEnabled()) {
                  // Dump matching views
                  StringBuffer buf = new StringBuffer(statement.getName() + " will match views [");
                  Iterator iter = views.iterator();
                  while(iter.hasNext()) {
                      buf.append(iter.next()).append(" ");
                  }
                  buf.append("] at ").append(statement.getLocation());
  
                  getLogger().debug(buf.toString());
              }
          }
  
          return views;
      }
  
      /**
       * Before linking nodes, lookup the view category node used in {@link #getViewNodes(Collection)}.
       */
      protected void linkNodes() throws Exception {
          // Get the views category node
          this.viewsNode = CategoryNodeBuilder.getCategoryNode(this, "views");
  
          super.linkNodes();
      }
  
      /**
       * Get the {view name, view node} map for a collection of view names.
       * This allows to resolve view nodes at build time, thus avoiding runtime lookup.
       *
       * @param viewNames the view names
       * @return association of names to views
       */
      public Map getViewNodes(Collection viewNames) throws Exception {
          if (viewNames == null) {
              return null;
          }
  
          if (this.viewsNode == null) {
              return null;
          }
  
          Map result = new HashMap();
  
          Iterator iter = viewNames.iterator();
          while(iter.hasNext()) {
              String viewName = (String)iter.next();
              result.put(viewName, viewsNode.getNodeByName(viewName));
          }
  
          return result;
      }
  
      /**
       * Split a list of space/comma separated labels into a Collection
       *
       * @return the collection of labels (may be empty, nut never null)
       */
      private static final Collection splitLabels(String labels) {
          if (labels == null) {
              return Collections.EMPTY_SET;
          } else {
              return Arrays.asList(StringUtils.split(labels, ", \t\n\r"));
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapNode.java
  
  Index: SitemapNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  
  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.SitemapRedirector;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode;
  import org.apache.cocoon.components.treeprocessor.EnvironmentSourceResolver;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  
  import java.util.*;
  
  /**
   * The root node of a sitemap.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SitemapNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SitemapNode extends AbstractParentProcessingNode implements Composable {
  
      private static final String REDIRECTOR_ATTR = "sitemap:redirector";
  
      protected ComponentManager manager;
  
      protected ProcessingNode pipelines;
  
      protected ProcessingNode[] otherNodes;
  
      public static SitemapRedirector getRedirector(Environment env) {
          return (SitemapRedirector)env.getAttribute(REDIRECTOR_ATTR);
      }
  
      /**
       * Keep the component manager used everywhere in the tree so that we can
       * cleanly dispose it.
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      /**
       * Set the pipeline nodes that will process the environment.
       */
      public void setPipelines(ProcessingNode pipelines) {
          this.pipelines = pipelines;
      }
  
      /**
       * Set the non-pipeline nodes (views & resources), which are held to properly
       * <code>dispose()</code> them.
       */
      public void setOtherNodes(ProcessingNode[] otherNodes) {
          this.otherNodes = otherNodes;
      }
  
      /**
       * Process the environment. Also adds an <code>EnvironmentSourceResolver</code>
       * and a <code>Redirector</code> in the object model. The previous resolver and
       * redirector, if any, are restored before return.
       */
      public boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          // Recompose context (and pipelines) to the local component manager
          context.recompose(this.manager);
  
          // Create the source resolver relative to the environment.
  
          // Design note : creating the SourceResolver could also have been done
          // in TreeProcessor.invoke(), but doing it here ensures we use the local
          // component manager used by all other nodes.
          EnvironmentSourceResolver resolver = new EnvironmentSourceResolver(this.manager, env);
          SitemapRedirector redirector = new SitemapRedirector(env);
  
          Map objectModel = env.getObjectModel();
  
          Object oldResolver = objectModel.get(OBJECT_SOURCE_RESOLVER);
          Object oldRedirector = env.getAttribute(REDIRECTOR_ATTR);
  
          objectModel.put(OBJECT_SOURCE_RESOLVER, resolver);
          env.setAttribute(REDIRECTOR_ATTR, redirector);
  
          try {
              // FIXME : is there any useful information that can be passed as top-level parameters,
              //         such as the URI of the mount point ?
  
              return this.pipelines.invoke(env, context);
  
          } finally {
  
              // Restore old redirector and resolver
              env.setAttribute(REDIRECTOR_ATTR, oldRedirector);
              objectModel.put(OBJECT_SOURCE_RESOLVER, oldResolver);
  
              // Dispose the resolver
              resolver.dispose();
          }
      }
  
      /**
       * Dispose the component manager.
       */
      public void dispose() {
          if (this.manager instanceof Disposable) {
              ((Disposable)this.manager).dispose();
          }
      }
  }
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapNodeBuilder.java
  
  Index: SitemapNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
  
  import java.util.*;
  
  /**
   * Builds all nodes below the top-level &lt;sitemap&gt; element, and returns the
   * &lt;pipelines&gt; node. There is no node for &gt;sitemap&lt; since no processing
   * occurs at this level.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: SitemapNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class SitemapNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          ProcessingNode[] children = this.buildChildNodes(config);
  
          ProcessingNode pipelines = null;
  
          for (int i = 0; i < children.length; i++) {
              if (children[i] instanceof PipelinesNode) {
                  if (pipelines != null) {
                      String msg = "Only one 'pipelines' is allowed, at " + config.getLocation();
                      getLogger().error(msg);
                      throw new ConfigurationException(msg);
                  }
                  pipelines = children[i];
              }
          }
  
          if (pipelines == null) {
              String msg = "Invalid sitemap : there must be a 'pipelines' at " + config.getLocation();
              getLogger().error(msg);
              throw new ConfigurationException(msg);
          }
  
          return pipelines;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/TransformNode.java
  
  Index: TransformNode.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
  import org.apache.cocoon.components.treeprocessor.InvokeContext;
  import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.List;
  import java.util.Map;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: TransformNode.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class TransformNode extends AbstractProcessingNode implements ParameterizableProcessingNode {
  
      private String transformerName;
  
      private MapStackResolver source;
  
      private Map parameters;
  
      private Map views;
  
      public TransformNode(String name, String source) throws PatternException {
          this.transformerName = name;
          this.source = MapStackResolver.getResolver(source);
      }
  
      public void setParameters(Map parameterMap) {
          this.parameters = parameterMap;
      }
  
      public void setViews(Map views) {
          this.views = views;
      }
  
      public final boolean invoke(Environment env, InvokeContext context)
        throws Exception {
  
          List mapStack = context.getMapStack();
  
          context.getEventPipeline().addTransformer(
              this.transformerName,
              source.resolve(mapStack),
              MapStackResolver.buildParameters(this.parameters, mapStack)
          );
  
          // Check view
          if (this.views != null) {
              String cocoonView = env.getView();
              if (cocoonView != null) {
  
                  // Get view node
                  ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
  
                  if (viewNode != null) {
                      if (getLogger().isInfoEnabled()) {
                          getLogger().info("Jumping to view " + cocoonView + " from transformer at " + this.getLocation());
                      }
                      return viewNode.invoke(env, context);
                  }
              }
          }
  
          // Return false to contine sitemap invocation
          return false;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/TransformNodeBuilder.java
  
  Index: TransformNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.cocoon.transformation.Transformer;
  
  import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  
  import java.util.*;
  
  /**
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: TransformNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class TransformNodeBuilder extends AbstractProcessingNodeBuilder
    implements LinkedProcessingNodeBuilder {
  
      private TransformNode node;
  
      private Collection views;
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          String type = this.treeBuilder.getTypeForStatement(config, Transformer.ROLE + "Selector");
  
          this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Transformer.ROLE, type, config);
  
          this.node = new TransformNode(type, config.getAttribute("src", null));
          return this.treeBuilder.setupNode(node, config);
      }
  
      public void linkNode() throws Exception {
          this.node.setViews(
              ((SitemapLanguage)this.treeBuilder).getViewNodes(this.views)
          );
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ViewNodeBuilder.java
  
  Index: ViewNodeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.treeprocessor.sitemap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.treeprocessor.NamedContainerNodeBuilder;
  import org.apache.cocoon.components.treeprocessor.NamedProcessingNode;
  import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  import org.apache.cocoon.components.treeprocessor.TreeBuilder;
  
  import org.apache.cocoon.util.StringUtils;
  
  import java.util.*;
  
  /**
   * Builds a &lt;map:view&gt;
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Id: ViewNodeBuilder.java,v 1.1 2002/03/05 08:26:23 sylvain Exp $
   */
  
  public class ViewNodeBuilder extends NamedContainerNodeBuilder implements ThreadSafe {
  
      public ProcessingNode buildNode(Configuration config) throws Exception {
  
          // Get the label or position (pseudo-label) of this view.
          String label = config.getAttribute("from-label", null);
  
          if (label == null) {
              String position = config.getAttribute("from-position");
              if ("first".equals(position)) {
                  label = SitemapLanguage.FIRST_POS_LABEL;
              } else if ("last".equals(position)) {
                  label = SitemapLanguage.LAST_POS_LABEL;
              } else {
                  String msg = "Bad value for 'from-position' at " + config.getLocation();
                  getLogger().error(msg);
                  throw new ConfigurationException(msg);
              }
          }
  
          SitemapLanguage sitemapBuilder = (SitemapLanguage)this.treeBuilder;
  
          // Indicate to child builders that we're in a view (they won't perform view branching)
          sitemapBuilder.setBuildingView(true);
  
          // Build children
          NamedProcessingNode result = (NamedProcessingNode)super.buildNode(config);
  
          sitemapBuilder.addViewForLabel(label, result.getName());
  
          // Clear the flag
          sitemapBuilder.setBuildingView(false);
  
          return result;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head><title>package description</title></head>
  <body>
    Implemention of the Sitemap language.
  </body>
    
  
  
  1.11      +4 -4      xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TreeProcessor.java	4 Mar 2002 17:41:21 -0000	1.10
  +++ TreeProcessor.java	5 Mar 2002 08:26:24 -0000	1.11
  @@ -51,17 +51,17 @@
   package org.apache.cocoon.treeprocessor;
   
   /**
  - * @deprecated Moved to org.apache.cocoon.components.processor.treeprocessor.TreeProcessor
  + * @deprecated Moved to org.apache.cocoon.components.treeprocessor.TreeProcessor
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Id: TreeProcessor.java,v 1.10 2002/03/04 17:41:21 sylvain Exp $
  + * @version CVS $Id: TreeProcessor.java,v 1.11 2002/03/05 08:26:24 sylvain Exp $
    */
   
  -public class TreeProcessor extends org.apache.cocoon.components.processor.treeprocessor.TreeProcessor {
  +public class TreeProcessor extends org.apache.cocoon.components.treeprocessor.TreeProcessor {
   
       public void initialize() throws Exception {
       	
           getLogger().warn("The class 'org.apache.cocoon.treeprocessor.Treeprocessor' has moved to " +
  -            "'org.apache.cocoon.components.processor.treeprocessor.TreeProcessor'.");
  +            "'org.apache.cocoon.components.treeprocessor.TreeProcessor'.");
   
           super.initialize();
       }
  
  
  
  1.34      +1 -1      xml-cocoon2/src/webapp/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/cocoon.xconf,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- cocoon.xconf	4 Mar 2002 17:41:22 -0000	1.33
  +++ cocoon.xconf	5 Mar 2002 08:26:24 -0000	1.34
  @@ -497,7 +497,7 @@
   
       To use this engine, comment the declaration above and uncomment the declaration below.
     -->
  -  <!--sitemap class="org.apache.cocoon.components.processor.treeprocessor.TreeProcessor" logger="sitemap"/-->
  +  <!--sitemap class="org.apache.cocoon.components.treeprocessor.TreeProcessor" logger="sitemap"/-->
   
   <!-- ===================== Sitemap Components =========================== -->
   
  
  
  

----------------------------------------------------------------------
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


Mime
View raw message