cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 37203 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input
Date Mon, 30 Aug 2004 14:19:07 GMT
Author: cziegeler
Date: Mon Aug 30 07:19:06 2004
New Revision: 37203

Added:
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/NamingInputModule.java
  (contents, props changed)
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLDecodeModule.java
  (contents, props changed)
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLEncodeModule.java
  (contents, props changed)
Modified:
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/FlowAttributeModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
Log:
Sync input modules

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
Mon Aug 30 07:19:06 2004
@@ -36,7 +36,7 @@
  *
  * @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,v 1.9 2004/04/28 18:13:38 haul Exp $
+ * @version CVS $Id$
  */
 public abstract class AbstractMetaModule extends AbstractInputModule
     implements Composable, Disposable {
@@ -298,7 +298,7 @@
      * 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}).
+     * @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.
      */ 

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/FlowAttributeModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/FlowAttributeModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/FlowAttributeModule.java
Mon Aug 30 07:19:06 2004
@@ -13,7 +13,6 @@
  * 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;
@@ -28,7 +27,7 @@
  * object is not found then an exception will be thrown.
  *
  * @author <a href="mailto:danielf@nada.kth.se">Daniel Fagerstrom</a>
- * @version CVS $Id: FlowAttributeModule.java,v 1.1 2004/04/04 09:43:43 gcasper Exp $
+ * @version CVS $Id$
  */
 public class FlowAttributeModule extends AbstractJXPathModule
     implements ThreadSafe {

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
Mon Aug 30 07:19:06 2004
@@ -32,7 +32,7 @@
  * extended there.
  *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: GlobalInputModule.java,v 1.4 2004/03/05 13:02:48 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public final class GlobalInputModule 
     extends AbstractLogEnabled
@@ -74,7 +74,6 @@
         }
     }
 
-
     /**
      * Returns an Iterator of String objects containing the names
      * of the attributes available. If no attributes are available,
@@ -96,7 +95,6 @@
         }
     }
 
-
     /**
      * Returns an array of String objects containing all of the values
      * the given attribute has, or null if the attribute does not
@@ -119,6 +117,4 @@
         }
         return null;
     }
-
 }
-

Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/NamingInputModule.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/NamingInputModule.java
Mon Aug 30 07:19:06 2004
@@ -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();
+    }
+}

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/PropertiesFileModule.java
Mon Aug 30 07:19:06 2004
@@ -43,15 +43,13 @@
 public class PropertiesFileModule extends AbstractJXPathModule 
 implements InputModule, Serviceable, Configurable, ThreadSafe {
     
-    private ServiceManager m_manager;
-    
-    private SourceResolver m_resolver;
-    
+    private ServiceManager m_manager;    
+    private SourceResolver m_resolver;    
     private Properties m_properties;
     
     
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     * @see Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager manager) throws ServiceException {
         m_manager = manager;
@@ -68,7 +66,8 @@
             this.m_manager = null;
             this.m_resolver = null;
         }
-	}
+    }
+
     /**
      * Configure the location of the properties file:
      * <p>
@@ -89,19 +88,16 @@
             stream = source.getInputStream();
             m_properties = new Properties();
             m_properties.load(stream);
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             throw new ConfigurationException("Cannot load properties file " + file);
-        }
-        finally {
+        } finally {
             if (source != null) {
                 m_resolver.release(source);
             }
             if (stream != null) {
                 try {
                     stream.close();
-                }
-                catch (IOException e) {
+                } catch (IOException ignored) {
                 }
             }
         }
@@ -112,5 +108,4 @@
         
         return m_properties;
     }
-
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
Mon Aug 30 07:19:06 2004
@@ -38,7 +38,7 @@
  * getAttributeValues. Only one "*" is allowed.
  *
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: RequestAttributeModule.java,v 1.3 2004/03/05 13:02:48 bdelacretaz Exp
$
+ * @version CVS $Id$
  */
 public class RequestAttributeModule extends AbstractInputModule implements ThreadSafe {
 
@@ -55,17 +55,19 @@
     }
 
 
+    /* (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 {
-
+    throws ConfigurationException {
         return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getAttributeNames());
     }
 
 
     public Object[] getAttributeValues( String name, Configuration modeConf, Map objectModel
)
-        throws ConfigurationException {
-
-        Request request = ObjectModelHelper.getRequest(objectModel);
+    throws ConfigurationException {
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        
         String wildcard = (String) this.settings.get("parameter",name);
         if ( modeConf != null ) {
             wildcard = modeConf.getAttribute( "parameter", wildcard );

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SelectMetaInputModule.java
Mon Aug 30 07:19:06 2004
@@ -47,7 +47,7 @@
  * </tbody></table>
  * 
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: SelectMetaInputModule.java,v 1.3 2004/04/28 18:15:58 haul Exp $
+ * @version CVS $Id$
  */
 public class SelectMetaInputModule extends AbstractMetaModule implements ThreadSafe {
 
@@ -60,10 +60,9 @@
     	super();
         this.defaultInput = null; // not needed
     }
-    
-    
+        
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
     public void configure(Configuration config) throws ConfigurationException {
 
@@ -93,6 +92,7 @@
                 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");
@@ -101,23 +101,25 @@
                     new ModuleHolder(name, whens[i], null));
             }
         }
-
     }
 
     /* (non-Javadoc)
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(String, Configuration,
Map)
      */
-    public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws
ConfigurationException {
+    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 {
+    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 {
+    private Object getAttribute(String name, Configuration modeConf, Map objectModel, boolean
getValues)
+    throws ConfigurationException {
         if (!this.initialized) {
             this.lazy_initialize();
         }
@@ -209,7 +211,7 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
+     * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
      */
     public void compose(ComponentManager manager) throws ComponentException {
         super.compose(manager);
@@ -240,8 +242,9 @@
      * @see org.apache.cocoon.components.modules.input.AbstractMetaModule#lazy_initialize()
      */
     public synchronized void lazy_initialize() {
-
-        if (this.initialized) return;
+        if (this.initialized) {
+            return;
+        }
 
         super.lazy_initialize();
         
@@ -258,5 +261,4 @@
             }
         }
     }
-
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
Mon Aug 30 07:19:06 2004
@@ -34,7 +34,7 @@
  * sitemap base
  *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: SitemapVariableHolder.java,v 1.6 2004/03/05 13:02:48 bdelacretaz Exp
$
+ * @version CVS $Id$
  */
 public final class SitemapVariableHolder
     extends AbstractLogEnabled
@@ -76,8 +76,7 @@
     /**
      * Set the <code>Configuration</code> from a sitemap
      */
-    public void configure(SitemapConfigurationHolder holder)
-    throws ConfigurationException {
+    public void configure(SitemapConfigurationHolder holder) {
         this.holder = holder;
     }
 
@@ -123,6 +122,4 @@
             }
         }
     }
-    
 }
-

Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLDecodeModule.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLDecodeModule.java
Mon Aug 30 07:19:06 2004
@@ -0,0 +1,51 @@
+/*
+ * 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.UnsupportedEncodingException;
+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.util.NetUtils;
+
+/**
+ * This module provides functionality for converting a String from the
+ * application/x-www-form-urlencoded MIME format. It is useful for example for
+ * calling remote services: <br/>
+ * &lt;map:generate src="http://remote/page?param1={url-encode:{request-param:param1}}"/&gt;<br/>
+ * Module configuration takes only one configuration parameter:
+ * "encoding" which is a target string encoding. This is utf-8 by default.
+ */
+public final class URLDecodeModule extends AbstractInputModule
+                                   implements ThreadSafe {
+
+    public Object getAttribute(String name,
+                               Configuration modeConf,
+                               Map objectModel) throws ConfigurationException {
+        if (name == null) {
+            return null;
+        }
+
+        String encoding = (String) this.settings.get("encoding", "utf-8");
+        try {
+            return NetUtils.decode(name, encoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new ConfigurationException("URLDecodeModule, invalid encoding: " + encoding);
+        }
+    }
+}

Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLEncodeModule.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/URLEncodeModule.java
Mon Aug 30 07:19:06 2004
@@ -0,0 +1,51 @@
+/*
+ * 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.UnsupportedEncodingException;
+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.util.NetUtils;
+
+/**
+ * This module provides functionality for converting a String to the
+ * application/x-www-form-urlencoded MIME format. It is useful for example for
+ * calling remote services: <br/>
+ * &lt;map:generate src="http://remote/page?param1={url-encode:{request-param:param1}}"/&gt;<br/>
+ * Module configuration takes only one configuration parameter:
+ * "encoding" which is a target string encoding. This is utf-8 by default.
+ */
+public final class URLEncodeModule extends AbstractInputModule
+                                   implements ThreadSafe {
+
+    public Object getAttribute(String name,
+                               Configuration modeConf,
+                               Map objectModel) throws ConfigurationException {
+        if (name == null) {
+            return null;
+        }
+
+        String encoding = (String) this.settings.get("encoding", "utf-8");
+        try {
+            return NetUtils.encode(name, encoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new ConfigurationException("URLEncodeModule, invalid encoding: " + encoding);
+        }
+    }
+}

Mime
View raw message