vgritsenko 2004/07/06 19:37:01
Modified: src/java/org/apache/cocoon/components/modules/input
GlobalInputModule.java SitemapVariableHolder.java
src/webapp/samples sitemap.xmap
src/webapp/samples/modules menu.xml sitemap.xmap
Log:
Add demo for GlobalInputModule
Revision Changes Path
1.5 +12 -16
cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
Index: GlobalInputModule.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GlobalInputModule.java 5 Mar 2004 13:02:48 -0000 1.4
+++ GlobalInputModule.java 7 Jul 2004 02:37:01 -0000 1.5
@@ -1,12 +1,12 @@
/*
* 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.
@@ -34,19 +34,19 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-public final class GlobalInputModule
+public final class GlobalInputModule
extends AbstractLogEnabled
implements InputModule, Serviceable, ThreadSafe {
private ServiceManager manager;
-
+
/**
* Serviceable
*/
public void service(ServiceManager manager) {
this.manager = manager;
}
-
+
/**
* Standard access to an attribute's value. If more than one value
* exists, the first is returned. If the value does not exist,
@@ -61,12 +61,12 @@
* description. This argument is optional.
* @param objectModel
*/
- public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
+ public Object getAttribute(String name, Configuration modeConf, Map
objectModel)
throws ConfigurationException {
SitemapVariableHolder holder = null;
try {
holder =
(SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
- return holder.get(name);
+ return holder.get(name);
} catch (ServiceException ce) {
throw new ConfigurationException("Unable to lookup
SitemapVariableHolder.", ce);
} finally {
@@ -74,7 +74,6 @@
}
}
-
/**
* Returns an Iterator of String objects containing the names
* of the attributes available. If no attributes are available,
@@ -83,12 +82,12 @@
* description. This argument is optional.
* @param objectModel
*/
- public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames(Configuration modeConf, Map
objectModel)
throws ConfigurationException {
SitemapVariableHolder holder = null;
try {
holder =
(SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
- return holder.getKeys();
+ return holder.getKeys();
} catch (ServiceException ce) {
throw new ConfigurationException("Unable to lookup
SitemapVariableHolder.", ce);
} finally {
@@ -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
@@ -111,7 +109,7 @@
* description. This argument is optional.
* @param objectModel
*/
- public Object[] getAttributeValues( String name, Configuration modeConf,
Map objectModel )
+ public Object[] getAttributeValues(String name, Configuration modeConf,
Map objectModel)
throws ConfigurationException {
Object o = this.getAttribute(name, modeConf, objectModel);
if (o != null) {
@@ -119,6 +117,4 @@
}
return null;
}
-
}
-
1.7 +16 -19
cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
Index: SitemapVariableHolder.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SitemapVariableHolder.java 5 Mar 2004 13:02:48 -0000 1.6
+++ SitemapVariableHolder.java 7 Jul 2004 02:37:01 -0000 1.7
@@ -1,12 +1,12 @@
/*
* 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.
@@ -40,9 +40,9 @@
extends AbstractLogEnabled
implements Component, Configurable, SitemapConfigurable, ThreadSafe
{
-
+
public static final String ROLE = SitemapVariableHolder.class.getName();
-
+
/**
* Stores (global) configuration parameters as <code>key</code> /
* <code>value</code> pairs from the component configuration
@@ -62,7 +62,7 @@
*
* For nested configurations override this function.
* */
- public void configure(Configuration conf)
+ public void configure(Configuration conf)
throws ConfigurationException {
final Configuration[] parameters = conf.getChildren();
this.globalValues = new HashMap(parameters.length);
@@ -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;
}
@@ -87,42 +86,40 @@
public Object get(String key) {
return this.getValues().get(key);
}
-
+
/**
* Get keys
*/
public Iterator getKeys() {
return this.getValues().keySet().iterator();
}
-
+
protected Map getValues() {
Map values = (Map)this.holder.getPreparedConfiguration();
- if ( null == values ) {
+ if (null == values) {
values = new HashMap(this.globalValues);
ChainedConfiguration conf = this.holder.getConfiguration();
- if ( conf != null ) {
+ if (conf != null) {
this.prepare(conf, values);
this.holder.setPreparedConfiguration(conf, values);
}
}
return values;
}
-
+
protected void prepare(ChainedConfiguration conf, Map values) {
ChainedConfiguration parent = conf.getParent();
- if ( null != parent) {
+ if (null != parent) {
this.prepare(parent, values);
}
final Configuration[] parameters = conf.getChildren();
final int len = parameters.length;
- for ( int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) {
final String key = parameters[i].getName();
final String value = parameters[i].getValue("");
- if ( key != null && value != null) {
+ if (key != null && value != null) {
values.put(key, value);
}
}
}
-
}
-
1.28 +11 -1 cocoon-2.1/src/webapp/samples/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/sitemap.xmap,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- sitemap.xmap 11 Jun 2004 21:38:10 -0000 1.27
+++ sitemap.xmap 7 Jul 2004 02:37:01 -0000 1.28
@@ -48,6 +48,16 @@
<!-- ========================== Pipelines ================================
-->
<map:pipelines>
+ <map:component-configurations>
+ <global-variables>
+ <!--+
+ | Define global parameters, used in the input modules
GlobalInputModule demo.
+ +-->
+ <global-sitemap>This value is defined in the
samples/sitemap.xmap</global-sitemap>
+ <global-sitemap-override>This value is defined in the
samples/sitemap.xmap, should be overridden by
samples/modules/sitemap.xmap</global-sitemap-override>
+ </global-variables>
+ </map:component-configurations>
+
<map:pipeline>
<map:match pattern="">
<map:generate src="samples.xml"/>
1.13 +1 -0 cocoon-2.1/src/webapp/samples/modules/menu.xml
Index: menu.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/modules/menu.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- menu.xml 16 Jun 2004 20:00:07 -0000 1.12
+++ menu.xml 7 Jul 2004 02:37:01 -0000 1.13
@@ -41,6 +41,7 @@
<menu-item label="URLEncodeModule" href="url-encode.html"
desc="URLEncode passed parameter"/>
<menu-item label="URLDecodeModule" href="url-decode.html"
desc="URLDecode passed parameter"/>
<menu-item label="NamingInputModule" href="naming.html" desc="JNDI
Resources. This sample does not work with built-in Jetty as it does not provide
JNDI."/>
+ <menu-item label="GlobalInputModule" href="global.html" desc="Access to
the global variables defined in the sitemap."/>
</menu>
<menu label="Documentation">
1.13 +25 -1 cocoon-2.1/src/webapp/samples/modules/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/modules/sitemap.xmap,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- sitemap.xmap 16 Jun 2004 20:00:07 -0000 1.12
+++ sitemap.xmap 7 Jul 2004 02:37:01 -0000 1.13
@@ -40,6 +40,16 @@
<!-- =========================== Pipelines
================================= -->
<map:pipelines>
+ <map:component-configurations>
+ <global-variables>
+ <!--+
+ | (Re)Define global parameters, used in the input modules
GlobalInputModule demo.
+ +-->
+ <global-sub-sitemap>This value is defined in the
samples/modules/sitemap.xmap</global-sub-sitemap>
+ <global-sitemap-override>This value was defined in the
samples/sitemap.xmap, but was overridden by
samples/modules/sitemap.xmap</global-sitemap-override>
+ </global-variables>
+ </map:component-configurations>
+
<map:pipeline>
<!-- Default URL matcher. Matches '/' URLs-->
@@ -358,6 +368,20 @@
<map:serialize/>
</map:match>
+ <map:match pattern="content/global.xml">
+ <map:generate type="jx" src="properties.xml">
+ <map:parameter name="global-sitemap"
value="{global:global-sitemap}"/>
+ <map:parameter name="global-sub-sitemap"
value="{global:global-sub-sitemap}"/>
+ <map:parameter name="global-sitemap-override"
value="{global:global-sitemap-override}"/>
+ </map:generate>
+ <map:transform src="properties2html.xsl">
+ <map:parameter name="title" value="Global Input Module
(GlobalInputModule)"/>
+ <map:parameter name="description" value="GlobalInputModule
+ contains 'global' values defined in the sitemap. Children
sitemaps
+ can override values defined in the parent sitemap."/>
+ </map:transform>
+ <map:serialize/>
+ </map:match>
<!-- Display this sitemap source-->
<map:match pattern="sitemap.xmap">