cziegeler    2002/10/08 02:48:01

  Modified:    src/webapp/samples sitemap.xmap
               src/java/org/apache/cocoon/components/treeprocessor
                        treeprocessor-builtins.xml
               src/java/org/apache/cocoon/components/modules modules.xconf
                        modules.xroles
               src/webapp sitemap.xmap
               src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        PipelinesNodeBuilder.java PipelinesNode.java
  Added:       src/java/org/apache/cocoon/components/modules/input
                        GlobalInputModule.java SitemapVariableHolder.java
  Log:
  Removing global-parameters from sitemap in favour of the new
  global input module which does the same.
  
  Revision  Changes    Path
  1.22      +0 -3      xml-cocoon2/src/webapp/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/samples/sitemap.xmap,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- sitemap.xmap      22 Sep 2002 03:14:22 -0000      1.21
  +++ sitemap.xmap      8 Oct 2002 09:48:00 -0000       1.22
  @@ -214,9 +214,6 @@
   -->
   
    <map:pipelines>
  -  <map:global-parameters>
  -     <!-- Define global parameters here -->
  -  </map:global-parameters>
     <map:component-configurations>
        <!-- Define component configuration here -->
     </map:component-configurations>
  
  
  
  1.9       +1 -1      
xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/treeprocessor-builtins.xml
  
  Index: treeprocessor-builtins.xml
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/treeprocessor-builtins.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- treeprocessor-builtins.xml        24 Sep 2002 08:21:13 -0000      1.8
  +++ treeprocessor-builtins.xml        8 Oct 2002 09:48:00 -0000       1.9
  @@ -149,7 +149,7 @@
         
         <node name="pipelines" 
builder="org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNodeBuilder">
           <allowed-children>pipeline</allowed-children>
  -        <ignored-children>global-parameters, 
component-configurations</ignored-children>
  +        <ignored-children>component-configurations</ignored-children>
         </node>
   
         <node name="components" 
builder="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsNodeBuilder"/>
  
  
  
  1.7       +1 -0      
xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf
  
  Index: modules.xconf
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- modules.xconf     20 Sep 2002 22:49:50 -0000      1.6
  +++ modules.xconf     8 Oct 2002 09:48:01 -0000       1.7
  @@ -4,6 +4,7 @@
      <!-- =============== Sitemap In/Out/Database Modules ==================== -->
      
      <input-modules>
  +      <component-instance logger="core.modules.input" name="global"          
class="org.apache.cocoon.components.modules.input.GlobalInputModule"/>
         <component-instance logger="core.modules.input" name="request"         
class="org.apache.cocoon.components.modules.input.RequestModule"/>
         <component-instance logger="core.modules.input" name="session"         
class="org.apache.cocoon.components.modules.input.SessionModule"/>
         <component-instance logger="core.modules.input" name="request-param"          
 class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
  
  
  
  1.2       +5 -0      
xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xroles
  
  Index: modules.xroles
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xroles,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- modules.xroles    21 Aug 2002 06:15:31 -0000      1.1
  +++ modules.xroles    8 Oct 2002 09:48:01 -0000       1.2
  @@ -13,4 +13,9 @@
     <role 
name="org.apache.cocoon.components.modules.database.AutoIncrementModuleSelector"
           shorthand="autoincrement-modules"
           
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +
  +  <role name="org.apache.cocoon.components.modules.input.SitemapVariableHolder"
  +        shorthand="global-variables"
  +        
default-class="org.apache.cocoon.components.modules.input.SitemapVariableHolder"/>
  +
   </xroles>
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
  
  Index: GlobalInputModule.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.modules.input;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import sun.tools.tree.ThisExpression;
  
  import java.util.Enumeration;
  import java.util.Map;
  
  /**
   * This simple module allows to define global parameters in a sitemap. The
   * values are inherited from one sitemap to its sub sitemaps and can be
   * extended there.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: AbstractInputModule.java,v 1.2 2002/07/31 13:13:24 stephan Exp $
   */
  public final class GlobalInputModule 
      extends AbstractLogEnabled
      implements InputModule, Composable, ThreadSafe {
  
      private ComponentManager manager;
      
      /**
       * Composable
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
      
      /**
       * Standard access to an attribute's value. If more than one value
       * exists, the first is returned. If the value does not exist,
       * null is returned. To get all values, use {@link
       * #getAttributeValues getAttributeSet} or {@link
       * #getAttributeNames getAttributeNames} and {@link #getAttribute
       * getAttribute} to get them one by one.
       * @param name a String that specifies what the caller thinks
       * would identify an attribute. This is mainly a fallback if no
       * modeConf is present.
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param objectModel
       */
      public Object getAttribute( String name, Configuration modeConf, Map objectModel 
) 
      throws ConfigurationException {
          SitemapVariableHolder holder = null;
          try {
              holder = 
(SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
              return holder.get(name); 
          } catch (ComponentException ce) {
              throw new ConfigurationException("Unable to lookup 
SitemapVariableHolder.", ce);
          } finally {
              this.manager.release(holder);
          }
      }
  
  
      /**
       * Returns an Enumeration of String objects containing the names
       * of the attributes available. If no attributes are available,
       * the method returns an empty Enumeration.
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param objectModel
       */
      public Enumeration getAttributeNames( Configuration modeConf, Map objectModel ) 
      throws ConfigurationException {
          SitemapVariableHolder holder = null;
          try {
              holder = 
(SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
              // return holder.getKeys(); 
              return null; 
          } catch (ComponentException ce) {
              throw new ConfigurationException("Unable to lookup 
SitemapVariableHolder.", ce);
          } finally {
              this.manager.release(holder);
          }
      }
  
  
      /**
       * Returns an array of String objects containing all of the values
       * the given attribute has, or null if the attribute does not
       * exist. As an alternative, {@link #getAttributeNames
       * getAttributeNames} together with {@link #getAttribute
       * getAttribute} can be used to get the values one by one.
       * @param name a String that specifies what the caller thinks
       * would identify an attributes. This is mainly a fallback
       * if no modeConf is present.
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param objectModel
       */
      public Object[] getAttributeValues( String name, Configuration modeConf, Map 
objectModel ) 
      throws ConfigurationException {
          Object o = this.getAttribute(name, modeConf, objectModel);
          if (o != null) {
              return new Object[] {o};
          }
          return null;
      }
  
  }
  
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
  
  Index: SitemapVariableHolder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.modules.input;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.component.Component;
  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.AbstractLogEnabled;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.SitemapConfigurable;
  import org.apache.cocoon.environment.SourceResolver;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  /**
   * This "component" is a trick to get global variables on a per
   * sitemap base
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: AbstractInputModule.java,v 1.2 2002/07/31 13:13:24 stephan Exp $
   */
  public final class SitemapVariableHolder
      extends AbstractLogEnabled
      implements Component, Configurable, SitemapConfigurable, Recyclable
  {
   
      public static final String ROLE = SitemapVariableHolder.class.getName();
      
      /**
       * Stores (global) configuration parameters as <code>key</code> /
       * <code>value</code> pairs from the component configuration
       */
      private Map values;
  
      /** Manager for sitemap/sub sitemap configuration */
      private Manager manager;
  
      /**
       * Configures the database access helper.
       *
       * Takes all elements nested in component declaration and stores
       * them as key-value pairs in <code>settings</code>. Nested
       * configuration option are not catered for. This way global
       * configuration options can be used.
       *
       * For nested configurations override this function.
       * */
      public void configure(Configuration conf) 
      throws ConfigurationException {
          this.manager = new Manager();
          final Configuration[] parameters = conf.getChildren();
          final int len = parameters.length;
          this.values = new HashMap( len );
          for ( int i = 0; i < len; i++) {
              final String key = parameters[i].getName();
              final String value = parameters[i].getValue();
              if ( key != null && value != null) {
                  this.values.put(key, value);
              }
          }
      }
  
       /**
       * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
       * used to process the request.
       *  This method is automatically called for each request. Do not invoke
       *  this method by hand.
       */
      public void setup(SourceResolver resolver, Map objectModel)
      throws ProcessingException, SAXException, IOException {
          // we don't need them...
      }
      
      /**
       * Set the <code>Configuration</code> from a sitemap
       */
      public void setSitemapConfiguration(Configuration config)
      throws ConfigurationException {
          // add sitemap configuration
          this.manager.add(config);
      }
  
      /**
       * Recyclable
       */
      public void recycle() {
          // clear sitemap configuration
          this.manager.init(this.values);
      }
  
      /**
       * Get a value
       */
      public Object get(String key) {
          return this.manager.get(key);
      }
      
      /**
       * Get keys
       */
      public Iterator getKeys() {
          return this.manager.getKeys();
      }
  }
  
  final class Manager {
      
      private Map values = new HashMap();
      
      void init(Map newValues) {
          this.values.clear();
          this.values.putAll(newValues);
      }
      
      void add(Configuration conf) 
      throws ConfigurationException {
          final Configuration[] parameters = conf.getChildren();
          final int len = parameters.length;
          this.values = new HashMap( len );
          for ( int i = 0; i < len; i++) {
              final String key = parameters[i].getName();
              final String value = parameters[i].getValue();
              if ( key != null && value != null) {
                  this.values.put(key, value);
              }
          }
      }
      
      Object get(String key) {
          return this.values.get(key);
      }
      
      Iterator getKeys() {
          return this.values.keySet().iterator();
      }
  }
  
  
  
  1.77      +9 -3      xml-cocoon2/src/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/sitemap.xmap,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- sitemap.xmap      22 Sep 2002 03:14:08 -0000      1.76
  +++ sitemap.xmap      8 Oct 2002 09:48:01 -0000       1.77
  @@ -403,10 +403,16 @@
   -->
   
    <map:pipelines>
  -  <map:global-parameters>
  -     <!-- Define global parameters here -->
  -  </map:global-parameters>
     <map:component-configurations>
  +    <global-variables>
  +       <!-- Define global parameters here:
  +           <skin>my_skin</skin>
  +           ...
  +           You can access them by {global:*name*}, e.g. {global:skin}.
  +           These values are inherited into sub-sitemaps and can
  +           be extended there.
  +        -->
  +    </global-variables>
        <!-- Define component configuration here -->
     </map:component-configurations>
   
  
  
  
  1.6       +3 -21     
xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java
  
  Index: PipelinesNodeBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PipelinesNodeBuilder.java 11 Sep 2002 10:08:35 -0000      1.5
  +++ PipelinesNodeBuilder.java 8 Oct 2002 09:48:01 -0000       1.6
  @@ -70,31 +70,13 @@
   
       public ProcessingNode buildNode(Configuration config)
       throws Exception {
  -        Map parameters = null;
  -
  -        // check for global paramters
  -        Configuration child = config.getChild("global-parameters", false);
  -        if ( null != child ) {
  -            this.checkNamespace(child);
  -
  -            Configuration[] children = child.getChildren("parameter");
  -            if (children.length != 0) {
  -                parameters = new HashMap();
  -                for (int i = 0; i < children.length; i++) {
  -                    Configuration param = children[i];
  -                    this.checkNamespace(param);
  -                    parameters.put(param.getAttribute("name"), 
param.getAttribute("value"));
  -                }
  -            }
  -        }
           // check for component configurations
  -        child = config.getChild("component-configurations", false);
  +        Configuration child = config.getChild("component-configurations", false);
           if (child != null) {
               this.checkNamespace(child);
               this.treeBuilder.getProcessor().setComponentConfigurations(child);
           }
  -        PipelinesNode node = new PipelinesNode(this.treeBuilder.getProcessor(),
  -                                               parameters);
  +        PipelinesNode node = new PipelinesNode(this.treeBuilder.getProcessor());
           this.treeBuilder.setupNode(node, config);
   
           ProcessingNode[] children = buildChildNodes(config);
  
  
  
  1.10      +3 -13     
xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java
  
  Index: PipelinesNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PipelinesNode.java        11 Sep 2002 10:08:35 -0000      1.9
  +++ PipelinesNode.java        8 Oct 2002 09:48:01 -0000       1.10
  @@ -80,18 +80,12 @@
   
       private Processor processor;
   
  -    /** Global sitemap parameters */
  -    private Map globalParameters;
  -
       /**
        * Constructor
        * @param processor               The processor for this sitemap
  -     * @param parameters              Optional global parameters for this sitemap 
(can be null)
        */
  -    public PipelinesNode(Processor       processor,
  -                         Map             parameters) {
  +    public PipelinesNode(Processor       processor) {
           this.processor = processor;
  -        this.globalParameters = parameters;
       }
   
       /**
  @@ -146,11 +140,7 @@
               // FIXME : is there any useful information that can be passed as 
top-level parameters,
               //         such as the URI of the mount point ?
   
  -            if ( null == this.globalParameters) {
  -                return invokeNodes(this.children, env, context);
  -            } else {
  -                return invokeNodes(this.children, env, context, 
this.globalParameters);
  -            }
  +            return invokeNodes(this.children, env, context);
   
           } finally {
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to