You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2007/02/14 00:07:49 UTC
svn commit: r507289 - in
/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main:
java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java
resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf
Author: danielf
Date: Tue Feb 13 15:07:48 2007
New Revision: 507289
URL: http://svn.apache.org/viewvc?view=rev&rev=507289
Log:
StringConcatMetaModule concats strings from configured module chain. It assumes that all modules have string attributes, on the contrary, it calls toString() method.
If null is returned by some module RuntimeException will be thrown.
Contributed by Grzegorz Kossakowski, https://issues.apache.org/jira/browse/COCOON-1996.
Added:
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java (with props)
Modified:
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf
Added: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java?view=auto&rev=507289
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java (added)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java Tue Feb 13 15:07:48 2007
@@ -0,0 +1,77 @@
+package org.apache.cocoon.components.modules.input;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+/**
+ * <p>StringConcatMetaModule concats strings from configured module chain. It assumes that all modules have string attributes, on the contrary, it calls toString() method.<br>
+ * If null is returned by some module {@link RuntimeException} will be thrown.</p>
+ * <p>For configuration of input module chain take a look at example on {@link ChainMetaModule}.</p>
+ */
+public class StringConcatMetaModule extends AbstractMetaModule {
+
+ private ModuleHolder[] inputs;
+
+ public StringConcatMetaModule() {
+ this.defaultInput = null;
+ }
+
+ /**
+ * @param configurations
+ * List of configuration objects for input modules
+ * @return List of {@link ModuleHolder} objects obtained from
+ * configurations. If configuration does not have {@code name}
+ * attribute it will be skipped and error logged.
+ * @throws ConfigurationException
+ */
+ protected ModuleHolder[] getFilteredInputModules(Configuration[] configurations) throws ConfigurationException {
+ ModuleHolder[] moduleList = new ModuleHolder[configurations.length];
+ int j = 0;
+ for (int i = 0; i < configurations.length; i++) {
+ if (configurations[i].getAttribute("name", null) == null) {
+ if (getLogger().isErrorEnabled())
+ getLogger().error("No name attribute for module configuration. Skipping.");
+ continue;
+ }
+ moduleList[j] = new ModuleHolder(configurations[i].getAttribute("name"), configurations[i]);
+ j++;
+ }
+ return moduleList;
+ }
+
+ /**
+ * @param dynamicConfigurations
+ * @return It returns list of modules. If {@code dynamicConfigurations} does
+ * not contain valid list of configuration (e.g. is null) then
+ * static list is returned. In other case list is obtained from
+ * dynamicConfigurations.
+ * @throws ConfigurationException
+ */
+ protected ModuleHolder[] getInputModules(Configuration[] dynamicConfigurations) throws ConfigurationException {
+ return (dynamicConfigurations != null && dynamicConfigurations.length != 0) ? getFilteredInputModules(dynamicConfigurations) : inputs;
+ }
+
+ /**
+ * @see org.apache.cocoon.components.modules.input.AbstractInputModule#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ this.inputs = getFilteredInputModules(config.getChildren("input-module"));
+ }
+
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ ModuleHolder[] inputModules = getInputModules(modeConf != null ? modeConf.getChildren("input-module") : null);
+ Object rawValue;
+ String value = "";
+
+ for (int i = 0; i < inputModules.length; i++) {
+ rawValue = getValue(name, objectModel, inputModules[i]);
+ if (rawValue == null)
+ throw new RuntimeException("Module " + inputModules[i].name + "returned null as attribute " + name);
+ value = value + rawValue;
+ }
+
+ return value;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/StringConcatMetaModule.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf?view=diff&rev=507289&r1=507288&r2=507289
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-modules-input.xconf Tue Feb 13 15:07:48 2007
@@ -64,6 +64,7 @@
<component-instance logger="core.modules.input" name="cookie" class="org.apache.cocoon.components.modules.input.CookieModule"/>
<component-instance logger="core.modules.input" name="system-property" class="org.apache.cocoon.components.modules.input.SystemPropertyModule"/>
<component-instance logger="core.modules.input" name="constant" class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
+ <component-instance logger="core.modules.input" name="concat" class="org.apache.cocoon.components.modules.input.StringConcatMetaModule"/>
<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">