You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by kp...@apache.org on 2002/09/21 00:49:51 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/modules modules.xconf
kpiroumian 2002/09/20 15:49:51
Modified: src/java/org/apache/cocoon/components/modules modules.xconf
Added: src/java/org/apache/cocoon/components/modules/input
AbstractJXPathModule.java RequestModule.java
SessionModule.java
Log:
Input modules for Request and Session properties.
Implementation is based on JXPath therefore XPath
expressions are also supported.
Revision Changes Path
1.1 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
Index: AbstractJXPathModule.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components.modules.input;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.Context;
import org.apache.commons.jxpath.*;
import org.apache.commons.jxpath.servlet.*;
/**
* 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.
*
* @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
* @version $Id: AbstractJXPathModule.java,v 1.1 2002/09/20 22:49:50 kpiroumian Exp $
*/
public abstract class AbstractJXPathModule extends AbstractInputModule
implements ThreadSafe {
public Object getAttribute(String name, Configuration modeConf,
Map objectModel)
throws ConfigurationException {
try {
Object contextObj = getContextObject(modeConf, objectModel);
JXPathContext jxContext = JXPathContext.newContext(contextObj);
return jxContext.getValue(name);
} catch (Exception e) {
throw new ConfigurationException(
"Module does not support <" + name + ">" + "attribute.",
e
);
}
}
public Enumeration getAttributeNames(Configuration modeConf, Map objectModel)
throws ConfigurationException {
Object contextObj = getContextObject(modeConf, objectModel);
try {
JXPathBeanInfo info = JXPathIntrospector.getBeanInfo(
contextObj.getClass());
java.beans.PropertyDescriptor[] properties = info.getPropertyDescriptors();
java.util.Vector names = new java.util.Vector();
for (int i = 0; i < properties.length; i++) {
names.add(properties[i].getName());
}
return names.elements();
} catch (Exception e) {
throw new ConfigurationException(
"Error retrieving attribute names for class: "
+ contextObj.getClass(),
e
);
}
}
public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
try {
Object contextObj = getContextObject(modeConf, objectModel);
JXPathContext jxContext = JXPathContext.newContext(contextObj);
List values = new LinkedList();
Iterator i = jxContext.iterate(name);
while (i.hasNext()) {
values.add(i.next());
}
return values.toArray();
} catch (Exception e) {
throw new ConfigurationException(
"Module does not support <" + name + ">" + "attribute.",
e
);
}
}
/**
* 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);
}
1.1 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestModule.java
Index: RequestModule.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components.modules.input;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.environment.ObjectModelHelper;
/**
* RequestModule provides access to Request object properties.
* To get access to request properties use XPath syntax, e.g. to get the request
* context path use <code>'contextPath'</code> as the attribute name.<br/>
* More complex expressions are also supported, e.g.:
* <pre>
* 'userPrincipal/name'
* </pre>
* will return the name property of the Principal object returned by the
* request.getUserPrincipal() method. If requested object is not found then
* an exception will be thrown.
*
* @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
* @version $Id: RequestModule.java,v 1.1 2002/09/20 22:49:50 kpiroumian Exp $
*/
public class RequestModule extends AbstractJXPathModule
implements ThreadSafe {
protected Object getContextObject(Configuration modeConf,
Map objectModel) {
return ObjectModelHelper.getRequest(objectModel);
}
}
1.1 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SessionModule.java
Index: SessionModule.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components.modules.input;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.environment.ObjectModelHelper;
/**
* SessionModule provides access to Session object properties.
* To get access to session properties use XPath syntax, e.g. to get the session
* id use <code>'id'</code> as the attribute name.<br/>
* More complex expressions with functions are also supported, e.g.:
* <pre>
* 'substring(id, 8)'
* </pre>
* will return the substring of id property of the session object.
* <strong>NOTE:</strong> The module does not create a new session.
*
* @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
* @version $Id: SessionModule.java,v 1.1 2002/09/20 22:49:50 kpiroumian Exp $
*/
public class SessionModule extends AbstractJXPathModule
implements ThreadSafe {
protected Object getContextObject(Configuration modeConf,
Map objectModel) {
return ObjectModelHelper.getRequest(objectModel).getSession();
}
}
1.6 +18 -17 xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf
Index: modules.xconf
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- modules.xconf 9 Aug 2002 08:32:10 -0000 1.5
+++ modules.xconf 20 Sep 2002 22:49:50 -0000 1.6
@@ -4,21 +4,22 @@
<!-- =============== Sitemap In/Out/Database Modules ==================== -->
<input-modules>
- <component-instance logger="core.modules.input" name="request" class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
- <component-instance logger="core.modules.input" name="attribute" class="org.apache.cocoon.components.modules.input.RequestAttributeModule"/>
- <component-instance logger="core.modules.input" name="URI" class="org.apache.cocoon.components.modules.input.RequestURIModule"/>
- <component-instance logger="core.modules.input" name="header" class="org.apache.cocoon.components.modules.input.HeaderAttributeModule"/>
- <component-instance logger="core.modules.input" name="session" class="org.apache.cocoon.components.modules.input.SessionAttributeModule"/>
- <component-instance logger="core.modules.input" name="constant" class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
- <component-instance logger="core.modules.input" name="random" class="org.apache.cocoon.components.modules.input.RandomNumberModule"/>
- <component-instance logger="core.modules.input" name="digest" class="org.apache.cocoon.components.modules.input.DigestMetaModule"/>
- <component-instance logger="core.modules.input" name="date" class="org.apache.cocoon.components.modules.input.DateInputModule"/>
- <component-instance logger="core.modules.input" name="nullinput" class="org.apache.cocoon.components.modules.input.NullInputModule"/>
- <component-instance logger="core.modules.input" name="collection" class="org.apache.cocoon.components.modules.input.CollectionMetaModule"/>
- <component-instance logger="core.modules.input" name="xmlmeta" class="org.apache.cocoon.components.modules.input.XMLMetaModule"/>
- <component-instance logger="core.modules.input" name="mapmeta" class="org.apache.cocoon.components.modules.input.MapMetaModule"/>
- <component-instance logger="core.modules.input" name="defaults" class="org.apache.cocoon.components.modules.input.DefaultsMetaModule">
- <input-module name="request"/>
+ <component-instance logger="core.modules.input" name="request" class="org.apache.cocoon.components.modules.input.RequestModule"/>
+ <component-instance logger="core.modules.input" name="session" class="org.apache.cocoon.components.modules.input.SessionModule"/>
+ <component-instance logger="core.modules.input" name="request-param" class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
+ <component-instance logger="core.modules.input" name="request-attr" class="org.apache.cocoon.components.modules.input.RequestAttributeModule"/>
+ <component-instance logger="core.modules.input" name="request-header" class="org.apache.cocoon.components.modules.input.HeaderAttributeModule"/>
+ <component-instance logger="core.modules.input" name="session-attr" class="org.apache.cocoon.components.modules.input.SessionAttributeModule"/>
+ <component-instance logger="core.modules.input" name="constant" class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
+ <component-instance logger="core.modules.input" name="random" class="org.apache.cocoon.components.modules.input.RandomNumberModule"/>
+ <component-instance logger="core.modules.input" name="digest" class="org.apache.cocoon.components.modules.input.DigestMetaModule"/>
+ <component-instance logger="core.modules.input" name="date" class="org.apache.cocoon.components.modules.input.DateInputModule"/>
+ <component-instance logger="core.modules.input" name="nullinput" class="org.apache.cocoon.components.modules.input.NullInputModule"/>
+ <component-instance logger="core.modules.input" name="collection" class="org.apache.cocoon.components.modules.input.CollectionMetaModule"/>
+ <component-instance logger="core.modules.input" name="xmlmeta" class="org.apache.cocoon.components.modules.input.XMLMetaModule"/>
+ <component-instance logger="core.modules.input" name="mapmeta" class="org.apache.cocoon.components.modules.input.MapMetaModule"/>
+ <component-instance logger="core.modules.input" name="defaults" class="org.apache.cocoon.components.modules.input.DefaultsMetaModule">
+ <input-module name="request-param"/>
<values>
<skin>defaultSkin</skin>
<base-url>http://localhost:8080/cocoon</base-url>
@@ -27,8 +28,8 @@
</input-modules>
<output-modules>
- <component-instance logger="core.modules.output" name="attribute" class="org.apache.cocoon.components.modules.output.RequestAttributeOutputModule"/>
- <component-instance logger="core.modules.output" name="session" class="org.apache.cocoon.components.modules.output.SessionAttributeOutputModule"/>
+ <component-instance logger="core.modules.output" name="request-attr" class="org.apache.cocoon.components.modules.output.RequestAttributeOutputModule"/>
+ <component-instance logger="core.modules.output" name="session-attr" class="org.apache.cocoon.components.modules.output.SessionAttributeOutputModule"/>
</output-modules>
<autoincrement-modules>
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org