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/08/09 10:32:11 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/modules/input MapMetaModule.java XMLMetaModule.java DefaultsMetaModule.java DigestMetaModule.java

haul        2002/08/09 01:32:11

  Modified:    src/java/org/apache/cocoon/components/modules modules.xconf
               src/java/org/apache/cocoon/components/modules/output
                        RequestAttributeOutputModule.java
                        SessionAttributeOutputModule.java
               src/java/org/apache/cocoon/components/modules/input
                        DefaultsMetaModule.java DigestMetaModule.java
  Added:       src/java/org/apache/cocoon/components/modules/input
                        MapMetaModule.java XMLMetaModule.java
  Log:
    <action dev="CH" type="add">
     Added some more InputModules.
    </action>
  
  Revision  Changes    Path
  1.5       +23 -21    xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf
  
  Index: modules.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- modules.xconf	31 May 2002 07:41:50 -0000	1.4
  +++ modules.xconf	9 Aug 2002 08:32:10 -0000	1.5
  @@ -3,19 +3,21 @@
   <xconf xpath="/cocoon" unless="input-modules">
      <!-- =============== Sitemap In/Out/Database Modules ==================== -->
      
  -   <input-modules logger="core.modules.input">
  -	  <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"/>
  -	  <component-instance name="constant"  	class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
  -	  <component-instance name="random"    	class="org.apache.cocoon.components.modules.input.RandomNumberModule"/>
  -      <component-instance name="collection" class="org.apache.cocoon.components.modules.input.CollectionMetaModule"/>
  -      <component-instance name="digest"     class="org.apache.cocoon.components.modules.input.DigestMetaModule"/>
  -      <component-instance name="date"       class="org.apache.cocoon.components.modules.input.DateInputModule"/>
  -      <component-instance name="nullinput"  class="org.apache.cocoon.components.modules.input.NullInputModule"/>
  -      <component-instance name="defaults"   class="org.apache.cocoon.components.modules.input.DefaultsMetaModule">
  +   <input-modules>
  +	  <component-instance logger="core.modules.input" name="request"   	class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
  +	  <component-instance logger="core.modules.input" name="attribute" 	class="org.apache.cocoon.components.modules.input.RequestAttributeModule"/>
  +	  <component-instance logger="core.modules.input" name="URI"       	class="org.apache.cocoon.components.modules.input.RequestURIModule"/>
  +	  <component-instance logger="core.modules.input" name="header"    	class="org.apache.cocoon.components.modules.input.HeaderAttributeModule"/>
  +	  <component-instance logger="core.modules.input" name="session"   	class="org.apache.cocoon.components.modules.input.SessionAttributeModule"/>
  +	  <component-instance logger="core.modules.input" name="constant"  	class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
  +	  <component-instance logger="core.modules.input" name="random"    	class="org.apache.cocoon.components.modules.input.RandomNumberModule"/>
  +      <component-instance logger="core.modules.input" name="digest"     class="org.apache.cocoon.components.modules.input.DigestMetaModule"/>
  +      <component-instance logger="core.modules.input" name="date"       class="org.apache.cocoon.components.modules.input.DateInputModule"/>
  +      <component-instance logger="core.modules.input" name="nullinput"  class="org.apache.cocoon.components.modules.input.NullInputModule"/>
  +      <component-instance logger="core.modules.input" name="collection" class="org.apache.cocoon.components.modules.input.CollectionMetaModule"/>
  +      <component-instance logger="core.modules.input" name="xmlmeta"    class="org.apache.cocoon.components.modules.input.XMLMetaModule"/>
  +      <component-instance logger="core.modules.input" name="mapmeta"    class="org.apache.cocoon.components.modules.input.MapMetaModule"/>
  +      <component-instance logger="core.modules.input" name="defaults"   class="org.apache.cocoon.components.modules.input.DefaultsMetaModule">
   		 <input-module name="request"/>
   		 <values>
   			<skin>defaultSkin</skin>
  @@ -24,22 +26,22 @@
   	  </component-instance>
      </input-modules>
   
  -   <output-modules logger="core.modules.output">
  -      <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>
  +      <component-instance logger="core.modules.output" name="attribute" class="org.apache.cocoon.components.modules.output.RequestAttributeOutputModule"/>
  +      <component-instance logger="core.modules.output" name="session"   class="org.apache.cocoon.components.modules.output.SessionAttributeOutputModule"/>
      </output-modules>
   
  -   <autoincrement-modules logger="core.modules.auto">
  -      <component-instance name="auto" class="org.apache.cocoon.components.modules.database.HsqlIdentityAutoIncrementModule"/>
  +   <autoincrement-modules>
  +      <component-instance logger="core.modules.auto" 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"/>
  +      <component-instance logger="core.modules.auto" name="auto" class="org.apache.cocoon.components.modules.database.ManualAutoIncrementModule"/>
  +      <component-instance logger="core.modules.auto" name="auto" class="org.apache.cocoon.components.modules.database.IfxSerialAutoIncrementModule"/>
  +      <component-instance logger="core.modules.auto" name="auto" class="org.apache.cocoon.components.modules.database.MysqlAutoIncrementModule"/>
   -->
      </autoincrement-modules>
   </xconf>
  
  
  
  1.4       +13 -9     xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeOutputModule.java
  
  Index: RequestAttributeOutputModule.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeOutputModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RequestAttributeOutputModule.java	31 Jul 2002 13:13:24 -0000	1.3
  +++ RequestAttributeOutputModule.java	9 Aug 2002 08:32:10 -0000	1.4
  @@ -79,10 +79,12 @@
        * */
       public void setAttribute( Configuration modeConf, Map objectModel, String name, Object value ) {
   
  -        ObjectModelHelper.getRequest(objectModel)
  -            .setAttribute( ( (String) this.settings.get("key-prefix",
  -                                                        "org.apache.cocoon.components.modules.output.OutputModule" ) )
  -                           + ":" + name, value);
  +        String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" );
  +        if (prefix != "") {
  +            ObjectModelHelper.getRequest(objectModel).setAttribute(prefix+":"+name, value);
  +        } else {
  +            ObjectModelHelper.getRequest(objectModel).setAttribute(name, value);
  +        }
       }
   
   
  @@ -105,10 +107,12 @@
                 }
             }
           */
  -        ObjectModelHelper.getRequest(objectModel)
  -            .setAttribute( ( (String) this.settings.get("key-prefix",
  -                                                        "org.apache.cocoon.components.modules.output.OutputModule" ) ) + ":",
  -                           e.getMessage());
  +        String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" );
  +        if (prefix!="") {
  +            ObjectModelHelper.getRequest(objectModel).setAttribute(prefix+":",e.getMessage());
  +        } else {
  +            ObjectModelHelper.getRequest(objectModel).setAttribute("errorMessage",e.getMessage());
  +        }
       }
   
   
  
  
  
  1.4       +23 -12    xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/SessionAttributeOutputModule.java
  
  Index: SessionAttributeOutputModule.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/SessionAttributeOutputModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionAttributeOutputModule.java	31 Jul 2002 13:13:24 -0000	1.3
  +++ SessionAttributeOutputModule.java	9 Aug 2002 08:32:10 -0000	1.4
  @@ -54,6 +54,7 @@
   import java.util.Enumeration;
   import java.util.Map;
   import org.apache.cocoon.environment.Request;
  +import org.apache.cocoon.environment.Session;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.avalon.framework.configuration.Configuration;
   
  @@ -79,11 +80,15 @@
        * */
       public void setAttribute( Configuration modeConf, Map objectModel, String name, Object value ) {
   
  -        ObjectModelHelper.getRequest(objectModel)
  -            .getSession()
  -            .setAttribute(((String) this.settings.get("key-prefix",
  -                                                      "org.apache.cocoon.components.modules.output.OutputModule"))
  -                          + ":" + name, value);
  +        String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" );
  +        Request req = ObjectModelHelper.getRequest(objectModel);
  +        Session ses = req.getSession();
  +        if (ses == null || !req.isRequestedSessionIdValid()) ses = req.getSession(true);
  +        if (prefix!="") {
  +            ses.setAttribute(prefix + ":" + name, value);
  +        } else {
  +            ses.setAttribute(name, value);
  +        }
       }
   
   
  @@ -100,17 +105,23 @@
   
           Request request = ObjectModelHelper.getRequest(objectModel);
           Enumeration attributes = request.getSession().getAttributeNames();
  +        String prefix = (String) this.settings.get("key-prefix",
  +                                                   "org.apache.cocoon.components.modules.output.OutputModule");
           while ( attributes.hasMoreElements() ) {
               String name = (String) attributes.nextElement();
  -            if ( name.startsWith("org.apache.cocoon.acting.ModularDatabaseAccess.OutputModule:") ) {
  +            if ( name.startsWith(prefix) ) {
                   request.getSession().removeAttribute(name);
               }
           }
  -        request
  -            .getSession()
  -            .setAttribute(((String) this.settings.get("key-prefix",
  -                                                      "org.apache.cocoon.components.modules.output.OutputModule")) 
  -                          + ":", e.getMessage());
  +        if (prefix!="") {
  +            request
  +                .getSession()
  +                .setAttribute(prefix + ":", e.getMessage());
  +        } else {
  +            request
  +                .getSession()
  +                .setAttribute("errorMessage", e.getMessage());
  +        }
       }
   
   
  
  
  
  1.3       +7 -6      xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DefaultsMetaModule.java
  
  Index: DefaultsMetaModule.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DefaultsMetaModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultsMetaModule.java	31 Jul 2002 13:13:24 -0000	1.2
  +++ DefaultsMetaModule.java	9 Aug 2002 08:32:11 -0000	1.3
  @@ -107,7 +107,6 @@
       private Map constants = null;
   
   
  -
       /**
        * Set the current <code>ComponentManager</code> instance used by this
        * <code>Composable</code>.
  @@ -196,12 +195,14 @@
   
           // obtain correct configuration objects
           // default vs dynamic
  +        Configuration inputConfig = this.inputConf;
           Configuration mConf = null;
  -        Configuration inputConfig = null;
           String inputName=null;
  +        String parameter=name;
           if (modeConf!=null) {
               mConf       = modeConf.getChild("values");
               inputName   = modeConf.getChild("input-module").getAttribute("name",null);
  +            parameter   = modeConf.getAttribute("parameter",parameter);
               if (inputName != null) {
                   inputConfig = modeConf.getChild("input-module");
               }
  @@ -217,7 +218,7 @@
                       // thus we still have a reference to it
                       // and
                       // no other module is configured dynamically
  -                    values = input.getAttributeValues(name,this.inputConf,objectModel);
  +                    values = input.getAttributeValues(parameter,this.inputConf,objectModel);
                   } else {
                       // input was not thread safe
                       // or
  @@ -240,7 +241,7 @@
                               iput = (InputModule) iputSelector.select(inputName);
                           }
                           if (iput != null) {
  -                            values = iput.getAttributeValues(name, inputConfig, objectModel);
  +                            values = iput.getAttributeValues(parameter, inputConfig, objectModel);
                           }           
                       } catch (Exception e) {
                           if (getLogger().isWarnEnabled()) 
  @@ -263,7 +264,7 @@
   
               if (values == null) {
                   values = new Object[1];
  -                values[0] = (mConf!=null?mConf.getChild(name).getValue((String) this.constants.get(name)) : this.constants.get(name));
  +                values[0] = (mConf!=null?mConf.getChild(parameter).getValue((String) this.constants.get(parameter)) : this.constants.get(parameter));
               }
               return values;
           } catch (Exception e) {
  
  
  
  1.4       +1 -7      xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
  
  Index: DigestMetaModule.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DigestMetaModule.java	31 Jul 2002 13:13:24 -0000	1.3
  +++ DigestMetaModule.java	9 Aug 2002 08:32:11 -0000	1.4
  @@ -48,12 +48,6 @@
    Software Foundation, please see <http://www.apache.org/>.
   
   */
  -/*
  -  <mode name="CollectionMeta">
  -     <member name="foo_*" type="int"/>
  -  </mode>
  -
  - */
   package org.apache.cocoon.components.modules.input;
   
   
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/MapMetaModule.java
  
  Index: MapMetaModule.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.activity.Initializable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.modules.input.InputModule;
  
  import org.apache.cocoon.matching.AbstractWildcardMatcher;
  
  import java.net.URLEncoder;
  
  import java.util.Map;
  import java.util.Enumeration;
  
  /** 
   * Meta module that obtains an Object from another module, assumes
   * that this Object implements the java.util.Map interface, and gives
   * access to the map contents. Possible use is to propagate data from
   * flow through request attributes to database actions.
   *
   * <p>Configuration: "input-module", "object", "parameter"</p>
   *
   * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
   * @version CVS $Id: MapMetaModule.java,v 1.1 2002/08/09 08:32:11 haul Exp $
   */
  public class MapMetaModule extends AbstractLoggable
      implements InputModule, Configurable, Initializable, Composable, Disposable {
  
      /** The component manager instance */
      protected ComponentManager manager;
  
      protected String defaultInput = "attribute"; // default to request attributes
      protected Configuration inputConf = null;  // will become an empty configuration object
                                               // during configure() so why bother here...
      protected String INPUT_MODULE_ROLE = InputModule.ROLE;
      protected String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
  
      private boolean initialized = false;
      protected InputModule input = null;
      protected ComponentSelector inputSelector = null;
  
      protected String objectName = null;
      protected String parameter = null;
  
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager) throws ComponentException {
  
          this.manager=manager;
      }
  
  
      
      public void configure(Configuration config) throws ConfigurationException {
  
          this.inputConf = config.getChild("input-module");
          this.objectName = this.inputConf.getAttribute("object",this.objectName);
          this.parameter = this.inputConf.getAttribute("parameter",this.parameter);
      }
  
  
      public void initialize() {
  
          try {
              // obtain input module
              this.inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
              if (this.defaultInput != null && 
                  this.inputSelector != null && 
                  this.inputSelector.hasComponent(this.defaultInput)
                  ){
                  this.input = (InputModule) this.inputSelector.select(this.defaultInput);
                  if (!(this.input instanceof ThreadSafe && this.inputSelector instanceof ThreadSafe) ) {
                      this.inputSelector.release(this.input);
                      this.manager.release(this.inputSelector);
                      this.input = null;
                      this.inputSelector = null;
                  }
                  this.initialized = true;
              } else {
                  if (getLogger().isErrorEnabled())
                      getLogger().error("A problem occurred setting up '" + this.defaultInput 
                                        + "': Selector is "+(this.inputSelector!=null?"not ":"")
                                        +"null, Component is "
                                        +(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
              }
          } catch (Exception e) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("A problem occurred setting up '" + this.defaultInput + "': " + e.getMessage());
          }
      }
  
  
  
      public void dispose() {
  
          if (!this.initialized) 
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
          else 
              if (this.inputSelector != null) {
                  if (this.input != null)
                      this.inputSelector.release(this.input);
                  this.manager.release(this.inputSelector);
              }
      }
  
  
      
  
      public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
          if (!this.initialized) {
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
              return null;
          }
          if (this.defaultInput == null) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("No input module given. FAILING");
              return null;
          }
  
          // obtain correct configuration objects
          // default vs dynamic
          Configuration inputConfig = this.inputConf;
          String inputName=null;
          String objectName = this.objectName;
          String parameter = this.parameter;
          if (modeConf!=null) {
              inputName  = modeConf.getChild("input-module").getAttribute("name",null);
              objectName = modeConf.getAttribute("object",objectName);
              parameter  = modeConf.getAttribute("parameter",parameter);
              if (inputName != null) {
                  inputConfig = modeConf.getChild("input-module");
              }
          }
          parameter = (parameter != null? parameter : name);
  
          // done reading configuration
          // setup modules and read values
          InputModule iput = this.input;
          ComponentSelector iputSelector = null;
          StringBuffer sb = new StringBuffer();
          Object value = null;
          try {
              if (this.input != null && inputName == null) {
                  // thread safe input module
                  // use existing reference
                  iput = this.input;
              } else {
                  // input was not thread safe
                  // or
                  // another module is configured dynamically
                  // so acquire it again
                  iputSelector = null;
                  iput = null;
  
                  // obtain input module
                  if (inputName == null) {
                      inputName   = this.defaultInput;
                      inputConfig = this.inputConf;
                  }
                  
                  iputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
                  if (this.defaultInput != null 
                      && iputSelector != null 
                      && iputSelector.hasComponent(inputName)) {
                      
                      iput = (InputModule) iputSelector.select(inputName);
                  }
              }
              if (iput != null) {
                  value = iput.getAttribute(objectName, inputConfig, objectModel);
                  value = (value!=null? ((Map) value).get(parameter) : null);
              }           
              
          } catch (Exception e) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("A problem occurred acquiring a value from '" + inputName 
                                   + "' for '"+name+"': " + e.getMessage());
          } finally {
              // release components
              if (iputSelector != null) {
                  if (iput != null)
                      iputSelector.release(iput);
                  this.manager.release(iputSelector);
              }
          }
          return value;        
      }
  
  
  
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
           if (!this.initialized) {
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
              return null;
          }
          if (this.defaultInput == null) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("No input module given. FAILING");
              return null;
          }
  
          // obtain correct configuration objects
          // default vs dynamic
          Configuration inputConfig = null;
          String inputName=null;
          String objectName = this.objectName;
          if (modeConf!=null) {
              inputName   = modeConf.getChild("input-module").getAttribute("name",null);
              objectName = modeConf.getAttribute("object",this.objectName);
              if (inputName != null) {
                  inputConfig = modeConf.getChild("input-module");
              }
          }
  
          // done reading configuration
          // setup modules and read values
          InputModule iput = this.input;
          ComponentSelector iputSelector = null;
          StringBuffer sb = new StringBuffer();
          Enumeration keys = null;
          try {
              if (this.input != null && inputName == null) {
                  // thread safe input module
                  // use existing reference
                  iput = this.input;
              } else {
                  // input was not thread safe
                  // or
                  // another module is configured dynamically
                  // so acquire it again
                  iputSelector = null;
                  iput = null;
  
                  // obtain input module
                  if (inputName == null) {
                      inputName   = this.defaultInput;
                      inputConfig = this.inputConf;
                  }
                  
                  iputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
                  if (this.defaultInput != null 
                      && iputSelector != null 
                      && iputSelector.hasComponent(inputName)) {
                      
                      iput = (InputModule) iputSelector.select(inputName);
                  }
              }
              if (iput != null) {
                  keys = new EnumerationHelper(((Map) iput.getAttribute(objectName, inputConfig, objectModel)).keySet().iterator());
              }           
              
          } catch (Exception e) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("A problem occurred acquiring a names from '" + inputName 
                                   + "' " + e.getMessage());
          } finally {
              // release components
              if (iputSelector != null) {
                  if (iput != null)
                      iputSelector.release(iput);
                  this.manager.release(iputSelector);
              }
          }
          return keys;        
     }
  
  
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
          Object[] values = new Object[1];
          values[0] = this.getAttribute(name, modeConf, objectModel);
          return (values[0]!=null?values:null);
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLMetaModule.java
  
  Index: XMLMetaModule.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.activity.Initializable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.modules.input.InputModule;
  
  import org.apache.cocoon.matching.AbstractWildcardMatcher;
  
  import java.net.URLEncoder;
  
  import java.util.Map;
  import java.util.Enumeration;
  import java.util.StringTokenizer;
  
  /** 
   * Meta module that obtains values from other module and returns all
   * parameters as XML.
   * 
   * <p>Config</p>
   * <pre>
   *   &lt;!-- in cocoon.xconf --&gt;
   *   &lt;input-module name="request" ignore="do-" strip="user."/&gt;
   *
   *   &lt;!-- e.g. in database.xml --&gt;
   *   &lt;mode type="all" name="xmlmeta" ignore="foo." use="foo" strip="f" root="my-root"/&gt;
   * </pre>
   *
   * <p>If present, "ignore" gives a prefix of parameters to ignore,
   * ignore has precedence over the "use" attribute, "strip" a prefix
   * that will be removed from the final parameter names in the produced
   * XML, "use" is a prefix for parameters to include in the XML, and
   * "root" is the name of the root element in the created XML.</p>
   *
   * <p>Input</p>
   * <pre>
   *    foo.one = ['abc']
   *    foo.two = ['def']
   *    foo1 = ['bar']
   *    foo2 = ['one','two','three']
   *    bar = ['rubber duck']
   * </pre>
   *
   * <p>Output</p>
   * <pre> 
   *   &lt;my-root&gt;
   *     &lt;item name="oo1"&gt;bar&lt;/item&gt;
   *     &lt;item name="oo2"&gt;
   *        &lt;value&gt;one&lt;/value&gt;
   *        &lt;value&gt;two&lt;/value&gt;
   *        &lt;value&gt;three&lt;/value&gt;
   *     &lt;/item&gt;
   *   &lt;/my-root&gt;
   * </pre>
   *
   * <p>Should produce Objects that are XMLizable and Document one
   * day. Currently, produces only Strings.</p>
   *
   * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
   * @version CVS $Id: XMLMetaModule.java,v 1.1 2002/08/09 08:32:11 haul Exp $
   */
  public class XMLMetaModule extends AbstractLoggable
      implements InputModule, Configurable, Initializable, Composable, Disposable {
  
      /** The component manager instance */
      protected ComponentManager manager;
  
      protected String defaultInput = "request"; // default to request parameters
      protected Configuration inputConf = null;  // will become an empty configuration object
                                               // during configure() so why bother here...
      protected String INPUT_MODULE_ROLE = InputModule.ROLE;
      protected String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
  
      private boolean initialized = false;
      protected InputModule input = null;
      protected ComponentSelector inputSelector = null;
  
      protected String rootName = "root";
      protected String ignore = null;
      protected String use = null;
      protected String strip = null;
  
      final static Enumeration returnNames = new StringTokenizer("XML");
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager) throws ComponentException {
  
          this.manager=manager;
      }
  
  
      
      public void configure(Configuration config) throws ConfigurationException {
  
          this.inputConf = config.getChild("input-module");
          this.rootName = this.inputConf.getAttribute("root",this.rootName);
          this.ignore = this.inputConf.getAttribute("ignore",this.ignore);
          this.use = this.inputConf.getAttribute("use",this.use);
          this.strip = this.inputConf.getAttribute("strip",this.strip);
      }
  
  
      public void initialize() {
  
          try {
              // obtain input module
              this.inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
              if (this.defaultInput != null && 
                  this.inputSelector != null && 
                  this.inputSelector.hasComponent(this.defaultInput)
                  ){
                  this.input = (InputModule) this.inputSelector.select(this.defaultInput);
                  if (!(this.input instanceof ThreadSafe && this.inputSelector instanceof ThreadSafe) ) {
                      this.inputSelector.release(this.input);
                      this.manager.release(this.inputSelector);
                      this.input = null;
                      this.inputSelector = null;
                  }
                  this.initialized = true;
              } else {
                  if (getLogger().isErrorEnabled())
                      getLogger().error("A problem occurred setting up '" + this.defaultInput 
                                        + "': Selector is "+(this.inputSelector!=null?"not ":"")
                                        +"null, Component is "
                                        +(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
              }
          } catch (Exception e) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("A problem occurred setting up '" + this.defaultInput + "': " + e.getMessage());
          }
      }
  
  
  
      public void dispose() {
  
          if (!this.initialized) 
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
          else 
              if (this.inputSelector != null) {
                  if (this.input != null)
                      this.inputSelector.release(this.input);
                  this.manager.release(this.inputSelector);
              }
      }
  
  
      
  
      public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
          if (!this.initialized) {
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
              return null;
          }
          if (this.defaultInput == null) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("No input module given. FAILING");
              return null;
          }
  
          // obtain correct configuration objects
          // default vs dynamic
          Configuration inputConfig = null;
          String inputName=null;
          String rootName = this.rootName;
          String ignore  = this.ignore;
          String use  = this.use;
          String strip  = this.strip;
          if (modeConf!=null) {
              inputName   = modeConf.getChild("input-module").getAttribute("name",null);
              rootName = modeConf.getAttribute("root",this.rootName);
              ignore  = modeConf.getAttribute("ignore" ,this.ignore );
              use  = modeConf.getAttribute("use" ,this.use );
              strip  = modeConf.getAttribute("strip" ,this.strip );
              if (inputName != null) {
                  inputConfig = modeConf.getChild("input-module");
              }
          }
  
          // done reading configuration
          // setup modules and read values
          InputModule iput = this.input;
          ComponentSelector iputSelector = null;
          StringBuffer sb = new StringBuffer();
          sb.append('<').append(rootName).append('>');
          try {
              if (this.input != null && inputName == null) {
                  // thread safe input module
                  // use existing reference
                  iput = this.input;
              } else {
                  // input was not thread safe
                  // or
                  // another module is configured dynamically
                  // so acquire it again
                  iputSelector = null;
                  iput = null;
  
                  // obtain input module
                  if (inputName == null) {
                      inputName   = this.defaultInput;
                      inputConfig = this.inputConf;
                  }
                  
                  iputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
                  if (this.defaultInput != null 
                      && iputSelector != null 
                      && iputSelector.hasComponent(inputName)) {
                      
                      iput = (InputModule) iputSelector.select(inputName);
                  }
              }
              if (iput != null) {
                  Enumeration names = iput.getAttributeNames(inputConfig, objectModel);
                  while (names.hasMoreElements()){
                      String attribute = (String) names.nextElement();
                      if ((use == null || attribute.startsWith(use)) &&
                          (ignore == null || !attribute.startsWith(ignore))) {
                          Object[] values = iput.getAttributeValues(attribute, inputConfig, objectModel);
                          if (strip != null && attribute.startsWith(strip)) 
                              attribute = attribute.substring(strip.length());
                          sb.append("<item name=\"").append(attribute).append("\">");
                          if (values.length == 1) {
                              sb.append(values[0]);
                          } else {
                              for (int i=0;i<values.length;i++){
                                  sb.append("<value>").append(values[i]).append("</value>");
                              }
                          }
                          sb.append("</item>");
                      }
                  }
              }           
              
          } catch (Exception e) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("A problem occurred acquiring a value from '" + inputName 
                                   + "' for '"+name+"': " + e.getMessage());
          } finally {
              // release components
              if (iputSelector != null) {
                  if (iput != null)
                      iputSelector.release(iput);
                  this.manager.release(iputSelector);
              }
          }
          sb.append('<').append('/').append(rootName).append('>');
          return sb.toString();        
      }
  
  
  
  
  
      public Enumeration getAttributeNames( Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
           if (!this.initialized) {
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
              return null;
          }
          if (this.defaultInput == null) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("No input module given. FAILING");
              return null;
          }
  
          return XMLMetaModule.returnNames;
     }
  
  
  
  
      public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 
          throws ConfigurationException {
  
          if (!this.initialized) {
              if (getLogger().isErrorEnabled()) 
                  getLogger().error("Uninitialized Component! FAILING");
              return null;
          }
          if (this.defaultInput == null) {
              if (getLogger().isWarnEnabled()) 
                  getLogger().warn("No input module given. FAILING");
              return null;
          }
          
          Object[] values = new Object[1];
          values[0] = this.getAttribute(name, modeConf, objectModel);
          return values;
      }
  
  }
  
  
  

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