cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [19/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NamingInputModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NamingInputModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NamingInputModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NamingInputModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,141 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * NamingInputModule accesses values stored in the JNDI context.
+ *
+ * <p>This module accept any configuration parameters and passes them as
+ * properties to the InitialContext. When connecting to the Naming context
+ * of the server Cocoon is running in, no parameters are required.</p>
+ *
+ * <p>Example module configuration when connecting to external WebLogic server:
+ * <pre>
+ *   &lt;java.naming.factory.initial&gt;weblogic.jndi.WLInitialContextFactory&lt;/java.naming.factory.initial&gt;
+ *   &lt;java.naming.provider.url&gt;t3://localhost:7001&lt;/java.naming.provider.url&gt;
+ * </pre>
+ *
+ * <p>Example usage:
+ * <pre>
+ *   &lt;map:generate src="{naming:java:comp/env/greeting}"/&gt;
+ * </pre>
+ * This lookups <code>greeting</code> entry from the environment of the webapp.
+ * Webapp's web.xml should define this entry:
+ * <pre>
+ *   &lt;env-entry&gt;
+ *     &lt;env-entry-name&gt;greeting&lt;/env-entry-name&gt;
+ *     &lt;env-entry-value&gt;Hello, World&lt;/env-entry-value&gt;
+ *     &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
+ *   &lt;/env-entry&gt;
+ * </pre>
+ *
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version CVS $Id: NamingInputModule.java 36239 2004-08-11 18:28:06Z vgritsenko $
+ */
+public class NamingInputModule extends AbstractInputModule implements ThreadSafe, Initializable {
+
+    /**
+     * Initial context properties.
+     */
+    private Properties properties;
+
+    /**
+     * Initial context.
+     */
+    private InitialContext context;
+
+    /**
+     * Fill in InitialContext properties from passed configuration.
+     */
+    public void configure(Configuration conf) throws ConfigurationException {
+        Configuration[] parameters = conf.getChildren();
+        this.properties = new Properties();
+        for (int i = 0; i < parameters.length; i++) {
+            String key = parameters[i].getName();
+            String val = parameters[i].getValue("");
+            this.properties.put(key, val);
+        }
+    }
+
+    /**
+     * Creates InitialContext with configured properties.
+     */
+    public void initialize() throws Exception {
+        this.context = new InitialContext(this.properties);
+    }
+
+    /**
+     * Close InitialContext.
+     */
+    public void dispose() {
+        super.dispose();
+        if (this.context != null) {
+            try {
+                this.context.close();
+            } catch (NamingException ignored) {
+            }
+        }
+    }
+
+    /**
+     * Look up <code>name</code> from the InitialContext.
+     */
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        // Why properties can override passed name parameter? See RequestParameterModule
+        String pname = (String) this.properties.get("path");
+        if (pname == null) {
+            pname = name;
+        }
+
+        if (modeConf != null) {
+            pname = modeConf.getAttribute("path", pname);
+            // preferred
+            pname = modeConf.getChild("path").getValue(pname);
+        }
+
+        try {
+            return this.context.lookup(pname);
+        } catch (NamingException e) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Can't get parameter " + pname, e);
+            }
+            return null;
+        }
+    }
+
+    /**
+     * Returns empty iterator
+     */
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        return Collections.EMPTY_LIST.iterator();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NamingInputModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NullInputModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NullInputModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NullInputModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NullInputModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * NullInputModule returns a null object.  Use this if you want to
+ * explicitly forbid a parameter to be filled. E.g. a database column
+ * shall be filled with a default value, your forms never contain that
+ * parameter but you don't want anyone to provide this parameter
+ * manually.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: NullInputModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class NullInputModule extends AbstractInputModule implements ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+        
+        return null;
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return null;
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        return null;
+            
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/NullInputModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ProjectPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ProjectPathModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ProjectPathModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ProjectPathModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,165 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+
+/**
+ * ProjectPathModule provides relative and absolute paths with regards to the root of a project.
+ * <p>Config:
+ * <pre>
+ *    <component-instance logger="core.modules.input"
+ *           name="myproject"
+ *           class="org.apache.cocoon.components.modules.input.ProjectPathModule">
+ *      	<uri-prefix>my/project/</uri-prefix>
+ *    </component-instance>
+ * </pre>
+ * </p>
+ * <p>Usage:
+ * <pre>
+ * <map:transform src="skins/{forrest:skin}/xslt/fo/document2html.xsl">
+ *    <map:parameter name="base" value="{myproject:relative}"/>
+ * </map:transform>
+ *
+ * And then prepend this to all image paths:
+ *  ...
+ *  <xsl:param name="base"/>
+ *  ...
+ *  <xsl:template match="img">
+ *      <img src="{concat($base, @src)}" ...
+ *      ...
+ *  </xsl:template>
+ *  </pre>
+ * Then if you are in my/project/some/folder/page.html, the image will have a relative path bact to the root of the project.
+ * <pre>
+ *   <img src="../../imagename.png"/>
+ * </pre>
+ * Using 'myproject:path' would have given you: /some/folder/page.html<br/>
+ * Using 'myproject:folder' would have given you: /some/folder/
+ * </p>
+ *
+ */
+public class ProjectPathModule
+    extends AbstractInputModule
+    implements Configurable, ThreadSafe {
+
+    protected static String PROJECT_PARAM_NAME = "uri-prefix";
+    protected static String PROJECT_PARAM_DEFAULT = "/";
+
+    protected String projectBase;
+	
+    final static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("relative");
+        tmp.add("path");
+        tmp.add("folder");
+        returnNames = tmp;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration conf) throws ConfigurationException {
+        this.projectBase = conf.getChild(PROJECT_PARAM_NAME).getValue();
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Configuration supplied: " + this.projectBase);
+        }
+        if (this.projectBase == null) {
+       	    this.projectBase = PROJECT_PARAM_DEFAULT;
+            if (getLogger().isWarnEnabled()) {
+                getLogger().warn("No configuration supplied, using default: " + PROJECT_PARAM_DEFAULT);
+            }
+        }
+        if (this.projectBase.equals("")) {
+            this.projectBase = PROJECT_PARAM_DEFAULT;
+            if (getLogger().isWarnEnabled()) {
+                getLogger().warn("Empty configuration supplied, using default: " + PROJECT_PARAM_DEFAULT);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+        String uri = ObjectModelHelper.getRequest(objectModel).getServletPath();
+        StringBuffer result = new StringBuffer(uri.length());
+        int baseIndex = uri.indexOf(this.projectBase);
+        if (baseIndex != -1) {
+            uri = uri.substring(baseIndex + this.projectBase.length());
+        } else {
+            throw new ConfigurationException( "No project-base path found in URI");
+        }
+        try {
+            // provide a relative path back to the project
+            if (name.startsWith("relative")) {
+                int nextIndex = 0;
+                while ((nextIndex = uri.indexOf('/', nextIndex) + 1) > 0) {
+                    result.append("../");
+                }
+            } else if (name.startsWith("path")) {
+                // provide the full path from the project
+                result.append("/");
+                result.append(uri);
+            } else if (name.startsWith("folder")) {
+                // provide the folder path from the project
+                result.append("/");
+                result.append(uri.substring(0,uri.lastIndexOf("/") + 1));
+            } else {
+                if (getLogger().isWarnEnabled()) {
+                    getLogger().warn("Invalid verb: " + name);
+                }
+            }
+            return result;
+        } catch( final Exception mue ) {
+            throw new ConfigurationException( "Problems resolving project path.", mue);
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return ProjectPathModule.returnNames.iterator();
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        List values = new LinkedList();
+        values.add( this.getAttribute(name, modeConf, objectModel) );
+
+        return values.toArray();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ProjectPathModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.modules.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+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.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+
+/**
+ * Input module for accessing properties in a properties file.
+ *
+ * <p>
+ *  The properties file can only be configured statically and
+ *  is resolved via the SourceResolver system.
+ * </p>
+ *
+ * @author <a href="mailto:unico@apache.org">Unico Hommes</a>
+ */
+public class PropertiesFileModule extends AbstractJXPathModule
+implements InputModule, Serviceable, Configurable, ThreadSafe {
+
+    private ServiceManager m_manager;
+    private SourceResolver m_resolver;
+    private Properties m_properties;
+
+
+    /* (non-Javadoc)
+     * @see Serviceable#service(ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        m_manager = manager;
+        m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        super.dispose();
+        if (this.m_manager != null) {
+            this.m_manager.release(this.m_resolver);
+            this.m_manager = null;
+            this.m_resolver = null;
+        }
+    }
+
+    /**
+     * Configure the location of the properties file:
+     * <p>
+     *  <code>&lt;file src="resource://my.properties" /&gt;</code>
+     * </p>
+     */
+    public void configure(Configuration configuration) throws ConfigurationException {
+        super.configure(configuration);
+        String file = configuration.getChild("file").getAttribute("src");
+        load(file);
+    }
+
+    private void load(String file) throws ConfigurationException {
+        Source source = null;
+        InputStream stream = null;
+        try {
+            source = m_resolver.resolveURI(file);
+            stream = source.getInputStream();
+            m_properties = new Properties();
+            m_properties.load(stream);
+        } catch (IOException e) {
+            throw new ConfigurationException("Cannot load properties file " + file);
+        } finally {
+            if (source != null) {
+                m_resolver.release(source);
+            }
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException ignored) {
+                }
+            }
+        }
+    }
+
+    protected Object getContextObject(Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        return m_properties;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * RandomNumberModule returns a random number as a string.
+ * Configuration through child elements: "min", "max" setting
+ * range of random number. Defaults to "0" and "9999999999"
+ * respectively.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: RandomNumberModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RandomNumberModule extends AbstractInputModule implements ThreadSafe {
+
+    final static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("randomNumber");
+        returnNames = tmp;
+    }
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+        
+        long min = 0;
+        long max = java.lang.Long.MAX_VALUE;
+        if (modeConf != null) {
+            min = Long.parseLong(modeConf.getAttribute("min","0"));
+            max = Long.parseLong(modeConf.getAttribute("max",String.valueOf(max)));
+            
+            //preferred
+            min = Long.parseLong(modeConf.getChild("min").getValue("0"));
+            max = Long.parseLong(modeConf.getChild("max").getValue(String.valueOf(max)));
+        }
+        return Long.toString(java.lang.Math.round(java.lang.Math.random()*(max-min)));
+
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return RandomNumberModule.returnNames.iterator();
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+            List values = new LinkedList();
+            values.add( this.getAttribute(name, modeConf, objectModel ) );
+
+            return values.toArray();
+            
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RawRequestParameterModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RawRequestParameterModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RawRequestParameterModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RawRequestParameterModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * RawRequestParameterModule accesses request parameters without
+ * decoding to the specified <code>form-encoding</code> or casting. It uses the
+ * {@link org.apache.cocoon.environment.Request#get} method instead of the
+ * {@link org.apache.cocoon.environment.Request#getParameter} method of the
+ * {@link org.apache.cocoon.environment.Request Request} This is useful for example
+ * in conjunction with uploads.
+ *
+ * <p>If <code>get()</code> returns a Vector, <code>getAttribute()</code> will return
+ * the first element, otherwise it will return the same as <code>get()</code>.
+ * <code>getAttributeValues()</code> will either convert the Vector to an array,
+ * place the result in a new array, or return the array as is.</p>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: RawRequestParameterModule.java 159645 2005-03-31 21:34:24Z vgritsenko $
+ */
+public class RawRequestParameterModule extends AbstractInputModule implements ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        String pname = (String) this.settings.get("parameter",name);
+        if ( modeConf != null ) {
+            pname = modeConf.getAttribute( "parameter", pname );
+            // preferred
+            pname = modeConf.getChild("parameter").getValue(pname);
+        }
+        Object obj = ObjectModelHelper.getRequest(objectModel).get( pname );
+        if (obj instanceof Vector) {
+            return ((Vector) obj).firstElement();
+        } else {
+            return obj;
+        }
+
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getParameterNames());
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        Object obj = getAttribute(name, modeConf, objectModel);
+        if (obj instanceof Vector) {
+           return ((Vector)obj).toArray();
+        } else if (obj.getClass().isArray()) {
+            return (Object[]) obj;
+        } else {
+            Object[] tmp = new Object[1];
+            tmp[0] = obj;
+            return tmp;
+        }
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RawRequestParameterModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RealPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RealPathModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RealPathModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RealPathModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * RealPathModule provides a real filesystem path for a virtual
+ * context-relative path.  If this mapping cannot be performed (e.g. Cocoon is
+ * running in a .war file), <code>null</code> will be returned.
+ *
+ * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
+ * @version $Id: RealPathModule.java 292264 2005-09-28 19:17:43Z vgritsenko $
+ */
+
+/*
+ * Note: the primary use for this is to support external code that wants a
+ * filesystem path.  For example, The FOP 0.20.x serializer doesn't like
+ * relative image paths, and doesn't understand Cocoon URLs (context:, cocoon:
+ * etc).  So we pass the *2fo.xsl stylesheet a real filesystem path to where we
+ * keep our images:
+ *
+ * <map:transform src="skins/{forrest:skin}/xslt/fo/document2fo.xsl">
+ *    <map:parameter name="basedir" value="{realpath:resources}/"/>
+ * </map:transform>
+ *
+ * And then prepend this to all image paths:
+ *  ...
+ *  <xsl:param name="basedir" select="''"/>
+ *  ...
+ *  <xsl:template match="img">
+ *      <xsl:variable name="imgpath" select="concat($basedir, @src)"/>
+ *      <fo:external-graphic src="{$imgpath}" ...
+ *      ...
+ *  </xsl:template>
+ */
+public class RealPathModule extends AbstractInputModule implements ThreadSafe {
+
+    private final static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("realPath");
+        returnNames = tmp;
+    }
+
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+        String uri = ObjectModelHelper.getContext(objectModel).getRealPath(name);
+        if (uri == null) {
+            return null;
+        }
+
+        int lastCharPos = uri.length() - 1;
+        if (uri.charAt(lastCharPos) == '\\') {
+            uri = uri.substring(0, lastCharPos);
+        }
+        return uri;
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+        return RealPathModule.returnNames.iterator();
+    }
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return new Object[] { getAttribute(name, modeConf, objectModel) };
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RealPathModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,145 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * 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 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestAttributeModule extends AbstractInputModule implements ThreadSafe {
+
+    protected Object getAttribute( String name, Configuration modeConf, Map objectModel, int scope)
+    throws ConfigurationException {
+        String pname = (String) this.settings.get("parameter", name);
+        if ( modeConf != null ) {
+            pname = modeConf.getAttribute( "parameter", pname );
+            // preferred
+            pname = modeConf.getChild("parameter").getValue(pname);
+        }
+        return ObjectModelHelper.getRequest(objectModel).getAttribute( pname, scope );        
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return this.getAttribute(name, modeConf, objectModel, Request.GLOBAL_SCOPE);
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getAttributeNames());
+    }
+
+
+    protected Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel, int scope )
+    throws ConfigurationException {
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        
+        String wildcard = (String) this.settings.get("parameter",name);
+        if ( modeConf != null ) {
+            wildcard = modeConf.getAttribute( "parameter", wildcard );
+            // preferred
+            wildcard = modeConf.getChild("parameter").getValue(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 = "";
+            }
+            SortedSet names = new TreeSet();
+            Enumeration allNames = request.getAttributeNames( scope );
+
+            while (allNames.hasMoreElements()) {
+                String pname = (String) allNames.nextElement();
+                if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
+                    names.add(pname);
+                }
+            }
+
+            List values = new LinkedList();
+            Iterator j = names.iterator();
+            while (j.hasNext()){
+                String pname = (String) j.next();
+                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, scope );
+            if ( value != null && !value.getClass().isArray() ) {
+                Object[] values = new Object[1];
+                values[0] = value;
+                return values;
+            } else {
+                return (Object[]) value;
+            }
+
+        }
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return this.getAttributeValues(name, modeConf, objectModel, Request.GLOBAL_SCOPE );
+    }
+
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Map;
+
+/**
+ * RequestModule provides access to Request object properties.
+ * To get access to request properties use XPath syntax, e.g. to get the request
+ * context path use <code>'contextPath'</code> as the attribute name.<br/>
+ * More complex expressions are also supported, e.g.:
+ * <pre>
+ * 'userPrincipal/name'
+ * </pre>
+ * will return the name property of the Principal object returned by the
+ * request.getUserPrincipal() method. If requested object is not found then
+ * an exception will be thrown.
+ *
+ * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
+ * @version CVS $Id: RequestModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestModule extends AbstractJXPathModule
+    implements ThreadSafe {
+
+    protected Object getContextObject(Configuration modeConf,
+                                      Map objectModel) {
+
+        return ObjectModelHelper.getRequest(objectModel);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,120 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * 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 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestParameterModule extends AbstractInputModule implements ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        String pname = (String) this.settings.get("parameter", name);
+        if ( modeConf != null ) {
+            pname = modeConf.getAttribute( "parameter", pname );
+            // preferred
+            pname = modeConf.getChild("parameter").getValue(pname);
+        }
+        return ObjectModelHelper.getRequest(objectModel).getParameter( pname );
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getParameterNames());
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        String wildcard = (String) this.settings.get("parameter", name);
+        if ( modeConf != null ) {
+            wildcard = modeConf.getAttribute( "parameter", wildcard );
+            // preferred
+            wildcard = modeConf.getChild("parameter").getValue(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 = "";
+            }
+            SortedSet names = new TreeSet();
+            Enumeration allNames = request.getParameterNames();
+
+            while (allNames.hasMoreElements()) {
+                String pname = (String) allNames.nextElement();
+                if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
+                    names.add(pname);
+                }
+            }
+
+            List values = new LinkedList();
+            Iterator j = names.iterator();
+            while (j.hasNext()){
+                String pname = (String) j.next();
+                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 );
+
+        }
+
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestScopedAttributeModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestScopedAttributeModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestScopedAttributeModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestScopedAttributeModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.environment.Request;
+
+/**
+ * This is an extension of the {@link RequestAttributeModule}. It has the same
+ * features but requires to define the scope of an attribute: either "global" or
+ * "request"; so the name follows this form: SCOPE:KEY.
+ * 
+ * @since 2.2
+ * @version CVS $Id: RequestScopedAttributeModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestScopedAttributeModule extends RequestAttributeModule {
+
+    private static final class KeyInfo {
+        public final int scope;
+        public final String key;
+        
+        public KeyInfo(String name) throws ConfigurationException {
+            final int pos = name.indexOf(':');
+            if ( pos == -1 ) {
+                throw new ConfigurationException("Scope is missing in '" + name + '.');
+            }
+            final String scopeValue = name.substring(0, pos);
+            this.key = name.substring(pos + 1);
+            if ( "global".equalsIgnoreCase(scopeValue) ) {
+                this.scope = Request.GLOBAL_SCOPE;
+            } else if ("request".equalsIgnoreCase(scopeValue)) {
+                this.scope = Request.REQUEST_SCOPE;
+            } else {
+                throw new ConfigurationException("Unknown value for scope: " + scopeValue);
+            }
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        final KeyInfo info = new KeyInfo(name);
+        return this.getAttribute(info.key, modeConf, objectModel, info.scope);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        final KeyInfo info = new KeyInfo(name);
+        return this.getAttributeValues(info.key, modeConf, objectModel, info.scope );
+    }
+
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestScopedAttributeModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestURIModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestURIModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestURIModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestURIModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * RequestURIModule accesses the request URI. The {@link
+ * RequestModule} provides similar functionality based on JXPath.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: RequestURIModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestURIModule extends AbstractInputModule implements ThreadSafe {
+
+    final static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("requestURI");
+        returnNames = tmp;
+    }
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        String uri = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
+
+        if (uri.startsWith("/")) {
+            uri = uri.substring(1);
+        }
+
+        return uri;
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return RequestURIModule.returnNames.iterator();
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+            Object values = new Object[1];
+            values = this.getAttribute(name, modeConf, objectModel);
+
+            return (values == null? null : new Object[]{values});            
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/RequestURIModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,255 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.modules.input;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ *
+ * <h2>Configuration</h2>
+ * <table><tbody>
+ * <tr><th>input-module</th>
+ *  <td>Configuration and name of input module used for the selection.</td>
+ *  <td>req</td>
+ *  <td>String</td><td><code>null</code></td>
+ * </tr>
+ * <tr><th>when</th>
+ *  <td>Selection case, condition in test attribute, input module name
+ *      in name attribute. Optional configuration as nested content.</td>
+ *  <td>req</td><td>String</td><td><code>null</code></td>
+ * </tr>
+ * <tr><th>otherwise</th>
+ *  <td>Default selection case. If not present and no case matches, <code>null</code>
+ *      is returned.</td>
+ *  <td></td><td>String</td><td><code>null</code></td>
+ * </tr>
+ * </tbody></table>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: SelectMetaInputModule.java 55054 2004-10-19 08:21:39Z cziegeler $
+ */
+public class SelectMetaInputModule extends AbstractMetaModule implements ThreadSafe {
+
+    private Map whenTest = null;
+    private ModuleHolder expression = null;
+    private ModuleHolder otherwise = null;
+    private String parameter = null;
+
+    public SelectMetaInputModule() {
+        super();
+        this.defaultInput = null; // not needed
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+
+        Configuration[] expr = config.getChildren("input-module");
+        if (expr == null || expr.length != 1) {
+            throw new ConfigurationException("Need to have exactly one input-module element.");
+        }
+        this.parameter = config.getChild("parameter").getValue();
+        Configuration[] whens = config.getChildren("when");
+        Configuration[] others = config.getChildren("otherwise");
+        if ((whens == null && others == null)
+            || ((whens == null || whens.length == 0) && (others == null || others.length == 0))) {
+            throw new ConfigurationException("Need to have at least one when or otherwise element.");
+        }
+        if (others != null && others.length > 1) {
+            throw new ConfigurationException("Need to have at most one otherwise element.");
+        }
+        this.whenTest = new TreeMap();
+        for (int i = 0; i < expr.length; i++) {
+            String name = expr[i].getAttribute("name");
+            this.expression = new ModuleHolder(name, expr[i], null);
+        }
+
+        if (others != null) {
+            for (int i = 0; i < others.length; i++) {
+                String name = others[i].getAttribute("name");
+                this.otherwise = new ModuleHolder(name, others[i], null);
+            }
+        }
+
+        if (whens != null) {
+            for (int i = 0; i < whens.length; i++) {
+                String name = whens[i].getAttribute("name");
+                this.whenTest.put(
+                    whens[i].getAttribute("test"),
+                    new ModuleHolder(name, whens[i], null));
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(String, Configuration, Map)
+     */
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+        Object result = this.getAttribute(name, modeConf, objectModel, false);
+        return result;
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+        Object result = this.getAttribute(name, modeConf, objectModel, true);
+        return (result != null ? (Object[]) result : null );
+    }
+
+    private Object getAttribute(String name, Configuration modeConf, Map objectModel, boolean getValues)
+    throws ConfigurationException {
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+        ModuleHolder expression = this.expression;
+        ModuleHolder otherwise = this.otherwise;
+        ModuleHolder module = null;
+        String parameter = this.parameter;
+        boolean needRelease = false;
+        boolean dynamicConfig = (modeConf != null && modeConf.getChildren().length > 0);
+
+        if (dynamicConfig) {
+            // clear all configured values so that they
+            // don't get mixed up
+            expression = null;
+            otherwise = null;
+            needRelease = true;
+
+            Configuration[] expr = modeConf.getChildren("input-module");
+            Configuration[] other = modeConf.getChildren("otherwise");
+            if (expr != null && expr.length == 1) {
+                expression = new ModuleHolder(expr[0].getAttribute("name"), expr[0]);
+            }
+            if (other != null && other.length == 1) {
+                otherwise = new ModuleHolder(other[0].getAttribute("name"), other[0]);
+            }
+            parameter = modeConf.getChild("parameter").getValue();
+        }
+
+        String value =
+            (String) this.getValue(parameter, objectModel, expression.input, expression.name, expression.config);
+        if (needRelease) {
+            this.releaseModule(expression.input);
+        }
+        if (this.getLogger().isDebugEnabled()) {
+            this.getLogger().debug(
+                (dynamicConfig ? "(dyn)" : "(static)")
+                    + " select ("
+                    + value
+                    + ") from "
+                    + expression.name
+                    + ":"
+                    + parameter);
+        }
+
+        if (dynamicConfig && value != null) {
+            Configuration[] whens = modeConf.getChildren("when");
+            if (whens != null && whens.length > 0) {
+                int i = 0;
+                boolean found = false;
+                while (!found && i < whens.length) {
+                    if (whens[i].getAttribute("test").equals(value)) {
+                        found = true;
+                        break;
+                    }
+                    i++;
+                }
+                if (found) {
+                    module = new ModuleHolder(whens[i].getAttribute("name"), whens[i]);
+                }
+            }
+        } else if (value != null) {
+            module = (ModuleHolder) this.whenTest.get(value);
+        }
+        if (module != null) {
+            if (this.getLogger().isDebugEnabled()) {
+                this.getLogger().debug("found matching when : "+module.name);
+            }
+        } else {
+            module = otherwise;
+            if (this.getLogger().isDebugEnabled()) {
+                this.getLogger().debug("using otherwise : "+module.name);
+            }
+        }
+
+        Object result;
+        if (getValues){
+            result = (module == null ? null : this.getValues(name, objectModel, module));
+        } else {
+            result = (module == null ? null : this.getValue(name, objectModel, module));
+        }
+
+        if (needRelease && module != null) {
+            this.releaseModule(module.input);
+        }
+        if (this.getLogger().isDebugEnabled()) {
+            this.getLogger().debug("Obtained value : "+result);
+        }
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        this.releaseModule(this.expression.input);
+        this.expression = null;
+
+        if (this.otherwise != null) {
+            this.releaseModule(this.otherwise.input);
+            this.otherwise = null;
+        }
+
+        for (Iterator i = this.whenTest.values().iterator(); i.hasNext();) {
+            ModuleHolder holder = (ModuleHolder) i.next();
+            this.releaseModule(holder.input);
+        }
+        this.whenTest = null;
+
+        super.dispose();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.components.modules.input.AbstractMetaModule#lazy_initialize()
+     */
+    public synchronized void lazy_initialize() {
+        if (this.initialized) {
+            return;
+        }
+
+        super.lazy_initialize();
+
+        if (this.expression != null) {
+            this.expression.input = this.obtainModule(this.expression.name);
+        }
+        if (this.otherwise != null){
+            this.otherwise.input = this.obtainModule(this.otherwise.name);
+        }
+        if (this.whenTest != null){
+            for (Iterator i = this.whenTest.values().iterator(); i.hasNext(); ){
+                ModuleHolder moduleHolder = (ModuleHolder) i.next();
+                moduleHolder.input = this.obtainModule(moduleHolder.name);
+            }
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * 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 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionAttributeModule extends AbstractInputModule implements ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        String pname = (String) this.settings.get("parameter", name);
+        if ( modeConf != null ) {
+            pname = modeConf.getAttribute( "parameter", pname );
+            // preferred
+            pname = modeConf.getChild("parameter").getValue(pname);
+        }
+        return ObjectModelHelper.getRequest(objectModel).getSession().getAttribute( pname );
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getSession().getAttributeNames());
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel )
+        throws ConfigurationException {
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        String wildcard = (String) this.settings.get("parameter", name);
+        if ( modeConf != null ) {
+            wildcard = modeConf.getAttribute( "parameter", wildcard );
+            // preferred
+            wildcard = modeConf.getChild("parameter").getValue(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 = "";
+            }
+            SortedSet names = new TreeSet();
+            Session session = request.getSession();
+            Enumeration allNames = session.getAttributeNames();
+
+            while (allNames.hasMoreElements()) {
+                String pname = (String) allNames.nextElement();
+                if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) {
+                    names.add(pname);
+                }
+            }
+
+            List values = new LinkedList();
+            Iterator j = names.iterator();
+            while (j.hasNext()){
+                String pname = (String) j.next();
+                values.add( session.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;
+            }
+
+        }
+
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.util.Map;
+
+/**
+ * SessionModule provides access to Session object properties.
+ * To get access to session properties use XPath syntax, e.g. to get the session
+ * id use <code>'id'</code> as the attribute name.<br/>
+ * More complex expressions with functions are also supported, e.g.:
+ * <pre>
+ * 'substring(id, 8)'
+ * </pre>
+ * will return the substring of id property of the session object.
+ * <strong>NOTE:</strong> The module does not create a new session.
+ *
+ * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
+ * @version CVS $Id: SessionModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionModule extends AbstractJXPathModule
+    implements ThreadSafe {
+
+    protected Object getContextObject(Configuration modeConf,
+                                      Map objectModel) {
+
+        return ObjectModelHelper.getRequest(objectModel).getSession(false);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SessionModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,318 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/** Meta module that obtains values from an other module and by
+ * replacing the requested attribute name with another name. This is
+ * done first through a replacement table and may additionally prepend
+ * or append a string. Replacement works in both ways, it is applied
+ * to the returned attribute names as well.
+ *
+ * <p>Example configuration:<pre>
+ * &lt;prefix&gt;cocoon.&lt;/prefix&gt;
+ * &lt;suffix&gt;.attr&lt;/suffix&gt;
+ * &lt;mapping in="foo" out="bar"/&gt;
+ * &lt;mapping in="yuk" out="yeeha"/&gt;
+ *</pre>
+ *
+ * Will map a parameter "foo" to the real one named
+ * "cocoon.bar.attr". If parameters "coocoon.yeeha.attr" and
+ * "shopping.cart" exist, the iterator will return
+ * "yeeha". "shopping.cart" does not contain the pre-/ suffix and thus
+ * is dropped.</p> 
+ *
+ * <p>Similarily, rm-prefix and rm-suffix will be removed from the
+ * attribute name.</p>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: SimpleMappingMetaModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SimpleMappingMetaModule extends AbstractMetaModule implements ThreadSafe {
+
+    String prefix = null;
+    String suffix = null;
+    String rmPrefix = null;
+    String rmSuffix = null;
+    Mapping mapping = null;
+
+    protected class Mapping {
+        Map toMap = null;
+        Map fromMap = null;
+
+        public Mapping() {
+        }       
+
+        public Mapping(Map to, Map from) {
+            this.toMap = to;
+            this.fromMap = from;
+        }
+
+        public Mapping(Configuration config) throws ConfigurationException {
+            Configuration[] mappings = config.getChildren("mapping");
+            if (mappings!=null) {
+                if (this.toMap == null) this.toMap = new HashMap();
+                if (this.fromMap == null) this.fromMap = new HashMap();
+                for (int i=0; i < mappings.length; i++){
+                    String in = mappings[i].getAttribute("in",null);
+                    String out = mappings[i].getAttribute("out",null);
+                    if (in != null && out != null) {
+                        this.toMap.put(in,out);
+                        this.fromMap.put(out,in);
+                    }
+                }
+            }
+        }
+
+        private String mapIt(Map map, String param) {
+            Object newParam = param;
+            if (map != null) {
+                newParam = map.get(param);
+                if (!map.containsKey(param) || newParam == null)
+                    newParam = param;
+            }
+            return (String) newParam;
+        }
+
+        public String mapFrom(String param) {
+            return this.mapIt(this.fromMap, param);
+        }
+
+        public String mapTo(String param) {
+            return this.mapIt(this.toMap, param);
+        }
+    }
+
+
+    public void configure(Configuration config) throws ConfigurationException {
+
+        // It seems that even if there is no config, we'll get an empty
+        // input-module element here, so it will never be null (JT)
+        this.inputConf = config.getChild("input-module");
+        this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput);
+        this.prefix = config.getChild("prefix").getValue(null);
+        this.suffix = config.getChild("suffix").getValue(null);
+        this.rmPrefix = config.getChild("rm-prefix").getValue(null);
+        this.rmSuffix = config.getChild("rm-suffix").getValue(null);
+        this.mapping = new Mapping(config);
+    }
+
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+        if (this.defaultInput == null) {
+            if (getLogger().isWarnEnabled()) 
+                getLogger().warn("No input module given. FAILING");
+            return null;
+        }
+
+        Configuration inputConfig = null;
+        String inputName=null;
+        Mapping mapping = this.mapping;
+        String prefix = this.prefix;
+        String suffix = this.suffix;
+        String rmPrefix = this.rmPrefix;
+        String rmSuffix = this.rmSuffix;
+
+        if (modeConf!=null && modeConf.getChildren().length > 0) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+            mapping = new Mapping(modeConf);
+            prefix = modeConf.getChild("prefix").getValue(null);
+            suffix = modeConf.getChild("suffix").getValue(null);
+            rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
+            rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
+        }
+        
+        // remove rm-prefix and rm-suffix
+        if (rmPrefix != null && name.startsWith(rmPrefix)) {
+            name = name.substring(rmPrefix.length());
+        }
+        if (rmSuffix != null && name.endsWith(rmSuffix)) {
+            name = name.substring(0,name.length() - rmSuffix.length());
+        }
+        // map
+        String param = mapping.mapTo(name);
+        // add prefix and suffix
+        if (prefix != null) param = prefix + param;
+        if (suffix != null) param = param + suffix;
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("mapping ['"+name+"'] to ['"+param+"']");
+
+        Object res = getValue(param, objectModel,
+                              this.input, this.defaultInput, this.inputConf,
+                              null, inputName, inputConfig);
+        
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("getting for real attribute ['"+param+"'] value: "+res);
+
+        return res;
+    }
+
+
+
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+        if (this.defaultInput == null) {
+            if (getLogger().isWarnEnabled()) 
+                getLogger().warn("No input module given. FAILING");
+            return null;
+        }
+
+        Configuration inputConfig = null;
+        String inputName=null;
+        Mapping mapping = this.mapping;
+        String prefix = this.prefix;
+        String suffix = this.suffix;
+        String rmPrefix = this.rmPrefix;
+        String rmSuffix = this.rmSuffix;
+
+        if (modeConf!=null && modeConf.getChildren().length > 0) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+            mapping = new Mapping(modeConf);
+            prefix = modeConf.getChild("prefix").getValue(null);
+            suffix = modeConf.getChild("suffix").getValue(null);
+            rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
+            rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
+        }
+        
+        // remove rm-prefix and rm-suffix
+        if (rmPrefix != null && name.startsWith(rmPrefix)) {
+            name = name.substring(rmPrefix.length());
+        }
+        if (rmSuffix != null && name.endsWith(rmSuffix)) {
+            name = name.substring(0,name.length() - rmSuffix.length());
+        }
+        // map
+        String param = mapping.mapTo(name);
+        // add prefix and suffix
+        if (prefix != null) param = prefix + param;
+        if (suffix != null) param = param + suffix;
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("mapping ['"+name+"'] to ['"+param+"']");
+
+        Object[] res = getValues(param, objectModel,
+                                 this.input, this.defaultInput, this.inputConf,
+                                 null, inputName, inputConfig);
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("getting for real attribute ['"+param+"'] value: "+res);
+
+        return res;
+    }
+
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+        if (this.defaultInput == null) {
+            if (getLogger().isWarnEnabled()) 
+                getLogger().warn("No input module given. FAILING");
+            return null;
+        }
+
+        Configuration inputConfig = null;
+        String inputName=null;
+        Mapping mapping = this.mapping;
+        String prefix = this.prefix;
+        String suffix = this.suffix;
+        String rmPrefix = this.rmPrefix;
+        String rmSuffix = this.rmSuffix;
+        if (modeConf!=null && modeConf.getChildren().length > 0) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+            mapping = new Mapping(modeConf);
+            prefix = modeConf.getChild("prefix").getValue(null);
+            suffix = modeConf.getChild("suffix").getValue(null);
+            rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
+            rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
+        }
+        
+        Iterator names = getNames(objectModel, 
+                                  this.input, this.defaultInput, this.inputConf, 
+                                  null, inputName, inputConfig);
+
+        Set set = new HashSet();
+        while (names.hasNext()) {
+            String param = (String) names.next();
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("reverse mapping starts with ['"+param+"']");
+            if (prefix != null) 
+                if (param.startsWith(prefix))
+                    param = param.substring(prefix.length());
+                else 
+                    continue; // prefix is set but parameter does not start with it.
+            
+            //if (getLogger().isDebugEnabled())
+            //    getLogger().debug("reverse mapping after remove prefix ['"+param+"']");
+
+            if (suffix != null)
+                if (param.endsWith(suffix))
+                    param = param.substring(0,param.length() - suffix.length());
+                else 
+                    continue; // suffix is set but parameter does not end with it.
+
+            //if (getLogger().isDebugEnabled())
+            //    getLogger().debug("reverse mapping after remove suffix ['"+param+"']");
+
+            if (param.length() < 1)
+                continue; // nothing left
+
+            String newName = mapping.mapFrom(param);
+
+            if (rmPrefix != null) newName = rmPrefix + newName;
+            if (rmSuffix != null) newName = newName + rmSuffix;
+
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("reverse mapping results in ['"+newName+"']");
+
+            set.add(newName);
+        }
+
+        return set.iterator();
+
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message