cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [17/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/AbstractJXPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,138 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+/**
+ * JXPathModule allows to access properties of any object in generic
+ * way.  JXPath provides APIs for the traversal of graphs of
+ * JavaBeans, DOM and other types of objects using the XPath
+ * syntax.
+ *
+ * <p><strong>Note:</strong> JXPathMetaModule is based on this class
+ * and duplicates the code since multiple inheritance is not possible.
+ * Please keep both classes in sync.</p>
+ *
+ * <h3>Configuration</h3>
+ * <table>
+ * <tr>
+ *   <td><code>&lt;lenient&gt;false&lt;/lenient&gt;</code></td>
+ *   <td>When set to true, non-existing attributes return null; when set to false,
+ *       an exception is thrown. Default is true.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;parameter&gt;foo&lt;/parameter&gt;</td>
+ *   <td>When set overrides attribute name passed to module.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;function name="java.lang.String" prefix="str"/&gt;</td>
+ *   <td>Imports the class "String" as extension class to the JXPathContext using
+ *   the prefix "str". Thus "str:length(xpath)" would apply the method "length" to
+ *   the string object obtained from the xpath expression. Please note that the class
+ *   needs to be fully qualified.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;package name="java.util" prefix="util"/&gt;</td>
+ *   <td>Imports all classes in the package "java.util" as extension classes to the
+ *   JXPathContext using the prefix "util". Thus "util:Date.new()" would create a
+ *   new java.util.Date object.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;namespace uri="uri:foo" prefix="bar"/&gt;</td>
+ *   <td>Registers the namespace identified by URI <code>uri:foo</code>
+ *   with the JXPathContext using the prefix <code>bar</code>. Thus
+ *   expressions can query XML with nodes in this namespace using
+ *   registered prefix.</td>
+ * </tr>
+ * </table>
+ *
+ * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version $Id: AbstractJXPathModule.java 160295 2005-04-06 13:59:30Z vgritsenko $
+ */
+public abstract class AbstractJXPathModule extends AbstractInputModule {
+
+    /**
+     * Contains all globally registered extension classes and
+     * packages. Thus the lookup and loading of globally registered
+     * extensions is done only once.
+     */
+    protected JXPathHelperConfiguration configuration;
+
+    /**
+     * Overrides attribute name
+     */
+    protected String parameter;
+
+    /**
+     * Configure component. Preprocess list of packages and functions
+     * to add to JXPath context later.
+     *
+     * @param config a <code>Configuration</code> value
+     * @exception ConfigurationException if an error occurs
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+
+        this.configuration = JXPathHelper.setup(config);
+    }
+
+
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        Object contextObj = getContextObject(modeConf, objectModel);
+        if (modeConf != null) {
+            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter : name);
+        }
+        return JXPathHelper.getAttribute(name, modeConf, this.configuration, contextObj);
+    }
+
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        Object contextObj = getContextObject(modeConf, objectModel);
+        return JXPathHelper.getAttributeNames(this.configuration, contextObj);
+    }
+
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
+
+        Object contextObj = getContextObject(modeConf, objectModel);
+        if (modeConf != null) {
+            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter : name);
+        }
+        return JXPathHelper.getAttributeValues(name, modeConf, this.configuration, contextObj);
+    }
+
+
+    /**
+     * Returns the object which should be used as JXPath context.
+     * Descendants should override this method to return a specific object
+     * that is requried by the implementing class.
+     * Examples are: request, session and application context objects.
+     */
+    protected abstract Object getContextObject(Configuration modeConf,
+                                               Map objectModel)
+    throws ConfigurationException;
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,382 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+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.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ * AbstractMetaModule gives you the infrastructure for easily
+ * deploying more "meta" InputModules i.e. InputModules that are
+ * composed of other InputModules.  In order to get at the Logger, use
+ * getLogger().
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
+ * @version CVS $Id: AbstractMetaModule.java 149131 2005-01-30 18:21:40Z cziegeler $
+ */
+public abstract class AbstractMetaModule extends AbstractInputModule
+    implements Serviceable, Disposable {
+
+    /** The service manager instance */
+    protected ServiceManager manager;
+
+    /** The cached InputModule-Selector */
+    protected ServiceSelector inputSelector;
+
+    /** The cached default InputModule */
+    protected InputModule input;
+
+    /** The default InputModule name / shorthand. Defaults to 'request-param' */
+    protected String defaultInput = "request-param"; // default to request parameters
+
+    /** The default InputModule configuration */
+    protected Configuration inputConf;  // will become an empty configuration object
+                                        // during configure() so why bother here...
+    
+    /** Is this instance initialized? */
+    protected boolean initialized = false;
+
+    /* Constants */
+
+    protected final static String INPUT_MODULE_SELECTOR = InputModule.ROLE+"Selector";
+
+    /* Operation codes */
+    private final static int OP_GET = 0;
+    private final static int OP_VALUES = 1;
+    private final static int OP_NAMES = 2;
+    private final static String[] OPNAME = new String[] {"GET_VALUE", "GET_VALUES", "GET_NAMES"};
+
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager=manager;
+    }
+
+    /**
+     * Initialize the meta module with exactly one other input
+     * module. Since "meta" modules require references to components
+     * of the same role, initialization cannot be done in initialize()
+     * when also implementing ThreadSafe since at that point the
+     * component selector is not yet initialized it would trigger the
+     * creation of a new one resulting in an endless loop of
+     * initializations. Therefore, every module needs to call this
+     * method when it first requires access to another module if the
+     * module itself has not been initialized. Override this method
+     * and dispose() to keep references to more than one module.
+     */
+    public synchronized void lazy_initialize() {
+
+        try {
+            // obtain input modules
+            if (!this.initialized) {
+                this.inputSelector=(ServiceSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
+                if (this.inputSelector != null && this.inputSelector instanceof ThreadSafe) {
+                    
+                    if (this.defaultInput != null) {
+                        this.input = obtainModule(this.defaultInput);
+                    }
+                    
+                } else if (!(this.inputSelector instanceof ThreadSafe) ) {
+                    this.manager.release(this.inputSelector);
+                    this.inputSelector = null;
+                }
+                
+                this.initialized = true;
+            }
+        } catch (Exception e) {
+            if (getLogger().isWarnEnabled()) 
+                getLogger().error("A problem occurred setting up input modules :'" + e.getMessage(), e);
+        }
+    }
+
+
+    /**
+     * Dispose exactly one cached InputModule. To work on more than
+     * one, override this method and initialize().
+     */
+    public void dispose() {
+
+        if (this.inputSelector != null) {
+            if (this.input != null)
+                this.inputSelector.release(this.input);
+            this.manager.release(this.inputSelector);
+        }
+    }
+
+
+    /**
+     * Obtain a permanent reference to an InputModule.
+     */
+    protected InputModule obtainModule(String type) {
+        ServiceSelector inputSelector = this.inputSelector;
+        InputModule module = null;
+        try {
+            if (inputSelector == null) 
+                inputSelector=(ServiceSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
+
+            if (inputSelector.isSelectable(type)){
+                
+                if (type != null && inputSelector.isSelectable(type))
+                    module = (InputModule) inputSelector.select(type);
+                
+                if (!(module instanceof ThreadSafe) ) {
+                    inputSelector.release(module);
+                    module = null;
+                }
+            }
+            if (type != null && module == null)
+                if (getLogger().isWarnEnabled())
+                    getLogger().warn("A problem occurred setting up '" + type
+                                     +"': Selector is "+(inputSelector!=null?"not ":"")
+                                     +"null, Component is "
+                                     +(inputSelector!=null && inputSelector.isSelectable(type)?"known":"unknown"));
+            
+        } catch (ServiceException ce) {
+            if (getLogger().isWarnEnabled())
+                getLogger().warn("Could not obtain selector for InputModules: "+ce.getMessage());
+        } finally {
+            if (this.inputSelector == null) 
+                this.manager.release(inputSelector);
+            // FIXME: Is it OK to keep a reference to the module when we release the selector?
+        }
+
+        return module;
+    }
+
+
+    /**
+     * release a permanent reference to an InputModule.
+     */
+    protected void releaseModule(InputModule module) {
+        ServiceSelector inputSelector = this.inputSelector;
+        if (module != null) {
+            try {
+                // FIXME: Is it OK to release a module when we have released the selector before?
+                if (inputSelector == null) 
+                    inputSelector=(ServiceSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
+                
+                inputSelector.release(module);
+                module = null;
+                
+            } catch (ServiceException ce) {
+                if (getLogger().isWarnEnabled())
+                    getLogger().warn("Could not obtain selector for InputModules: "+ce.getMessage());
+            } finally {
+                if (this.inputSelector == null) 
+                    this.manager.release(inputSelector);
+            }
+        }
+    }
+
+    /**
+     * Get names of available attributes in the specified (usually statically
+     * assigned) Input Module.
+     * @see InputModule#getAttributeNames(Configuration, Map)
+     */
+    protected Iterator getNames(Map objectModel, 
+                                InputModule staticMod, String staticModName, Configuration staticModConf) 
+        throws ConfigurationException {
+
+        return (Iterator) this.get(OP_NAMES, null, objectModel, staticMod, staticModName, staticModConf, null, null, null);
+    }
+
+    /**
+     * Get names of available attributes in one of the specified Input Modules
+     * (static or dynamic, dynamic preferred).  Dynamic IM may be
+     * <code>null</code>.
+     * @see InputModule#getAttributeNames(Configuration, Map)
+     */
+     protected Iterator getNames(Map objectModel, 
+                                InputModule staticMod, String staticModName, Configuration staticModConf,
+                                InputModule dynamicMod, String dynamicModName, Configuration dynamicModConf)
+        throws ConfigurationException {
+
+        return (Iterator) this.get(OP_NAMES, null, objectModel, staticMod, staticModName, staticModConf, dynamicMod, dynamicModName, dynamicModConf);
+    }
+
+    protected Object getValue(String attr, Map objectModel, ModuleHolder holder) throws ConfigurationException{
+        return this.getValue(attr, objectModel, holder.input, holder.name, holder.config);
+    }
+
+    protected Object getValue(String attr, Map objectModel, ModuleHolder staticHolder, ModuleHolder dynamicHolder) throws ConfigurationException{
+        return this.getValue(attr, objectModel, staticHolder.input, staticHolder.name, dynamicHolder.config);
+    }
+
+    protected Object[] getValues(String attr, Map objectModel, ModuleHolder holder) throws ConfigurationException{
+        return this.getValues(attr, objectModel, holder.input, holder.name, holder.config);
+    }
+
+    protected Object[] getValues(String attr, Map objectModel, ModuleHolder staticHolder, ModuleHolder dynamicHolder) throws ConfigurationException{
+        return this.getValues(attr, objectModel, staticHolder.input, staticHolder.name, dynamicHolder.config);
+    }
+
+    /**
+     * Get an attribute's value from a (usually statically assigned) Input
+     * Module.
+     * @see InputModule#getAttribute(String, Configuration, Map)
+     */
+     protected Object getValue(String attr, Map objectModel, 
+                              InputModule staticMod, String staticModName, Configuration staticModConf)
+        throws ConfigurationException {
+
+        return this.get(OP_GET, attr, objectModel, staticMod, staticModName, staticModConf, null, null, null);
+    }
+
+
+    /**
+     * Get attribute's value in one of the specified Input Modules 
+     * (static or dynamic, dynamic preferred).  Dynamic IM may be
+     * <code>null</code>.
+     * @see InputModule#getAttribute(String, Configuration, Map)
+     */
+     protected Object getValue(String attr, Map objectModel, 
+                              InputModule staticMod, String staticModName, Configuration staticModConf,
+                              InputModule dynamicMod, String dynamicModName, Configuration dynamicModConf)
+        throws ConfigurationException {
+
+        return this.get(OP_GET, attr, objectModel, staticMod, staticModName, staticModConf, dynamicMod, dynamicModName, dynamicModConf);
+    }
+
+    /**
+     * Get an attribute's values from a (usually statically assigned) Input
+     * Module.
+     * @see InputModule#getAttributeValues(String, Configuration, Map)
+     */
+     protected Object[] getValues(String attr, Map objectModel, 
+                                 InputModule staticMod, String staticModName, Configuration staticModConf)
+        throws ConfigurationException {
+
+        return (Object[]) this.get(OP_VALUES, attr, objectModel, staticMod, staticModName, staticModConf, null, null, null);
+    }
+
+    /**
+     * Get attribute's values in one of the specified Input Modules 
+     * (static or dynamic, dynamic preferred).  Dynamic IM may be
+     * <code>null</code>.
+     * @see InputModule#getAttributeValues(String, Configuration, Map)
+     */
+     protected Object[] getValues(String attr, Map objectModel, 
+                                 InputModule staticMod, String staticModName, Configuration staticModConf,
+                                 InputModule dynamicMod, String dynamicModName, Configuration dynamicModConf)
+        throws ConfigurationException {
+
+        return (Object[]) this.get(OP_VALUES, attr, objectModel, staticMod, staticModName, staticModConf, dynamicMod, dynamicModName, dynamicModConf);
+    }
+
+
+    /**
+     * Encapsulates use of an InputModule. Does all the lookups and so on.  
+     * The second module (dynamic) is preferred if it has an non null name. If
+     * an exception is encountered, a warn message is printed and null is
+     * returned.
+     * @param op Operation to perform ({@link #OP_GET}, {@link #OP_NAMES}, {@link #OP_VALUES}).
+     *
+     * @return Either an Object, an Object[], or an Iterator, depending on <code>op</code> param.
+     */ 
+    private Object get(int op, String attr, Map objectModel,
+                         InputModule staticMod, String staticModName, Configuration staticModConf,
+                         InputModule dynamicMod, String dynamicModName, Configuration dynamicModConf)
+        throws ConfigurationException {
+
+        ServiceSelector cs = this.inputSelector;
+        Object value = null;
+        String name = null;
+        InputModule input = null;
+        Configuration conf = null;
+        boolean release = false;
+
+        try {
+            if (cs == null) {
+                try {
+                cs = (ServiceSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
+                } catch (ServiceException e) {
+                    throw new ConfigurationException("Could not find MetaModule's module selector", e);
+                }
+            }
+
+            boolean useDynamic;
+            if (dynamicMod == null && dynamicModName == null) {
+                useDynamic = false;
+                input = staticMod;
+                name = staticModName;
+                conf = staticModConf;
+            } else {
+                useDynamic = true;
+                input = dynamicMod;
+                name = dynamicModName;
+                conf = dynamicModConf;
+            }
+        
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("MetaModule performing op "+OPNAME[op]+" on " + 
+                        (useDynamic?"dynamically":"statically") + " " +
+                        (input==null?"created":"assigned") +
+                        " module '"+name+"', using config "+dynamicModConf);
+            }
+
+            if (input == null) {
+                if (cs.isSelectable(name)) {
+                    release = true;
+                    try {
+                        input = (InputModule) cs.select(name);
+                    } catch (ServiceException e) {
+                        throw new ConfigurationException(
+                                "MetaModule unable to create "+
+                                (useDynamic ? "dynamically" : "statically")+
+                                " specified internal module '"+name+"'", e);
+                    }
+                } else {
+                    throw new ConfigurationException("MetaModule: No such InputModule: "+name);
+                }
+            }
+
+            switch (op) {
+            case OP_GET:    
+                value = input.getAttribute(attr, conf, objectModel);
+                break;
+            case OP_VALUES:
+                value = input.getAttributeValues(attr, conf, objectModel);
+                break;
+            case OP_NAMES:
+                value = input.getAttributeNames(conf, objectModel);
+                break;
+            }
+
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("using "+name+" as "+input+" for "+op+" ("+attr+") and "+conf+" gives "+value);
+            
+        } finally {         
+            if (release)
+                cs.release(input);
+
+            if (this.inputSelector == null)
+                this.manager.release(cs);
+        }
+
+        return value;
+    }
+                              
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BaseLinkModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BaseLinkModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BaseLinkModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BaseLinkModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999-2002,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.Vector;
+
+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;
+
+/**
+ * BaseLinkModule returns a relative link (<code>../</code>,
+ * <code>../../</code> etc) to the base of the current request or sitemap URI.  For
+ * instance, if called within a &lt;map:match pattern="a/b/c.xsp"> pipeline,
+ * <code>{baselink:SitemapBaseLink}</code> would evaluate to <code>../../</code>.
+ *
+ * @author <a href="mailto:tk-cocoon@datas-world.de">Torsten Knodt</a>
+ * based on RequestURIModule
+ *
+ */
+public class BaseLinkModule extends AbstractInputModule implements ThreadSafe {
+
+    final static Vector returnNames = new Vector() {
+        {
+            add("RequestBaseLink");
+            add("SitemapBaseLink");
+        }
+    };
+
+    public Object getAttribute(
+        final String name,
+        final Configuration modeConf,
+        final Map objectModel)
+        throws ConfigurationException {
+
+        String uri;
+        if (name.equals("SitemapBaseLink"))
+            uri = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
+        else if (name.equals("RequestBaseLink"))
+            uri = ObjectModelHelper.getRequest(objectModel).getRequestURI();
+        else
+            uri = "";
+
+        if (uri.startsWith("/")) {
+            uri = uri.substring(1);
+        }
+
+        StringBuffer result = new StringBuffer(uri.length());
+
+        int nextIndex = 0;
+        while ((nextIndex = uri.indexOf('/', nextIndex) + 1) > 0) {
+            result.append("../");
+        }
+
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("Returns " + result + " for uri " + uri + " and attribute " + name);
+
+        return result.toString();
+    }
+
+    public Iterator getAttributeNames(final Configuration modeConf, final Map objectModel)
+        throws ConfigurationException {
+
+        return RequestURIModule.returnNames.iterator();
+    }
+
+    public Object[] getAttributeValues(
+        final String name,
+        final Configuration modeConf,
+        final Map objectModel)
+        throws ConfigurationException {
+
+        Object result = new Object[1];
+        result = getAttribute(name, modeConf, objectModel);
+        return (result == null? null : new Object[]{result});        
+    }
+
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,65 @@
+/*
+ * 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.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.Map;
+
+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.components.blocks.Block;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.internal.BlockEnvironmentHelper;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+
+/**
+ * BlockPathModule returns the absolute path of a block protocol path.
+ *
+ * @version $Id: BlockPathModule.java 293174 2005-10-02 22:00:30Z danielf $
+ */
+public class BlockPathModule implements InputModule, ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        Environment env = EnvironmentHelper.getCurrentEnvironment();
+        Block block = BlockEnvironmentHelper.getCurrentBlock();
+        String absoluteURI = null;
+        String baseURI = env.getURIPrefix();
+        if (baseURI.length() == 0 || !baseURI.startsWith("/"))
+            baseURI = "/" + baseURI;
+        try {
+            URI uri = block.absolutizeURI(new URI(name), new URI(null, null, baseURI, null));
+            absoluteURI = uri.toString();
+        } catch (URISyntaxException e) {
+            throw new ConfigurationException("Couldn't absolutize " + name);
+        }
+        return absoluteURI;
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPropertyModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPropertyModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPropertyModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/BlockPropertyModule.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 java.util.Iterator;
+import java.util.Map;
+
+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.internal.BlockEnvironmentHelper;
+
+/**
+ * BlockPropertyModule provides access to the properties of the current block.
+ *
+ * @version $Id: BlockPropertyModule.java 293174 2005-10-02 22:00:30Z danielf $
+ */
+public class BlockPropertyModule implements InputModule, ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return BlockEnvironmentHelper.getCurrentBlock().getProperty(name);
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,265 @@
+/*
+ * 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.service.ServiceSelector;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * This modules allows to "chain" several other modules. If a module
+ * returns "null" as attribute value, the next module in the chain is
+ * queried until either a value can be obtained or the end of the
+ * chain is reached.
+ *
+ * <p>A typical example would be to "chain" request parameters,
+ * session attributes, and constants in this order. This way, an
+ * application could have a default skin that could be overridden by a
+ * user in her/his profile stored in the session. In addition, the
+ * user could request a different skin through passing a request
+ * parameter.</p>
+ *
+ * <p>Usage:</p>
+ *
+ * <p> Any number of &lt;input-module/&gt; blocks may appear in the
+ * component configuration. The @name attribute is used as the name of
+ * the requested input module. The complete &lt;input-module/&gt;
+ * block is passed at run-time to the module and thus can contain any
+ * configuration data for that particular module.</p>
+ *
+ * <p>Configuration:</p>
+ *
+ * <p>It can be controlled whether it returns a flat or a deep view,
+ * i.e. whether only values from the first module are returned if
+ * non-null or they are merged with values from other modules
+ * <code>&lt;all-values&gt;true&lt;/all-values&gt;</code>. The same is
+ * possible for the attribute names
+ * (<code>&lt;all-names/&gt;</code>). In addition, empty strings could
+ * be treated the same as null values
+ * (<code>&lt;empty-as-null/&gt;</code>).</p>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: ChainMetaModule.java 55054 2004-10-19 08:21:39Z cziegeler $
+ */
+public class ChainMetaModule extends AbstractMetaModule implements ThreadSafe {
+
+    private ModuleHolder[] inputs = null;
+
+    private boolean emptyAsNull = false;
+    private boolean allNames = false;
+    private boolean allValues = false;
+
+    public void configure(Configuration config) throws ConfigurationException {
+
+        Configuration[] confs = config.getChildren("input-module");
+        if (confs.length > 0) {
+            this.inputs = new ModuleHolder[confs.length];
+            int j = 0;
+            for (int i=0; i<confs.length; i++) {
+                ModuleHolder module = new ModuleHolder();
+                module.name = confs[i].getAttribute("name",null);
+                if (module.name == null) {
+                    if (getLogger().isErrorEnabled())
+                        getLogger().error("No name attribute for module configuration. Skipping.");
+                    continue;
+                }
+                module.config = confs[i];
+                this.inputs[j]=module;
+                j++;
+            }
+        }
+        this.emptyAsNull = config.getChild("empty-as-null").getValueAsBoolean(this.emptyAsNull);
+        this.allNames = config.getChild("all-names").getValueAsBoolean(this.allNames);
+        this.allValues = config.getChild("all-values").getValueAsBoolean(this.allValues);
+    }
+
+
+    public synchronized void lazy_initialize() {
+
+        try {
+            // obtain input modules
+            if (!this.initialized) {
+                this.inputSelector=(ServiceSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 
+                if (this.inputSelector != null && this.inputSelector instanceof ThreadSafe) {
+                    
+                    for (int i=0; i<this.inputs.length; i++) {
+                        if (this.inputs[i].name != null) 
+                            this.inputs[i].input = obtainModule(this.inputs[i].name);
+                    }
+                    
+                } else if (!(this.inputSelector instanceof ThreadSafe) ) {
+                    this.manager.release(this.inputSelector);
+                    this.inputSelector = null;
+                }
+                
+                this.initialized = true;
+            }
+        } catch (Exception e) {
+            if (getLogger().isWarnEnabled()) 
+                getLogger().warn("A problem occurred setting up input modules :'" + e.getMessage());
+        }
+    }
+
+    
+    public void dispose() {
+        
+        if (this.inputSelector != null) {
+            
+            for (int i=0; i<this.inputs.length; i++) {
+                if (this.inputs[i].input != null)
+                    this.inputSelector.release(this.inputs[i].input);
+            }
+            
+            this.manager.release(this.inputSelector);
+        }
+    }
+
+
+    public Object[] getAttributeValues( String attr, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration[] inputConfigs = null;
+        boolean allValues = this.allValues;
+        boolean emptyAsNull = this.emptyAsNull;
+        if (modeConf!=null && modeConf.getChildren().length > 0) {
+            inputConfigs = modeConf.getChildren("input-module");
+            emptyAsNull = modeConf.getChild("empty-as-null").getValueAsBoolean(emptyAsNull);
+            allValues = modeConf.getChild("all-values").getValueAsBoolean(allValues);
+            if (inputConfigs.length == 0) inputConfigs = null;
+        }
+
+        Object[] value = null;
+        boolean debug = getLogger().isDebugEnabled();
+        List values = null;
+        if (allValues) values = new ArrayList();
+
+        if (inputConfigs == null) {
+            // static configuration branch
+            int i = 0;
+            while (i < this.inputs.length && (value == null || allValues)) {
+                if (this.inputs[i].name != null) {
+                    value = getValues(attr, objectModel, this.inputs[i].input, this.inputs[i].name, this.inputs[i].config);
+                    if (emptyAsNull && value != null && value.length == 0) value = null;
+                    if (emptyAsNull && value != null && value.length == 1 && 
+                        value[0] instanceof String && value[0].equals("")) value = null;
+                    if (debug) getLogger().debug("read from "+this.inputs[i].name+" attribute "+attr+" as "+value);
+                    if (allValues && value != null) values.addAll(Arrays.asList(value));
+                }
+                i++;
+            }
+        } else {
+            // run-time configuration branch
+            int i = 0;
+            while (i < inputConfigs.length && (value == null || allValues)) {
+                String name = inputConfigs[i].getAttribute("name",null);
+                if (name != null) {
+                    value = getValues(attr, objectModel, null, name, inputConfigs[i]);
+                    if (emptyAsNull && value != null && value.length == 0) value = null;
+                    if (emptyAsNull && value != null && value.length == 1 && 
+                        value[0] instanceof String && value[0].equals("")) value = null;
+                    if (debug) getLogger().debug("read from "+name+" attribute "+attr+" as "+value);
+                    if (allValues && value != null) values.addAll(Arrays.asList(value));
+                }
+                i++;
+            }
+        }
+        if (debug) getLogger().debug("result chaining for "+attr+" is "+(allValues? values.toArray() : value));
+        return (allValues? values.toArray() : value);
+    }
+
+    private void addIterator(Collection col, Iterator iter) {
+        while (iter != null && iter.hasNext())
+            col.add(iter.next());
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        if (!this.initialized) {
+            this.lazy_initialize();
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration[] inputConfigs = null;
+        boolean emptyAsNull = this.emptyAsNull;
+        boolean allNames = this.allNames;
+        if (modeConf!=null && modeConf.getChildren().length > 0) {
+            inputConfigs = modeConf.getChildren("input-module");
+            emptyAsNull = modeConf.getChild("empty-as-null").getValueAsBoolean(emptyAsNull);
+            allNames = modeConf.getChild("all-names").getValueAsBoolean(allNames);
+            if (inputConfigs.length == 0) inputConfigs = null;
+        }
+
+        Iterator value = null;
+        Collection values = null;
+        if (allNames) values = new ArrayList();
+        boolean debug = getLogger().isDebugEnabled();
+
+        if (inputConfigs == null) {
+            // static configuration branch
+            int i = 0;
+            while (i < this.inputs.length && (value == null || allNames)) {
+                if (this.inputs[i].name != null) {
+                    value = getNames(objectModel, this.inputs[i].input, this.inputs[i].name, this.inputs[i].config);
+                    if (debug) getLogger().debug("read from "+this.inputs[i].name+" AttributeNames as "+value);
+                    if (allNames && value != null) addIterator(values, value);
+                }
+                i++;
+            }
+        } else {
+            // run-time configuration branch
+            int i = 0;
+            while (i < inputConfigs.length && value == null) {
+                String name = inputConfigs[i].getAttribute("name",null);
+                if (name != null) {
+                    value = getNames(objectModel, null, name, inputConfigs[i]);
+                    if (debug) getLogger().debug("read from "+name+" AttributeNames as "+value);
+                    if (allNames && value != null) addIterator(values, value);
+                }
+                i++;
+            }
+        }
+        if (debug) getLogger().debug("result chaining names is "+(allNames? values.iterator() : value));
+        return (allNames? values.iterator() : value);
+     }
+
+
+    public Object getAttribute( String attr, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        Object[] values = this.getAttributeValues(attr,modeConf,objectModel);
+        if (getLogger().isDebugEnabled()) getLogger().debug("result chaining single for "+attr+" is "+(values != null? values[0] : "null"));
+        return (values != null? values[0] : null);
+    }
+
+
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ContextPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ContextPathModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ContextPathModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/ContextPathModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,135 @@
+/*
+ * 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.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.source.SourceResolver;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * ContextPathModule 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. Compared to
+ * the {@link RealPathModule} this module is able to provide the "real" absolute 
+ * path even if the application is mounted outside the webapp tree of Cocoon.
+ * <p>
+ * 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:
+ * </p>
+ * <p>
+ * A absolute path argument like {contextpath:/resources} will be resolved  
+ * from the root context path (ie. COCOON_HOME/build/webapp) whereas a relative
+ * path attribute like {contextpath:./resources} will be resolved from the
+ * location of the sitemap that uses it. If that sitemap is mounted outside the
+ * usual COCOON_HOME/build/webapp the path resolved with this modules points to
+ * the correct location.
+ * </p>
+ * <p>
+ * <pre>
+ * <map:transform src="skins/{forrest:skin}/xslt/fo/document2fo.xsl">
+ *    <map:parameter name="basedir" value="{contextpath: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>
+ *  </pre>
+ *  </p>
+ *
+ * @author <a href="mailto:giacomo at apache dor org">Giacomo Pati</a>
+ * @version $Id: ContextPathModule.java 292282 2005-09-28 19:54:16Z vgritsenko $
+ */
+public class ContextPathModule extends AbstractInputModule implements Serviceable, ThreadSafe {
+
+    private ServiceManager m_manager;
+    private SourceResolver m_resolver;
+
+    final  static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("contextPath");
+        returnNames = tmp;
+    }
+
+        /** (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;
+        }
+    }
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+        try {
+            if(name.startsWith("/")) {
+                return m_resolver.resolveURI("context:/"+name).getURI().substring("file:".length());
+            }
+            return m_resolver.resolveURI(name).getURI().substring("file:".length());
+        } catch( final IOException mue ) {
+            throw new ConfigurationException( "Cannot resolve realpath", mue);
+        }
+    }
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return ContextPathModule.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/ContextPathModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/CookieModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/CookieModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/CookieModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/CookieModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2004-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 java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+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.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.http.HttpCookie;
+
+/**
+ * Input module for cookies. Retrieves the value of the requested cookie.
+ * 
+ * @author Jon Evans <jon.evans@misgl.com>
+ * @version CVS $Id: CookieModule.java 292282 2005-09-28 19:54:16Z vgritsenko $
+ */
+public class CookieModule extends AbstractInputModule implements ThreadSafe {
+    
+    /**
+     * @return the value of the cookie whose name matches the one requested,
+     * or <code>null</code> if there is no match.
+     */
+    public Object getAttribute(String name, Configuration modeConf,
+            Map objectModel) throws ConfigurationException {
+        
+        HttpCookie cookie = (HttpCookie) getCookieMap(objectModel).get(name);
+        String value = (cookie == null ? null : cookie.getValue());
+        
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Cookie[" + name + "]=" + value);
+        }
+        return value;
+    }
+
+    /*
+     * (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 getCookieMap(objectModel).keySet().iterator();
+    }
+
+    /*
+     * (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 {
+        
+        Map allCookies = getCookieMap(objectModel);
+        
+        Iterator it = allCookies.values().iterator();
+        List matched = new LinkedList();
+        while (it.hasNext()) {
+            HttpCookie cookie = (HttpCookie) it.next();
+            if (cookie.getName().matches(name)) {
+                matched.add(cookie.getValue());
+            }
+        }
+        return matched.toArray();
+    }
+
+    /**
+     * @param objectModel
+     *            Object Model for the current request
+     * @return a Map of {see: HttpCookie}s for the current request, keyed on
+     *         cookie name.
+     */
+    protected Map getCookieMap(Map objectModel) {
+        return ObjectModelHelper.getRequest(objectModel).getCookieMap();
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateInputModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateInputModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateInputModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateInputModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,86 @@
+/*
+ * 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.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ * DateInputModule returns current date, optionally formated as
+ * string. Format given through attribute "format" of configuration
+ * root node or nested &lt;format/&gt; tag on module declaration.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: DateInputModule.java 106642 2004-11-26 07:49:19Z rgoers $
+ * @see java.text.SimpleDateFormat
+ */
+public class DateInputModule extends AbstractInputModule implements ThreadSafe {
+
+    final static Vector returnNames;
+    static {
+        Vector tmp = new Vector();
+        tmp.add("currentDate");
+        returnNames = tmp;
+    }
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException {
+        
+        String format = (String) this.settings.get("format",name);
+        if (modeConf != null) {
+            format = modeConf.getAttribute("format", format);
+            // this is preferred:
+            format = modeConf.getChild("format").getValue(format);
+        }
+
+        if (format==null) {
+            return new Date();
+        } else {
+            try {
+                return new SimpleDateFormat(format).format(new Date());
+            } catch (Exception e) {
+                return new Date();
+            }           
+        }
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException {
+
+        return DateInputModule.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/DateInputModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,152 @@
+/*
+ * 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 java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Parses a date string according to a given format and returns a date
+ * object. Configuration options: element "format" to hold a {@link
+ * java.text.SimpleDateFormat} format string, child element
+ * "input-module" holds InputModule to obtain the string from.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: DateMetaInputModule.java 156968 2005-03-10 17:33:17Z cziegeler $
+ */
+public class DateMetaInputModule extends AbstractMetaModule implements ThreadSafe {
+
+    private String defaultFormat = "yyyy-MM-dd";
+    private DateFormat defaultFormatter = null;
+
+    
+    public void configure(Configuration config) throws ConfigurationException {
+
+        this.inputConf = config.getChild("input-module");
+        this.defaultInput = this.inputConf.getAttribute("name",this.defaultInput);
+        this.defaultFormat = this.inputConf.getAttribute("format",this.defaultFormat);
+        if (this.defaultFormat != null) {
+            this.defaultFormatter = new SimpleDateFormat(this.defaultFormat);
+        }
+    }
+
+
+    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");
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration mConf = null;
+        String inputName=null;
+        String parameter=name;
+        String format=this.defaultFormat;
+        DateFormat formatter=null;
+        if (modeConf!=null) {
+            mConf       = modeConf.getChild("input-module");
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            parameter   = modeConf.getAttribute("parameter",parameter);
+            format      = modeConf.getAttribute("format",format);
+            // preferred:
+            parameter   = modeConf.getChild("parameter").getValue(parameter);
+            format      = modeConf.getChild("format").getValue(format);
+        }
+        if (this.defaultFormat.equals(format)) {
+            formatter = this.defaultFormatter;
+        } else {
+            formatter = new SimpleDateFormat(format);
+        }
+        
+        Object[] values = getValues(parameter, objectModel, 
+                                    this.input, this.defaultInput, this.inputConf,
+                                    null, inputName, mConf);
+        
+        Object[] dates = null;
+        if (values != null) {
+            dates = new Object[values.length];
+            for (int i=0; i<values.length; i++) 
+                try {
+                    dates[i] = formatter.parse(String.valueOf(values[i]));
+                } catch (Exception e) {
+                    if(getLogger().isWarnEnabled()) 
+                        getLogger().warn("Problem: Aquired '"+values[i]+"' from '" + inputName + "' for '"
+                                         +name+"' using format '"+format+"' : "+e.getMessage());
+                }
+        }
+        return dates;
+    }
+
+
+
+
+
+    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");
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration inputConfig = this.inputConf;
+        Configuration mConf = null;
+        String inputName=null;
+        if (modeConf!=null) {
+            mConf       = modeConf.getChild("input-module");
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+        }
+
+        // done reading configuration
+        // setup modules and read values
+        Iterator enumeration = getNames(objectModel,
+                                    this.input, this.defaultInput, inputConfig,
+                                    null, inputName, mConf);
+        return enumeration;
+     }
+
+
+
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        Object[] values = this.getAttributeValues(name,modeConf,objectModel);
+        return (values != null ? values[0] : null);
+    }
+
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DefaultsModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DefaultsModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DefaultsModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DefaultsModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,96 @@
+/*
+ * 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.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Set a number of constants. To override the values with input from
+ * another module, combine this one with the ChainMetaModule and an
+ * arbitrary number of other modules.
+ *
+ * &lt;values&gt;
+ *  &lt;skin&gt;myskin&lt;/skin&gt;
+ *  &lt;base&gt;baseurl&lt;/base&gt;
+ *  ...
+ * &lt;/values&gt;
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: DefaultsModule.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class DefaultsModule extends AbstractLogEnabled
+    implements InputModule, Configurable, ThreadSafe {
+
+    private Map constants = null;
+    
+    public void configure(Configuration config) throws ConfigurationException {
+
+        this.constants = new HashMap();
+        Configuration[] consts = config.getChild("values").getChildren();
+        for (int i=0; i<consts.length; i++) {
+            this.constants.put(consts[i].getName(), consts[i].getValue(""));
+        }
+    }
+
+
+    public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        String parameter=name;
+        Configuration mConf = null;
+        if (modeConf!=null) {
+            mConf       = modeConf.getChild("values");
+        }
+
+        Object[] values = new Object[1];
+        values[0] = (mConf!=null? mConf.getChild(parameter).getValue((String) this.constants.get(parameter)) 
+                     : this.constants.get(parameter));
+        return values;
+    }
+
+
+    public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        SortedSet matchset = new TreeSet(this.constants.keySet());
+        if (modeConf!=null) {
+            Configuration[] consts = modeConf.getChild("values").getChildren();
+            for (int i=0; i<consts.length; i++)
+                matchset.add(consts[i].getName());
+        }
+        return matchset.iterator();
+     }
+
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 
+        throws ConfigurationException {
+
+        Object[] values = this.getAttributeValues(name,modeConf,objectModel);
+        return values[0];
+    }
+
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,331 @@
+/*
+ * 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.util.HashMap;
+
+import java.net.URLEncoder;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.util.Iterator;
+import java.util.Map;
+import java.io.UnsupportedEncodingException;
+
+/** Meta module that obtains values from other module and returns
+ * message digest of value. Very useful for storing and checking
+ * passwords. Input module configured through nested element
+ * "input-module", message digest algorithm, security provider, salt,
+ * and URL encoded output configurable through elements "algorithm",
+ * "provider", "salt", "encode". Defaults are "sha", null, "salt", and
+ * "false". Available value for encode are "none" (returns byte[]),
+ * "string" (return hash as string), "url" (returns url encoded
+ * string), "hex" (returns string of hex values).
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: DigestMetaModule.java 56223 2004-11-01 10:28:54Z cziegeler $
+ */
+public class DigestMetaModule extends AbstractMetaModule implements ThreadSafe {
+
+    private String defaultAlgorithm = "SHA";
+    private String defaultProvider = null;
+    private String defaultSalt = "salt";
+    private String defaultEncode = "false";
+
+    /** output encoding none */
+    static final int ENCODING_NONE = 0;
+    /** output encoding url encoding */
+    static final int ENCODING_STR = 1;
+    /** output encoding hex */
+    static final int ENCODING_URL = 2;
+    /** output encoding hex */
+    static final int ENCODING_HEX = 3;
+
+    private static final HashMap encodingNames;
+    /** setup mapping tables */
+    static {
+        HashMap names = new HashMap();
+        names.put("false", new Integer(ENCODING_NONE));
+        names.put("no", new Integer(ENCODING_NONE));
+        names.put("none", new Integer(ENCODING_NONE));
+        names.put("string", new Integer(ENCODING_STR));
+        names.put("yes", new Integer(ENCODING_URL));
+        names.put("true", new Integer(ENCODING_URL));
+        names.put("hex", new Integer(ENCODING_HEX));
+        encodingNames = names;
+        names = null;
+    }
+
+
+    public void configure(Configuration config) throws ConfigurationException {
+
+        this.inputConf = config.getChild("input-module");
+        this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput);
+
+        this.defaultAlgorithm = this.inputConf.getAttribute("algorithm",this.defaultAlgorithm);
+        this.defaultProvider = this.inputConf.getAttribute("provider",this.defaultProvider);
+        this.defaultSalt = this.inputConf.getAttribute("salt",this.defaultSalt);
+        this.defaultEncode = this.inputConf.getAttribute("encode","false");
+
+        // preferred
+        this.defaultAlgorithm = config.getChild("algorithm").getValue(this.defaultAlgorithm);
+        this.defaultProvider = config.getChild("provider").getValue(this.defaultProvider);
+        this.defaultSalt = config.getChild("salt").getValue(this.defaultSalt);
+        this.defaultEncode = config.getChild("encode").getValue(this.defaultEncode);
+
+        if (encodingNames.get(this.defaultEncode) == null) {
+            if (getLogger().isErrorEnabled())
+                getLogger().error("Requested encoding is unknown: "+this.defaultEncode);
+            this.defaultEncode="false";
+        }
+    }
+
+
+    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;
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration inputConfig = null;
+        String inputName=null;
+        String algorithm = this.defaultAlgorithm;
+        String provider  = this.defaultProvider;
+        String salt  = this.defaultSalt;
+        int encode = ((Integer) encodingNames.get(this.defaultEncode)).intValue();
+        if (modeConf!=null) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+            // read necessary parameters
+            algorithm = modeConf.getAttribute("algorithm", algorithm);
+            provider  = modeConf.getAttribute("provider", provider);
+            salt  = modeConf.getAttribute("salt", salt);
+            encode = ((Integer) encodingNames.get(modeConf.getAttribute("encode", this.defaultEncode))).intValue();
+
+            // preferred
+            algorithm = modeConf.getChild("algorithm").getValue(algorithm);
+            provider  = modeConf.getChild("provider").getValue(provider);
+            salt  = modeConf.getChild("salt").getValue(salt);
+            encode = ((Integer) encodingNames.get(modeConf.getChild("encode").getValue(this.defaultEncode))).intValue();
+        }
+
+
+        Object value = getValue(name, objectModel,
+                                this.input, this.defaultInput, this.inputConf,
+                                null, inputName, inputConfig);
+        
+        if (value != null)
+            try {
+                MessageDigest md = (provider==null ? MessageDigest.getInstance(algorithm) : 
+                                    MessageDigest.getInstance(algorithm,provider));
+                
+                md.update((salt+(value instanceof String? (String)value : value.toString())).getBytes());
+                return encodeByteArray(md.digest(),encode);
+
+            } catch (NoSuchAlgorithmException nsae) {
+                if (getLogger().isWarnEnabled()) 
+                    getLogger().warn("A problem occurred acquiring digest algorithm '" + algorithm 
+                                     + (provider==null?"":"' from '"+provider) +"': " + nsae.getMessage());
+            } catch (NoSuchProviderException nspe) {
+                if (getLogger().isWarnEnabled()) 
+                    getLogger().warn("A problem occurred acquiring digest algorithm '" + algorithm 
+                                     + (provider==null?"":"' from '"+provider) +"': " + nspe.getMessage());
+            }
+
+        return null;        
+    }
+
+
+    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;
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration inputConfig = null;
+        String inputName=null;
+        if (modeConf!=null) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+        }
+
+        Iterator names = getNames(objectModel, 
+                                  this.input, this.defaultInput, this.inputConf, 
+                                  null, inputName, inputConfig);
+        
+        return names;
+
+   }
+
+
+    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;
+        }
+
+        // obtain correct configuration objects
+        // default vs dynamic
+        Configuration inputConfig = null;
+        String inputName=null;
+        String algorithm = this.defaultAlgorithm;
+        String provider  = this.defaultProvider;
+        String salt  = this.defaultSalt;
+        int encode = ((Integer) encodingNames.get(this.defaultEncode)).intValue();
+        if (modeConf!=null) {
+            inputName   = modeConf.getChild("input-module").getAttribute("name",null);
+            if (inputName != null) {
+                inputConfig = modeConf.getChild("input-module");
+            }
+            // read necessary parameters
+            algorithm = modeConf.getAttribute("algorithm", algorithm);
+            provider  = modeConf.getAttribute("provider" , provider );
+            salt  = modeConf.getAttribute("salt" , salt );
+            encode = ((Integer) encodingNames.get(modeConf.getAttribute("encode" , this.defaultEncode))).intValue();
+
+            // preferred
+            algorithm = modeConf.getChild("algorithm").getValue(algorithm);
+            provider  = modeConf.getChild("provider").getValue(provider);
+            salt  = modeConf.getChild("salt").getValue(salt);
+            encode = ((Integer) encodingNames.get(modeConf.getChild("encode").getValue(this.defaultEncode))).intValue();
+        }
+
+        Object[] values = getValues(name, objectModel, 
+                                    this.input, this.defaultInput, this.inputConf, 
+                                    null, inputName, inputConfig);
+        Object[] result = null;
+
+        if (values != null) {
+            try {
+                MessageDigest md = (provider==null ? MessageDigest.getInstance(algorithm) : 
+                                    MessageDigest.getInstance(algorithm,provider));
+                
+                result = new Object[values.length];
+                for (int i=0; i<values.length; i++) {
+                    md.update((salt + (values[i] instanceof String? (String)values[i] : 
+                                       values[i].toString())).getBytes());
+                    result[i] = encodeByteArray(md.digest(), encode);
+                }
+                return result;
+            } catch (NoSuchAlgorithmException nsae) {
+                if (getLogger().isWarnEnabled()) 
+                    getLogger().warn("A problem occurred acquiring digest algorithm '" + algorithm 
+                                     + (provider==null?"":"' from '"+provider) +"': " + nsae.getMessage());
+            } catch (NoSuchProviderException nspe) {
+                if (getLogger().isWarnEnabled()) 
+                    getLogger().warn("A problem occurred acquiring digest algorithm '" + algorithm 
+                                     + (provider==null?"":"' from '"+provider) +"': " + nspe.getMessage());
+            }
+        }
+        return result;
+    }
+
+
+    /**
+     * Create the output representation.
+     * @param b a <code>byte[]</code>
+     * @param encode an <code>int</code>, one of {@link #ENCODING_NONE},{@link #ENCODING_URL},{@link #ENCODING_HEX}
+     * @return an <code>Object</code>
+     */
+    Object encodeByteArray(byte[] b, int encode) {
+        Object result = null;
+        switch(encode) {
+        case ENCODING_HEX:
+            result = byte2Hex(b);
+            break;
+        case ENCODING_STR:
+            try {
+                result = new String(b, "UTF-8");
+            } catch (UnsupportedEncodingException uee) {
+                if (getLogger().isErrorEnabled())
+                    getLogger().error("UTF-8 not supported -- cannot convert message digest to String.");
+            }
+            break;
+        case ENCODING_URL:
+            try {
+                String str = new String(b, "UTF-8");
+                result = URLEncoder.encode(str, "utf-8");
+            } catch (UnsupportedEncodingException uee) {
+                if (getLogger().isErrorEnabled())
+                    getLogger().error("UTF-8 not supported -- cannot convert message digest to String.");
+            }
+            break;
+        case ENCODING_NONE:
+            // nothing to do
+            break;
+        default:
+            // should not happen
+        }
+        return result;
+    }
+
+    /**
+     * Create a hex representation of a byte array.
+     *
+     * @param b a <code>byte[]</code> value
+     * @return a <code>String</code> value
+     */
+    static String byte2Hex ( byte[] b ) {
+        StringBuffer sb = new StringBuffer( b.length * 2 );
+        for ( int i=0 ; i < b.length ; i++ ) {
+            sb.append( hexChar [ ( b[i] & 0xf0 ) >>> 4 ] ) ;
+            sb.append( hexChar [ ( b[i] & 0x0f )       ] ) ;
+        }
+        return sb.toString() ;
+    }
+
+
+    /** 
+     * hex digits lookup table
+     */
+    static char[] hexChar = {
+        '0' , '1' , '2' , '3' ,
+        '4' , '5' , '6' , '7' ,
+        '8' , '9' , 'a' , 'b' ,
+        'c' , 'd' , 'e' , 'f' 
+    };
+
+}

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



Mime
View raw message