You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2002/03/15 16:15:08 UTC

cvs commit: xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database AbstractAutoIncrementModule.java AutoIncrementModule.java HsqlIdentityAutoIncrementModule.java IfxSerialAutoIncrementModule.java ManualAutoIncrementModule.java MysqlAutoIncrementModule.java

haul        02/03/15 07:15:08

  Added:       src/scratchpad/src/org/apache/cocoon/components/modules
                        modules.xconf
               src/scratchpad/src/org/apache/cocoon/components/modules/output
                        AbstractOutputModule.java OutputModule.java
                        RequestAttributeOutputModule.java
                        SessionAttributeOutputModule.java
               src/scratchpad/src/org/apache/cocoon/components/modules/input
                        AbstractInputModule.java HeaderAttributeModule.java
                        InputModule.java RequestAttributeModule.java
                        RequestParameterModule.java RequestURIModule.java
                        SessionAttributeModule.java
               src/scratchpad/src/org/apache/cocoon/components/modules/database
                        AbstractAutoIncrementModule.java
                        AutoIncrementModule.java
                        HsqlIdentityAutoIncrementModule.java
                        IfxSerialAutoIncrementModule.java
                        ManualAutoIncrementModule.java
                        MysqlAutoIncrementModule.java
  Log:
  Simple in/out components that can be used in other components
  so that their in- and outputs are pluggable.
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/modules.xconf
  
  Index: modules.xconf
  ===================================================================
  <?xml version="1.0"?>
  
  <xconf xpath="/cocoon">
  <!-- =============== Sitemap In/Out/Database Modules ==================== -->
  
     <input-modules>
        <component-instance name="request"   class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
        <component-instance name="attribute" class="org.apache.cocoon.components.modules.input.RequestAttributeModule"/>
        <component-instance name="URI"       class="org.apache.cocoon.components.modules.input.RequestURIModule"/>
        <component-instance name="header"    class="org.apache.cocoon.components.modules.input.HeaderAttributeModule"/>
        <component-instance name="session"   class="org.apache.cocoon.components.modules.input.SessionAttributeModule"/>
     </input-modules>
  
     <output-modules>
        <component-instance name="attribute" class="org.apache.cocoon.components.modules.output.RequestAttributeOutputModule"/>
        <component-instance name="session"   class="org.apache.cocoon.components.modules.output.SessionAttributeOutputModule"/>
     </output-modules>
  
     <autoincrement-modules>
        <component-instance name="auto" class="org.apache.cocoon.components.modules.database.HsqlIdentityAutoIncrementModule"/>
  <!--
        Choose the one suitable for your DBMS. You *can* have more than
        one at a time, but they need to have different names. You then
        need to specify explicitly, which one to use in your descriptor
        file.
  
        <component-instance name="auto" class="org.apache.cocoon.components.modules.database.ManualAutoIncrementModule"/>
        <component-instance name="auto" class="org.apache.cocoon.components.modules.database.IfxSerialAutoIncrementModule"/>
        <component-instance name="auto" class="org.apache.cocoon.components.modules.database.MysqlAutoIncrementModule"/>
  -->
     </autoincrement-modules>
  </xconf>
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/output/AbstractOutputModule.java
  
  Index: AbstractOutputModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.output;
  
  import org.apache.avalon.framework.activity.Disposable;
  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.HashMap;
  
  /**
   * AbstractOutputModule gives you the infrastructure for easily
   * deploying more output modules.  In order to get at the
   * Logger, use getLogger().
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: AbstractOutputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public abstract class AbstractOutputModule extends AbstractLoggable
      implements OutputModule, Configurable, Disposable {
  
      /**
       * Stores (global) configuration parameters as <code>key</code> /
       * <code>value</code> pairs.
       */
      protected HashMap settings = null;
  
      /**
       * Configures the module.
       *
       * 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 {
  
          if (conf != null) {
              String key = null;
              String val = null;
              Configuration[] parameters = conf.getChildren();
              this.settings = new HashMap(parameters.length);
              for ( int i = 0; i < parameters.length; i++) {
                  key = parameters[i].getName();
                  val = parameters[i].getValue();
                  if ( key != null )
                      this.settings.put(key, val);
              }
          }
      }
  
      /**
       *  dispose
       */
      public void dispose() {
          // Purposely empty so that we don't need to implement it in every
          // class.
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/output/OutputModule.java
  
  Index: OutputModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.output;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * Communicate results to other components. This could be done via
   * request attributes, session attribute etc. Implementors should obey
   * the transactional nature and e.g. queue values as request
   * attributes and do the real communication e.g. to a bean only when
   * the transaction completes successfully.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: OutputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public interface OutputModule extends Component {
  
      String ROLE = "org.apache.cocoon.components.modules.input.OutputModule";
  
      /**
       * communicate an attribute value to further processing logic.
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param request The request object
       * @param name The attribute's label, consisting of "table.column"
       * or "table.column[index]" in case of multiple attributes of the
       * same spec.
       * @param value The attriute's value.
       * */
      void setAttribute( Configuration modeConf, Request request, String name, Object value );
  
  
      /**
       * If a database transaction needs to rollback, this is called to
       * inform the further processing logic about this fact. All
       * already set attribute values are invalidated. <em>This is difficult
       * because only the request object can be used to synchronize this
       * and build some kind of transaction object. Beaware that sending
       * your data straight to some beans or other entities could result
       * in data corruption!</em>
       * */
      void rollback( Configuration modeConf, Request request, Exception e );
  
  
      /**
       * Signal that the database transaction completed
       * successfully. See notes on @link{rollback}.
       * */
      void commit( Configuration modeConf, Request request );
  
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/output/RequestAttributeOutputModule.java
  
  Index: RequestAttributeOutputModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.output;
  
  import java.util.Enumeration;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * Abstraction layer to encapsulate different output
   * destinations. Configuration option &lt;key-prefix&gt; defaults to
   * "org.apache.cocoon.components.modules.output.OutputModule"+":"
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: RequestAttributeOutputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class RequestAttributeOutputModule extends AbstractOutputModule implements OutputModule {
  
      /**
       * communicate an attribute value to further processing logic.
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param request The request object
       * @param name The attribute's label, consisting of "table.column"
       * or "table.column[index]" in case of multiple attributes of the
       * same spec.
       * @param value The attriute's value.
       * */
      public void setAttribute( Configuration modeConf, Request request, String name, Object value ) {
  
          request.setAttribute( ( (String) this.settings.get("key-prefix",
                                                             "org.apache.cocoon.components.modules.output.OutputModule" ) )
                                + ":" + name, value);
      }
  
  
      /**
       * If a database transaction needs to rollback, this is called to
       * inform the further processing logic about this fact. All
       * already set attribute values are invalidated. <em>This is difficult
       * because only the request object can be used to synchronize this
       * and build some kind of transaction object. Beaware that sending
       * your data straight to some beans or other entities could result
       * in data corruption!</em>
       * */
      public void rollback( Configuration modeConf, Request request, Exception e ) {
          /*
            Enumeration attributes = request.getAttributeNames();
            while ( attributes.hasMoreElements() ) {
                String name = (String) attributes.nextElement();
                if ( name.startsWith("org.apache.cocoon.acting.ModularDatabaseAccess.OutputModule:") ) {
                    request.removeAttribute(name);
                }
            }
          */
          request.setAttribute( ( (String) this.settings.get("key-prefix",
                                                             "org.apache.cocoon.components.modules.output.OutputModule" ) ) + ":",
                                e.getMessage());
      }
  
  
      /**
       * Signal that the database transaction completed
       * successfully. See notes on @link{rollback}.
       * */
      public void commit( Configuration modeConf, Request request )
      {
          // empty method
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/output/SessionAttributeOutputModule.java
  
  Index: SessionAttributeOutputModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.output;
  
  import java.util.Enumeration;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * Abstraction layer to encapsulate different output
   * destinations. Configuration option &lt;key-prefix&gt; defaults to
   * "org.apache.cocoon.components.modules.output.OutputModule"+":"
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: SessionAttributeOutputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   * */
  public class SessionAttributeOutputModule extends AbstractOutputModule implements OutputModule {
      
      /**
       * communicate an attribute value to further processing logic. 
       * @param modeConf column's mode configuration from resource
       * description. This argument is optional.
       * @param request The request object
       * @param name The attribute's label, consisting of "table.column"
       * or "table.column[index]" in case of multiple attributes of the
       * same spec.
       * @param value The attriute's value.
       * */
      public void setAttribute( Configuration modeConf, Request request, String name, Object value ) {
  
          request
              .getSession()
              .setAttribute(((String) this.settings.get("key-prefix",
                                                        "org.apache.cocoon.components.modules.output.OutputModule"))
                            + ":" + name, value);
      }
  
  
      /**
       * If a database transaction needs to rollback, this is called to
       * inform the further processing logic about this fact. All
       * already set attribute values are invalidated. <em>This is difficult
       * because only the request object can be used to synchronize this
       * and build some kind of transaction object. Beaware that sending
       * your data straight to some beans or other entities could result
       * in data corruption!</em>
       * */
      public void rollback( Configuration modeConf, Request request, Exception e ) {
          Enumeration attributes = request.getSession().getAttributeNames();
          while ( attributes.hasMoreElements() ) {
              String name = (String) attributes.nextElement();
              if ( name.startsWith("org.apache.cocoon.acting.ModularDatabaseAccess.OutputModule:") ) {
                  request.getSession().removeAttribute(name);
              }
          }
          request
              .getSession()
              .setAttribute(((String) this.settings.get("key-prefix",
                                                        "org.apache.cocoon.components.modules.output.OutputModule")) 
                            + ":", e.getMessage());
      }
  
  
      /**
       * Signal that the database transaction completed
       * successfully. See notes on @link{rollback}.
       * */
      public void commit( Configuration modeConf, Request request )
      {
          // empty method
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/AbstractInputModule.java
  
  Index: AbstractInputModule.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  <st...@apache.org>. 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.activity.Disposable;
  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.HashMap;
  
  /**
   * AbstractDatabaseModule gives you the infrastructure for easily
   * deploying more InputModules.  In order to get at the
   * Logger, use getLogger().
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: AbstractInputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public abstract class AbstractInputModule extends AbstractLoggable
      implements InputModule, Configurable, Disposable {
  
      /**
       * Stores (global) configuration parameters as <code>key</code> /
       * <code>value</code> pairs.
       */
      protected HashMap settings = null;
  
      /**
       * 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 {
  
          if (conf != null) {
              String key = null;
              String val = null;
              Configuration[] parameters = conf.getChildren();
              this.settings = new HashMap(parameters.length);
              for ( int i = 0; i < parameters.length; i++) {
                  key = parameters[i].getName();
                  val = parameters[i].getValue();
                  if ( key != null )
                      this.settings.put(key, val);
              }
          }
      }
  
      /**
       *  dispose
       */
      public void dispose() {
          // Purposely empty so that we don't need to implement it in every
          // class.
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/HeaderAttributeModule.java
  
  Index: HeaderAttributeModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.Enumeration;
  import java.util.List;
  import java.util.LinkedList;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * HeaderAttributeModule accesses request header attributes. If the
   * attribute name contains an askerisk "*" this is considered a
   * wildcard and all attributes that would match this wildcard are
   * considered to be part of an array of that name for
   * getAttributeValues. Only one "*" is allowed.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: HeaderAttributeModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $ */
  public class HeaderAttributeModule extends AbstractInputModule implements ThreadSafe {
      
      public Object getAttribute( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String pname = name;
          if ( modeConf != null ) {
              pname = modeConf.getAttribute( "parameter", pname );
          }
          return request.getHeader( pname );
      }
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Request request )
          throws ConfigurationException {
  
          return request.getHeaderNames();
      }
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String wildcard = name;
          if ( modeConf != null ) {
              wildcard = modeConf.getAttribute( "parameter", wildcard );
          }
          int wildcardIndex = wildcard.indexOf( "*" );
          if ( wildcardIndex != -1 ) {
              // "*" contained in attribute name => combine all
              // attributes' values that match prefix, suffix
              
              // split the attribute's name so that the "*" could be
              // determined by looking at the attributes' names that
              // start with the prefix and end with the suffix
              //
              String prefix = wildcard.substring( 0, wildcardIndex );
              String suffix;
              if ( wildcard.length() >= wildcardIndex + 1 ) {
                  suffix = wildcard.substring( wildcardIndex + 1 );
              } else {
                  suffix = "";
              }
              List values = new LinkedList();
              Enumeration names = request.getHeaderNames();
              
              while (names.hasMoreElements()) {
                  String pname = (String) names.nextElement();
                  if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
                      values.add( request.getHeader( pname ) );
                  }
              }
              
              return values.toArray();
  
          } else {
              // no "*" in attribute name => just return all values of
              // this one attribute. Make sure, it's an array.
              
              Object value = request.getHeader( wildcard );
              if ( value != null && !value.getClass().isArray() ) {
                  Object[] values = new Object[1];
                  values[0] = value;
                  return values;
              } else {
                  return (Object[]) value;
              }
              
          }
      
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/InputModule.java
  
  Index: InputModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.SortedSet;
  import java.util.Enumeration;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * AttributeModule specifies an interface for components that provide
   * access to individual attributes e.g. request parameters, request
   * attributes, session attributes &c.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: InputModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public interface InputModule extends Component {
  
      String ROLE = "org.apache.cocoon.components.modules.input.InputModule";
  
  
      /**
       * 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} or {@link getAttributeSet} and {@link
       * getValue} 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 request the request object
       */
      Object getAttribute( String name, Configuration modeConf, Request request ) throws ConfigurationException;
  
  
      /**
       * 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 request the request object
       */
      Enumeration getAttributeNames( Configuration modeConf, Request request ) throws ConfigurationException;
  
  
      /**
       * 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 getAttributeSet} together with
       * {@link getValue} 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 request the request object
       */
      Object[] getAttributeValues( String name, Configuration modeConf, Request request ) throws ConfigurationException;
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
  
  Index: RequestAttributeModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.Enumeration;
  import java.util.List;
  import java.util.LinkedList;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * RequestAttributeModule accesses request attributes. If the
   * attribute name contains an askerisk "*" this is considered a
   * wildcard and all attributes that would match this wildcard are
   * considered to be part of an array of that name for
   * getAttributeValues. Only one "*" is allowed.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: RequestAttributeModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class RequestAttributeModule extends AbstractInputModule implements ThreadSafe {
  
      public Object getAttribute( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String pname = name;
          if ( modeConf != null ) {
              pname = modeConf.getAttribute( "parameter", pname );
          }
          return request.getAttribute( pname );
      }
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Request request )
          throws ConfigurationException {
  
          return request.getAttributeNames();
      }
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String wildcard = name;
          if ( modeConf != null ) {
              wildcard = modeConf.getAttribute( "parameter", wildcard );
          }
          int wildcardIndex = wildcard.indexOf( "*" );
          if ( wildcardIndex != -1 ) {
              // "*" contained in attribute name => combine all
              // attributes' values that match prefix, suffix
  
              // split the attribute's name so that the "*" could be
              // determined by looking at the attributes' names that
              // start with the prefix and end with the suffix
              //
              String prefix = wildcard.substring( 0, wildcardIndex );
              String suffix;
              if ( wildcard.length() >= wildcardIndex + 1 ) {
                  suffix = wildcard.substring( wildcardIndex + 1 );
              } else {
                  suffix = "";
              }
              List values = new LinkedList();
              Enumeration names = request.getAttributeNames();
  
              while (names.hasMoreElements()) {
                  String pname = (String) names.nextElement();
                  if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
                      values.add( request.getAttribute( pname ) );
                  }
              }
  
              return values.toArray();
  
          } else {
              // no "*" in attribute name => just return all values of
              // this one attribute. Make sure, it's an array.
  
              Object value = request.getAttribute( wildcard );
              if ( value != null && !value.getClass().isArray() ) {
                  Object[] values = new Object[1];
                  values[0] = value;
                  return values;
              } else {
                  return (Object[]) value;
              }
  
          }
  
      }
  
  
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/RequestParameterModule.java
  
  Index: RequestParameterModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.Enumeration;
  import java.util.List;
  import java.util.LinkedList;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * RequestParameterModule accesses request parameters. If the
   * parameter name contains an askerisk "*" this is considered a
   * wildcard and all parameters that would match this wildcard are
   * considered to be part of an array of that name for
   * getAttributeValues. Only one "*" is allowed. Wildcard matches take
   * precedence over real arrays. In that case only the first value of
   * such array is returned.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: RequestParameterModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class RequestParameterModule extends AbstractInputModule implements ThreadSafe {
  
      public Object getAttribute( String name, Configuration modeConf, Request request ) throws ConfigurationException {
  
          String pname = name;
          if ( modeConf != null ) {
              pname = modeConf.getAttribute( "parameter", pname );
          }
          return request.getParameter( pname );
      }
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Request request ) throws ConfigurationException {
  
          return request.getParameterNames();
      }
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String wildcard = name;
          if ( modeConf != null ) {
              wildcard = modeConf.getAttribute( "parameter", wildcard );
          }
          int wildcardIndex = wildcard.indexOf( "*" );
          if ( wildcardIndex != -1 ) {
              // "*" contained in parameter name => combine all
              // parameters' values that match prefix, suffix
  
              // split the parameter's name so that the "*" could be
              // determined by looking at the parameters' names that
              // start with the prefix and end with the suffix
              //
              String prefix = wildcard.substring( 0, wildcardIndex );
              String suffix;
              if ( wildcard.length() >= wildcardIndex + 1 ) {
                  suffix = wildcard.substring( wildcardIndex + 1 );
              } else {
                  suffix = "";
              }
              List values = new LinkedList();
              Enumeration names = request.getParameterNames();
  
              while (names.hasMoreElements()) {
                  String pname = (String) names.nextElement();
                  if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
                      values.add( request.getParameter( pname ) );
                  }
              }
  
              return values.toArray();
  
          } else {
              // no "*" in parameter name => just return all values of
              // this one parameter.
  
              return request.getParameterValues( wildcard );
  
          }
  
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/RequestURIModule.java
  
  Index: RequestURIModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.Enumeration;
  import java.util.List;
  import java.util.LinkedList;
  import java.util.StringTokenizer;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * RequestURIModule accesses the request URI. If the
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: RequestURIModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class RequestURIModule extends AbstractInputModule implements ThreadSafe {
  
      final static Enumeration returnNames = new StringTokenizer("requestURI");
  
      public Object getAttribute( String name, Configuration modeConf, Request request ) throws ConfigurationException {
  
          String uri = request.getSitemapURI();
  
          if (uri.startsWith("/")) {
              uri = uri.substring(1);
          }
  
          return uri;
      }
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Request request ) throws ConfigurationException {
  
          return RequestURIModule.returnNames;
      }
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
              List values = new LinkedList();
              values.add( this.getAttribute(name, modeConf, request) );
  
              return values.toArray();
              
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/input/SessionAttributeModule.java
  
  Index: SessionAttributeModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.input;
  
  import java.util.Enumeration;
  import java.util.List;
  import java.util.LinkedList;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.Session;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * SessionAttributeModule accesses session attributes. If the
   * attribute name contains an askerisk "*" this is considered a
   * wildcard and all attributes that would match this wildcard are
   * considered to be part of an array of that name for
   * getAttributeValues. Only one "*" is allowed.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: SessionAttributeModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class SessionAttributeModule extends AbstractInputModule implements ThreadSafe {
  
      public Object getAttribute( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String pname = name;
          if ( modeConf != null ) {
              pname = modeConf.getAttribute( "parameter", pname );
          }
          return request.getSession().getAttribute( pname );
      }
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Request request )
          throws ConfigurationException {
  
          return request.getSession().getAttributeNames();
      }
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Request request )
          throws ConfigurationException {
  
          String wildcard = name;
          if ( modeConf != null ) {
              wildcard = modeConf.getAttribute( "parameter", wildcard );
          }
          int wildcardIndex = wildcard.indexOf( "*" );
          if ( wildcardIndex != -1 ) {
              // "*" contained in attribute name => combine all
              // attributes' values that match prefix, suffix
  
              // split the attribute's name so that the "*" could be
              // determined by looking at the attributes' names that
              // start with the prefix and end with the suffix
              //
              String prefix = wildcard.substring( 0, wildcardIndex );
              String suffix;
              if ( wildcard.length() >= wildcardIndex + 1 ) {
                  suffix = wildcard.substring( wildcardIndex + 1 );
              } else {
                  suffix = "";
              }
              List values = new LinkedList();
              Enumeration names = request.getSession().getAttributeNames();
  
              while (names.hasMoreElements()) {
                  String pname = (String) names.nextElement();
                  if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
                      values.add( request.getSession().getAttribute( pname ) );
                  }
              }
  
              return values.toArray();
  
          } else {
              // no "*" in attribute name => just return all values of
              // this one attribute. Make sure, it's an array.
  
              Object value = request.getSession().getAttribute( wildcard );
              if ( value != null && !value.getClass().isArray() ) {
                  Object[] values = new Object[1];
                  values[0] = value;
                  return values;
              } else {
                  return (Object[]) value;
              }
  
          }
  
      }
  
  
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/AbstractAutoIncrementModule.java
  
  Index: AbstractAutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import org.apache.avalon.framework.activity.Disposable;
  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.HashMap;
  
  /**
   * AbstractDatabaseModule gives you the infrastructure for easily
   * deploying more AutoIncrementModules.  In order to get at the Logger, use
   * getLogger().
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: AbstractAutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public abstract class AbstractAutoIncrementModule extends AbstractLoggable
      implements AutoIncrementModule, Configurable, Disposable {
  
      /**
       * Stores (global) configuration parameters as <code>key</code> /
       * <code>value</code> pairs.
       */
      protected HashMap settings = null;
  
      /**
       * Configures the database access module.
       *
       * 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 {
  
          if (conf != null) {
              String key = null;
              String val = null;
              Configuration[] parameters = conf.getChildren();
              this.settings = new HashMap(parameters.length);
              for ( int i = 0; i < parameters.length; i++) {
                  key = parameters[i].getName();
                  val = parameters[i].getValue();
                  if ( key != null )
                      this.settings.put(key, val);
              }
          }
      }
  
      /**
       *  dispose
       */
      public void dispose() {
          // Purposely empty so that we don't need to implement it in every
          // class.
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/AutoIncrementModule.java
  
  Index: AutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import java.sql.Connection;
  import java.sql.Statement;
  import java.sql.SQLException;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Abstraction layer to encapsulate different DBMS behaviour for key
   * attribute columns.
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: AutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   * */
  public interface AutoIncrementModule extends Component {
  
      String ROLE = "org.apache.cocoon.components.modules.database.AutoIncrementModule";
  
  
      /**
       * Return key attribute value of last inserted row.
       *
       * @param name a String that specifies what the caller thinks
       * would identify a set of parameters. This is mainly a fallback
       * if no modeConf is present.
  
       * @param tableConf Table's configuration from resource description.
       * @param columnConf column's configuration from resource description.
       * @param mdoeConf this mode's configuration from resource description.
       * @param conn Connection
       * @param stmt Statement that was executed to insert the last row.
       * @param request The request object
       * @return value representing the last key value value.
       * */
      Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                           Connection conn, Statement stmt, Request request ) throws SQLException, ConfigurationException;
  
  
      /**
       * Boolean whether the key attribute column needs to be included
       * in the insert query.
       *
       * @return true if the column is needed, false if the column
       * should be skipped.
       * */
      boolean includeInQuery( );
  
  
      /**
       * Boolean whether the key attribute needs to be included in the
       * insert query as an attribute value (no subquery).
       *
       * @return true if a value is needed, false if a subquery
       * expression is used or the column is skipped altogether.
       * */
      boolean includeAsValue( );
  
  
      /**
       * Provide the value for the key attribute column.
       *
       * If a value for the key value column is needed (i.e. the column
       * is not skipped), this value is computed here.
       *
       * @param tableConf Table's configuration from resource description.
       * @param columnConf column's configuration from resource description.
       * @param mdoeConf this mode's configuration from resource description.
       * @param conn Connection
       * @param request The request object
       * @param idx In case of multiple rows to be inserted, index to the desired row
       * @return exact value for key attribute column
       * */
      Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                          Connection conn, Request request ) throws SQLException, ConfigurationException;
  
  
      /**
       * Provide subquery string for the key attribute column.
       *
       * If a value for the autoincrement column is needed (i.e. the
       * column is not skipped), and the value can be determined through
       * a nested subquery, this function provides the subquery as a
       * string.
       *
       * @return subquery string for autoincrement column.
       */
      String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf ) throws ConfigurationException;
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/HsqlIdentityAutoIncrementModule.java
  
  Index: HsqlIdentityAutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import java.lang.Integer;
  import java.util.SortedSet;
  import java.sql.CallableStatement;
  import java.sql.PreparedStatement;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.sql.Types;
  import java.sql.SQLException;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
   *
   * Here: HSQLDB 1.6 IDENTITY columns
   * {@link http://hsqldb.sourceforge.net}
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: HsqlIdentityAutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class HsqlIdentityAutoIncrementModule implements AutoIncrementModule, ThreadSafe {
  
      public Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                  Connection conn, Statement stmt, Request request )  throws SQLException, ConfigurationException {
  
          Integer id = null;
          /*
            // if hsqldb did support callable statements ...
  
            CallableStatement callStmt = conn.prepareCall("? = {CALL IDENTITY()}");
            callStmt.registerOutParameter(1, Types.INTEGER);
            ResultSet resultSet = callStmt.executeQuery();
          */
  
          PreparedStatement pstmt = conn.prepareStatement("CALL IDENTITY()");
          ResultSet resultSet = pstmt.executeQuery();
          while ( resultSet.next() ) {
              id = new Integer(resultSet.getInt(1));
          }
          resultSet.close();
  
          return id;
      }
  
  
      public boolean includeInQuery() { return false; }
  
  
      public boolean includeAsValue() { return false; }
  
  
      public Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                 Connection conn, Request request ) throws SQLException, ConfigurationException {
  
          return null;
      }
  
  
      public String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf )
          throws ConfigurationException {
  
          return null;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/IfxSerialAutoIncrementModule.java
  
  Index: IfxSerialAutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import java.lang.Integer;
  import java.util.SortedSet;
  import java.sql.Connection;
  import java.sql.Statement;
  import java.sql.SQLException;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import com.informix.jdbc.IfxStatement;
  
  /**
   * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
   *
   * Here: Informix IUS 9.21 SERIAL columns
   * (need another one for SERIAL8 ones!)
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: IfxSerialAutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class IfxSerialAutoIncrementModule implements AutoIncrementModule, ThreadSafe {
  
      public Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                  Connection conn, Statement stmt, Request request )
          throws SQLException, ConfigurationException {
  
          return new Integer(((com.informix.jdbc.IfxStatement) stmt).getSerial());
      };
  
  
      public boolean includeInQuery() { return false; };
  
  
      public boolean includeAsValue() { return false; };
  
  
      public Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                 Connection conn, Request request ) throws SQLException, ConfigurationException {
  
          return null;
      };
  
      public String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf )
          throws ConfigurationException {
  
          return null;
      };
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/ManualAutoIncrementModule.java
  
  Index: ManualAutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import java.sql.Connection;
  import java.sql.Statement;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import java.lang.Integer;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.SortedSet;
  
  /**
   * Abstraction layer to encapsulate different DBMS behaviour for
   * autoincrement columns.
   *
   * Here: manual mode The new value is determined by doing a "select
   * max(column)+1 from table" query. With transactions and correct
   * isolation levels, this should to the trick almost everywhere.
   *
   * Note however, that the above query does not prevent a parallel
   * transaction to try to insert a row with the same ID since it
   * requires only shared locks. C.f. "Phantom Problem"
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: ManualAutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class ManualAutoIncrementModule extends AbstractAutoIncrementModule implements ThreadSafe {
  
      private Map selectStatements = new HashMap();
  
  
      public Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modenConf,
                                  Connection conn, Statement stmt, Request request )
          throws SQLException, ConfigurationException {
  
          return null;
      }
  
      public boolean includeInQuery( ) { return true; }
  
  
      public boolean includeAsValue( ) { return true; }
  
  
      public Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                 Connection conn, Request request )
          throws SQLException, ConfigurationException {
  
          /** Set the key value using SELECT MAX(keyname)+1 **/
          String tableName = tableConf.getAttribute("name","");
          String selectQuery = this.getSelectQuery(tableName, columnConf);
          PreparedStatement select_statement = conn.prepareStatement(selectQuery);
          ResultSet set = select_statement.executeQuery();
          set.next();
          int maxid = set.getInt("maxid");
          set.close();
          select_statement.close();
          if (getLogger().isDebugEnabled())
              getLogger().debug("autoincrementValue " + (maxid+1));
          return new Integer(maxid + 1);
      }
  
  
      public String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf )
          throws ConfigurationException {
  
          return null;
      }
  
  
      /**
       * Set the String representation of the MaxID lookup statement.  This is
       * mapped to the Configuration object itself, so if it doesn't exist,
       * it will be created.
       */
      protected final synchronized void setSelectQuery( String tableName, Configuration entry ) throws ConfigurationException {
  
          StringBuffer queryBuffer = new StringBuffer("SELECT max(");
          queryBuffer.append(entry.getAttribute("name"));
          queryBuffer.append(") AS maxid FROM ");
          queryBuffer.append(tableName);
  
          this.selectStatements.put(entry, queryBuffer.toString());
      }
  
  
      protected final synchronized String getSelectQuery( String tableName, Configuration entry ) throws ConfigurationException {
  
          String result = (String) this.selectStatements.get(entry);
          if (result == null) {
              setSelectQuery(tableName, entry);
              result = (String) this.selectStatements.get(entry);
          }
          return result;
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/modules/database/MysqlAutoIncrementModule.java
  
  Index: MysqlAutoIncrementModule.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.modules.database;
  
  import java.lang.Integer;
  import java.sql.PreparedStatement;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.sql.SQLException;
  import org.apache.cocoon.environment.Request;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
   *
   * Here: MYSQL AUTO_INCREMENT columns
   * {@link http://www.mysql.com}
   *
   * @author <a href="mailto:phantom@stserv.hcf.jhu.edu">Tim Myers</a>
   * @version CVS $Id: MysqlAutoIncrementModule.java,v 1.1 2002/03/15 15:15:08 haul Exp $
   */
  public class MysqlAutoIncrementModule implements AutoIncrementModule, ThreadSafe {
  
      public Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                  Connection conn, Statement stmt, Request request )  throws SQLException, ConfigurationException {
  
          Integer id = null;
          /*
            // if mysql did support callable statements ...  i'm not sure what what would go here, maybe:
  
            CallableStatement callStmt = conn.prepareCall("? = {CALL LAST_INSERT_ID()}");
            callStmt.registerOutParameter(1, Types.INTEGER);
            ResultSet resultSet = callStmt.executeQuery();
          */
  
          PreparedStatement pstmt = conn.prepareStatement("SELECT LAST_INSERT_ID()");
          ResultSet resultSet = pstmt.executeQuery();
          while ( resultSet.next() ) {
              id = new Integer(resultSet.getInt(1));
          }
          resultSet.close();
  
          return id;
      }
  
  
      public boolean includeInQuery() { return false; }
  
  
      public boolean includeAsValue() { return false; }
  
  
      public Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
                                 Connection conn, Request request ) throws SQLException, ConfigurationException {
  
          return null;
      }
  
  
      public String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf )
          throws ConfigurationException {
  
          return null;
      }
  }
  
  
  
  

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