Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 25128 invoked from network); 30 Aug 2004 14:19:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 30 Aug 2004 14:19:12 -0000 Received: (qmail 63191 invoked by uid 500); 30 Aug 2004 14:19:11 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 63021 invoked by uid 500); 30 Aug 2004 14:19:09 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 63007 invoked by uid 99); 30 Aug 2004 14:19:09 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Mon, 30 Aug 2004 07:19:08 -0700 Received: (qmail 25040 invoked by uid 65534); 30 Aug 2004 14:19:07 -0000 Date: 30 Aug 2004 14:19:07 -0000 Message-ID: <20040830141907.25035.qmail@minotaur.apache.org> From: cziegeler@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 37203 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 Christian Haul * @author Jeff Turner - * @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 op 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 Daniel Fagerstrom - * @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 Carsten Ziegeler - * @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. + * + *

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.

+ * + *

Example module configuration when connecting to external WebLogic server: + *

+ *   <java.naming.factory.initial>weblogic.jndi.WLInitialContextFactory</java.naming.factory.initial>
+ *   <java.naming.provider.url>t3://localhost:7001</java.naming.provider.url>
+ * 
+ * + *

Example usage: + *

+ *   <map:generate src="{naming:java:comp/env/greeting}"/>
+ * 
+ * This lookups greeting entry from the environment of the webapp. + * Webapp's web.xml should define this entry: + *
+ *   <env-entry>
+ *     <env-entry-name>greeting</env-entry-name>
+ *     <env-entry-value>Hello, World</env-entry-value>
+ *     <env-entry-type>java.lang.String</env-entry-type>
+ *   </env-entry>
+ * 
+ * + * @author Vadim Gritsenko + * @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 name 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: *

@@ -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 Christian Haul - * @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 @@ * * * @author Christian Haul - * @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 Carsten Ziegeler - * @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 Configuration 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:
+ * <map:generate src="http://remote/page?param1={url-encode:{request-param:param1}}"/>
+ * 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:
+ * <map:generate src="http://remote/page?param1={url-encode:{request-param:param1}}"/>
+ * 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); + } + } +}