cziegeler    2002/12/18 13:51:07

  Modified:    src/java/org/apache/cocoon/acting ServerPagesAction.java
  Added:       src/java/org/apache/cocoon/sitemap/properties
                        PropertyContainer.java PropertyContainerChain.java
                        InputModulePropertyContainer.java
  Log:
  This is a proposal for the "new" input modules.
  I called some property container - a component containing/delivering properties that 
can be used in the sitemap.
  Actually, the interface is very simple - it has only one method.
  Chaining of property containers can be done by using a special implementation that 
is configurable.
  Please, this is only a proposal - love it or discuss it.
  
  Revision  Changes    Path
  1.11      +2 -8      
xml-cocoon2/src/java/org/apache/cocoon/acting/ServerPagesAction.java
  
  Index: ServerPagesAction.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ServerPagesAction.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ServerPagesAction.java    5 Dec 2002 09:23:33 -0000       1.10
  +++ ServerPagesAction.java    18 Dec 2002 21:51:07 -0000      1.11
  @@ -108,14 +108,12 @@
    */
   public class ServerPagesAction
           extends ConfigurableComposerAction
  -        implements Disposable, ThreadSafe, LogKitManageable {
  +        implements Disposable, ThreadSafe {
   
       public static final String REDIRECTOR_OBJECT = "xsp-action:redirector";
       public static final String ACTION_RESULT_OBJECT = "xsp-action:result";
       public static final String ACTION_SUCCESS_OBJECT = "xsp-action:success";
   
  -    private LogKitManager logKitManager;
  -
       ComponentHandler generatorHandler;
   
       public void configure(Configuration conf)
  @@ -136,10 +134,6 @@
           } catch(Exception e) {
               throw new ConfigurationException("Cannot set up component handler", e);
           }
  -    }
  -
  -    public void setLogKitManager(LogKitManager logKitManager) {
  -        this.logKitManager = logKitManager;
       }
   
       public void dispose() {
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/sitemap/properties/PropertyContainer.java
  
  Index: PropertyContainer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.sitemap.properties;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.component.Component;
  
  /**
   * Properties can be used in the sitemap for value substitution. A 
   * property container is a component that can deliver several properties.
   * The property containers are configured in the sitemap:
   * <property-containers>
   *    <property-container name="request-param"
   *                        src="org.a.c.sitemap.properties.RequestParamPC"/>
   *    <property-container name="value-chain"
   *                        src="o.a.c.sitemap.properties.PropertyContainerChain">
   *       <property-container>session</property-container>
   *       <property-container>request</property-container>
   *       <property-container>global</property-container>
   *    </property-container>
   * </property-containers>
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: $
   */
  public interface PropertyContainer extends Component {
  
      String ROLE = PropertyContainer.class.getName();
  
  
      /**
       * Get the value of a property by name. If the value does not exist,
       * null is returned.
       */
      String getProperty( String name, Map objectModel );
  
  }
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/sitemap/properties/PropertyContainerChain.java
  
  Index: PropertyContainerChain.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.sitemap.properties;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * This implementation invokes a chain of {@link PropertyContainer}
   * components.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: $
   */
  public class PropertyContainerChain
        extends AbstractLogEnabled
        implements PropertyContainer, Composable, Configurable, ThreadSafe {
  
      private ComponentManager manager;
  
        private String[] containerNames;
      
        /**
         * @see 
org.apache.cocoon.sitemap.properties.PropertyContainer#getProperty(String, Map)
         */
        public String getProperty(String name, Map objectModel) {
                String value = null;
                int i = 0;
                
                while (value != null && i < this.containerNames.length) {
                        final String role = this.containerNames[i];
                        ComponentSelector selector = null;
                        PropertyContainer container = null;
                        try {
                                selector = (ComponentSelector)this.manager.lookup( 
PropertyContainer.ROLE + "Selector" );
                                container = (PropertyContainer) selector.select( role 
);
                                value = container.getProperty( name, objectModel );
                        } catch (ComponentException ce) {
                                this.getLogger().warn("Unable to lookup property 
container: " + role);
                        } finally {
                                if ( null != selector ) selector.release( container );
                                this.manager.release( selector );
                        }
                        i++;
                }
                return value;
        }
  
        /**
         * @see 
org.apache.avalon.framework.component.Composable#compose(ComponentManager)
         */
        public void compose(ComponentManager manager) throws ComponentException {
                this.manager = manager;
        }
  
        /**
         * @see 
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
         */
        public void configure(Configuration configuration) throws 
ConfigurationException {
          Configuration[] container = configuration.getChildren("container");
          if (container != null) {
                this.containerNames = new String[container.length];
                for(int i = 0; i < container.length; i++) {
                        this.containerNames[i] = container[i].getValue();
                }
          } else {
                // avoid null pointer test later on
                this.containerNames = new String[0];
          }
        }
  
  }
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/sitemap/properties/InputModulePropertyContainer.java
  
  Index: InputModulePropertyContainer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.sitemap.properties;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.components.modules.input.InputModule;
  
  /**
   * This implementation invokes an {@link InputModule} and can be
   * used for upgrading.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: $
   */
  public class InputModulePropertyContainer
        extends AbstractLogEnabled
        implements PropertyContainer, Composable, Parameterizable, ThreadSafe {
  
      private ComponentManager manager;
  
      private String inputModuleName;
          
        /**
         * @see 
org.apache.cocoon.sitemap.properties.PropertyContainer#getProperty(String, Map)
         */
        public String getProperty(String name, Map objectModel) {
                Object value = null;
        ComponentSelector selector = null;
            InputModule module = null;
                try {
                    selector = (ComponentSelector)this.manager.lookup( 
InputModule.ROLE + "Selector" );
                        module = (InputModule) selector.select( this.inputModuleName );
                        value = module.getAttribute( name, null, objectModel );
                } catch (ConfigurationException ce) {
                        this.getLogger().warn("Unable to lookup input module: " + 
this.inputModuleName);
                } catch (ComponentException ce) {
                        this.getLogger().warn("Unable to lookup input module: " + 
this.inputModuleName);
                } finally {
                        if ( null != selector ) selector.release( module );
                        this.manager.release( selector );
                }
                return (value == null ? null : value.toString());
        }
        
        /**
         * @see 
org.apache.avalon.framework.component.Composable#compose(ComponentManager)
         */
        public void compose(ComponentManager manager) throws ComponentException {
                this.manager = manager;
        }
  
        /**
         * @see 
org.apache.avalon.framework.parameters.Parameterizable#parameterize(Parameters)
         */
        public void parameterize(Parameters par) throws ParameterException {
                this.inputModuleName = par.getParameter("input-module");
        }
  
  }
  
  
  

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

Reply via email to