haul 2002/10/28 06:43:41
Modified: src/java/org/apache/cocoon/components/modules/input
AbstractJXPathModule.java AbstractMetaModule.java
ChainMetaModule.java DateInputModule.java
DateMetaInputModule.java DefaultsMetaModule.java
DigestMetaModule.java GlobalInputModule.java
HeaderAttributeModule.java InputModule.java
MapMetaModule.java NullInputModule.java
RandomNumberModule.java RequestAttributeModule.java
RequestContextPathModule.java
RequestParameterModule.java RequestURIModule.java
SessionAttributeModule.java
StringConstantModule.java XMLMetaModule.java
src/java/org/apache/cocoon/acting/modular TestAction.java
src/blocks/databases/java/org/apache/cocoon/components/modules/input
CollectionMetaModule.java
Added: src/java/org/apache/cocoon/components/modules/input
IteratorHelper.java
Log:
Changed InputModule interface to return java.util.Iterator instead of
java.util.Enumeration
Reorganized "meta" modules so less code is duplicated.
Revision Changes Path
1.2 +5 -5
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
Index: AbstractJXPathModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractJXPathModule.java 20 Sep 2002 22:49:50 -0000 1.1
+++ AbstractJXPathModule.java 28 Oct 2002 14:43:40 -0000 1.2
@@ -51,7 +51,7 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -96,7 +96,7 @@
}
}
- public Enumeration getAttributeNames(Configuration modeConf, Map
objectModel)
+ public Iterator getAttributeNames(Configuration modeConf, Map
objectModel)
throws ConfigurationException {
Object contextObj = getContextObject(modeConf, objectModel);
@@ -104,11 +104,11 @@
JXPathBeanInfo info = JXPathIntrospector.getBeanInfo(
contextObj.getClass());
java.beans.PropertyDescriptor[] properties =
info.getPropertyDescriptors();
- java.util.Vector names = new java.util.Vector();
+ java.util.List names = new java.util.LinkedList();
for (int i = 0; i < properties.length; i++) {
names.add(properties[i].getName());
}
- return names.elements();
+ return (java.util.Iterator) names.listIterator();
} catch (Exception e) {
throw new ConfigurationException(
"Error retrieving attribute names for class: "
1.2 +248 -23
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
Index: AbstractMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractMetaModule.java 18 Oct 2002 14:05:32 -0000 1.1
+++ AbstractMetaModule.java 28 Oct 2002 14:43:40 -0000 1.2
@@ -62,6 +62,8 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
/**
* AbstractMetaModule gives you the infrastructure for easily
@@ -78,11 +80,31 @@
/** The component manager instance */
protected ComponentManager manager;
- String INPUT_MODULE_ROLE = InputModule.ROLE;
- String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
-
+ /** The cached InputModule-Selector */
protected ComponentSelector inputSelector = null;
+ /** The cached default InputModule */
+ protected InputModule input = null;
+
+ /** The default InputModule name / shorthand. Defaults to
'request-param' */
+ protected String defaultInput = "request-param"; // default to request
parameters
+
+ /** The default InputModule configuration */
+ protected Configuration inputConf = null; // will become an empty
configuration object
+ // during configure() so why
bother here...
+
+ /** Is this instance initialized? */
+ protected boolean initialized = false;
+
+ /* Constants */
+
+ protected final static String INPUT_MODULE_SELECTOR =
InputModule.ROLE+"Selector";
+
+ /* Operation codes */
+ private final static int OP_GET = 0;
+ private final static int OP_VALUES = 1;
+ private final static int OP_NAMES = 2;
+
/**
* Set the current <code>ComponentManager</code> instance used by this
@@ -95,37 +117,240 @@
/**
- * Obtain a reference to an InputModule.
+ * Initialize the meta module with exactly one other input
+ * module. Override this method and dispose() to keep references
+ * to more than one module.
+ */
+ public void initialize() {
+
+ try {
+ // obtain input modules
+ this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+ if (this.inputSelector != null && this.inputSelector instanceof
ThreadSafe) {
+
+ if (this.defaultInput != null)
+ this.input = obtainModule(this.defaultInput);
+
+ } else if (!(this.inputSelector instanceof ThreadSafe) ) {
+ this.manager.release(this.inputSelector);
+ this.inputSelector = null;
+ }
+
+ this.initialized = true;
+
+ } catch (Exception e) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred setting up input
modules :'" + e.getMessage());
+ }
+ }
+
+
+ /**
+ * Dispose exactly one cached InputModule. To work on more than
+ * one, override this method and initialize().
+ */
+ public void dispose() {
+
+ if (!this.initialized)
+ if (getLogger().isErrorEnabled())
+ getLogger().error("Uninitialized Component! FAILING");
+ else
+ if (this.inputSelector != null) {
+ if (this.input != null)
+ this.inputSelector.release(this.input);
+ this.manager.release(this.inputSelector);
+ }
+ }
+
+
+ /**
+ * Obtain a permanent reference to an InputModule.
*/
protected InputModule obtainModule(String type) {
-
+ ComponentSelector inputSelector = this.inputSelector;
InputModule module = null;
try {
- if (type != null && this.inputSelector.hasComponent(type)){
- module = (InputModule) this.inputSelector.select(type);
+ if (inputSelector == null)
+ inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+
+ if (inputSelector.hasComponent(type)){
+
+ if (type != null && inputSelector.hasComponent(type))
+ module = (InputModule) inputSelector.select(type);
+
if (!(module instanceof ThreadSafe) ) {
- this.inputSelector.release(module);
+ inputSelector.release(module);
module = null;
}
- } else {
- if (type != null)
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
type
- +"': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(type)?"known":"unknown"));
}
+ if (type != null && module == null)
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred setting up '" + type
+ +"': Selector is
"+(inputSelector!=null?"not ":"")
+ +"null, Component is "
+ +(inputSelector!=null &&
inputSelector.hasComponent(type)?"known":"unknown"));
+
} catch (ComponentException ce) {
- if (getLogger().isWarnEnabled()) {
- getLogger().warn("A problem occurred setting up '" + type
- +"': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(type)?"known":"unknown"));
- getLogger().warn(ce.getMessage());
- }
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("Could not obtain selector for
InputModules: "+ce.getMessage());
+ } finally {
+ if (this.inputSelector == null)
+ this.manager.release(inputSelector);
+ // FIXME: Is it OK to keep a reference to the module when we
release the selector?
}
+
return module;
}
+
+
+ /**
+ * release a permanent reference to an InputModule.
+ */
+ protected void releaseModule(InputModule module) {
+ ComponentSelector inputSelector = this.inputSelector;
+ if (module != null) {
+ try {
+ // FIXME: Is it OK to release a module when we have released
the selector before?
+ if (inputSelector == null)
+ inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+
+ inputSelector.release(module);
+ module = null;
+
+ } catch (ComponentException ce) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("Could not obtain selector for
InputModules: "+ce.getMessage());
+ } finally {
+ if (this.inputSelector == null)
+ this.manager.release(inputSelector);
+ }
+ }
+ }
+
+
+ protected Iterator getNames(Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf) {
+
+ return (Iterator) this.get(OP_NAMES, null, objectModel, modA,
modAName, modAConf, null, null, null);
+ }
+
+ /**
+ * If two modules are specified, the second one is used if the name is
not null.
+ */
+ protected Iterator getNames(Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf,
+ InputModule modB, String modBName,
Configuration modBConf) {
+
+ return (Iterator) this.get(OP_NAMES, null, objectModel, modA,
modAName, modAConf, modB, modBName, modBConf);
+ }
+
+
+ protected Object getValue(String attr, Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf) {
+
+ return this.get(OP_GET, attr, objectModel, modA, modAName, modAConf,
null, null, null);
+ }
+
+
+ /**
+ * If two modules are specified, the second one is used if the name is
not null.
+ */
+ protected Object getValue(String attr, Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf,
+ InputModule modB, String modBName,
Configuration modBConf) {
+
+ return this.get(OP_GET, attr, objectModel, modA, modAName, modAConf,
modB, modBName, modBConf);
+ }
+
+
+ protected Object[] getValues(String attr, Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf) {
+
+ return (Object[]) this.get(OP_VALUES, attr, objectModel, modA,
modAName, modAConf, null, null, null);
+ }
+
+
+ /**
+ * If two modules are specified, the second one is used if the name is
not null.
+ */
+ protected Object[] getValues(String attr, Map objectModel,
+ InputModule modA, String modAName,
Configuration modAConf,
+ InputModule modB, String modBName,
Configuration modBConf) {
+
+ return (Object[]) this.get(OP_VALUES, attr, objectModel, modA,
modAName, modAConf, modB, modBName, modBConf);
+ }
+
+
+ /**
+ * Capsules use of an InputModule. Does all the lookups and so
+ * on. Returns either an Object, an Object[], or an Iterator,
+ * depending on the method called i.e. the op specified. The
+ * second module is preferred and has an non null name. If an
+ * exception is encountered, a warn message is printed and null is
+ * returned.
+ */
+ private Object get(int op, String attr, Map objectModel,
+ InputModule modA, String modAName, Configuration
modAConf,
+ InputModule modB, String modBName, Configuration
modBConf) {
+
+ ComponentSelector cs = this.inputSelector;
+ Object value = null;
+ String name = null;
+ InputModule input = null;
+ Configuration conf = null;
+ boolean release = false;
+
+ try {
+
+ if (cs == null)
+ cs = (ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+
+ if (modB == null) {
+ input = modA;
+ name = modAName;
+ conf = modAConf;
+ } else {
+ input = modB;
+ name = modBName;
+ conf = modBConf;
+ }
+
+ if (input == null) {
+ if (cs.hasComponent(name)) {
+ release = true;
+ input = (InputModule) cs.select(name);
+ } else {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("No such InputModule: "+name);
+ }
+ }
+
+ switch (op) {
+ case OP_GET:
+ value = input.getAttribute(attr, conf, objectModel);
+ break;
+ case OP_VALUES:
+ value = input.getAttributeValues(attr, conf, objectModel);
+ break;
+ case OP_NAMES:
+ value = input.getAttributeNames(conf, objectModel);
+ break;
+ };
+
+ } catch (Exception e) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem obtaining a value from "+name+"
occurred : "+e.getMessage());
+ } finally {
+ if (release)
+ cs.release(input);
+
+ if (this.inputSelector == null)
+ this.manager.release(cs);
+ }
+
+ return value;
+ }
+
}
1.2 +15 -42
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java
Index: ChainMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChainMetaModule.java 18 Oct 2002 14:05:32 -0000 1.1
+++ ChainMetaModule.java 28 Oct 2002 14:43:40 -0000 1.2
@@ -53,18 +53,13 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.modules.input.InputModule;
-
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Enumeration;
import java.util.Iterator;
/**
* This modules allows to "chain" several other modules. If a module
@@ -217,14 +212,7 @@
int i = 0;
while (i < this.inputs.length && (value == null || allValues)) {
if (this.inputs[i].name != null) {
- InputModule input = this.inputs[i].input;
- if (input == null) {
- input = obtainModule(this.inputs[i].name);
- value = input.getAttributeValues(attr,
this.inputs[i].config, objectModel);
- this.inputSelector.release(input);
- } else {
- value = input.getAttributeValues(attr,
this.inputs[i].config, objectModel);
- }
+ value = getValues(attr, objectModel,
this.inputs[i].input, this.inputs[i].name, this.inputs[i].config);
if (emptyAsNull && value != null && value.length == 0)
value = null;
if (emptyAsNull && value != null && value.length == 1 &&
value[0] instanceof String &&
((String)value[0]).equals("")) value = null;
@@ -238,10 +226,8 @@
int i = 0;
while (i < inputConfigs.length && (value == null || allValues)) {
String name = inputConfigs[i].getAttribute("name",null);
- if (this.inputs[i].name != null) {
- InputModule input = obtainModule(name);
- value = input.getAttributeValues(attr, inputConfigs[i],
objectModel);
- this.inputSelector.release(input);
+ if (name != null) {
+ value = getValues(attr, objectModel, null, name,
inputConfigs[i]);
if (emptyAsNull && value != null && value.length == 0)
value = null;
if (emptyAsNull && value != null && value.length == 1 &&
value[0] instanceof String &&
((String)value[0]).equals("")) value = null;
@@ -254,17 +240,13 @@
return (allValues? values.toArray() : value);
}
-
- /** kludge - will be removed when getAttributeNames() returns
java.util.Iterator */
- private void addEnumeration(Collection col, Enumeration enum) {
- while (enum.hasMoreElements()) {
- col.add(enum.nextElement());
- }
+ private void addIterator(Collection col, Iterator iter) {
+ while (iter != null && iter.hasNext())
+ col.add(iter.next());
}
-
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
@@ -285,7 +267,7 @@
allNames =
modeConf.getChild("all-names").getValueAsBoolean(allNames);
}
- Enumeration value = null;
+ Iterator value = null;
Collection values = null;
if (allNames) values = new ArrayList();
boolean debug = getLogger().isDebugEnabled();
@@ -295,16 +277,9 @@
int i = 0;
while (i < this.inputs.length && (value == null || allNames)) {
if (this.inputs[i].name != null) {
- InputModule input = this.inputs[i].input;
- if (input == null) {
- input = obtainModule(this.inputs[i].name);
- value =
input.getAttributeNames(this.inputs[i].config, objectModel);
- this.inputSelector.release(input);
- } else {
- value =
input.getAttributeNames(this.inputs[i].config, objectModel);
- }
+ value = getNames(objectModel, this.inputs[i].input,
this.inputs[i].name, this.inputs[i].config);
if (debug) getLogger().debug("read from
"+this.inputs[i].name+" AttributeNames as "+value);
- if (allNames && value != null) addEnumeration(values,
value);
+ if (allNames && value != null) addIterator(values,
value);
}
i++;
}
@@ -313,17 +288,15 @@
int i = 0;
while (i < inputConfigs.length && value == null) {
String name = inputConfigs[i].getAttribute("name",null);
- if (this.inputs[i].name != null) {
- InputModule input = obtainModule(name);
- value = input.getAttributeNames(inputConfigs[i],
objectModel);
- this.inputSelector.release(input);
+ if (name != null) {
+ value = getNames(objectModel, null, name,
inputConfigs[i]);
if (debug) getLogger().debug("read from "+name+"
AttributeNames as "+value);
- if (allNames && value != null) addEnumeration(values,
value);
+ if (allNames && value != null) addIterator(values,
value);
}
i++;
}
}
- return (allNames? new EnumerationHelper(values.iterator()) : value);
+ return (allNames? values.iterator() : value);
}
1.5 +11 -6
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateInputModule.java
Index: DateInputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateInputModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DateInputModule.java 18 Oct 2002 15:59:08 -0000 1.4
+++ DateInputModule.java 28 Oct 2002 14:43:40 -0000 1.5
@@ -51,10 +51,10 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
-import java.util.StringTokenizer;
+import java.util.Vector;
import java.util.Date;
import java.util.Map;
import java.text.SimpleDateFormat;
@@ -74,7 +74,12 @@
*/
public class DateInputModule extends AbstractInputModule implements
ThreadSafe {
- final static Enumeration returnNames = new
StringTokenizer("stringConstant");
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("currentDate");
+ returnNames = tmp;
+ }
public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {
@@ -91,9 +96,9 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
- return DateInputModule.returnNames;
+ return DateInputModule.returnNames.iterator();
}
1.2 +25 -224
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java
Index: DateMetaInputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DateMetaInputModule.java 18 Oct 2002 14:05:32 -0000 1.1
+++ DateMetaInputModule.java 28 Oct 2002 14:43:40 -0000 1.2
@@ -51,29 +51,12 @@
package org.apache.cocoon.components.modules.input;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.modules.input.InputModule;
-
-import org.apache.cocoon.matching.AbstractWildcardMatcher;
-
-import java.util.ArrayList;
import java.util.Map;
-import java.util.HashMap;
-import java.util.Enumeration;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.Iterator;
+
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -83,35 +66,11 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class DateMetaInputModule extends AbstractLogEnabled
- implements InputModule, Configurable, Initializable, Composable,
Disposable {
+public class DateMetaInputModule extends AbstractMetaModule {
- /** The component manager instance */
- protected ComponentManager manager;
-
- private String defaultInput = null;
- private Configuration inputConf = null; // will become an empty
configuration object
- // during configure() so why
bother here...
- String INPUT_MODULE_ROLE = InputModule.ROLE;
- String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
-
- private boolean initialized = false;
- private InputModule input = null;
- private ComponentSelector inputSelector = null;
private String defaultFormat = "yyyy-MM-dd";
private DateFormat defaultFormatter = null;
-
- /**
- * Set the current <code>ComponentManager</code> instance used by this
- * <code>Composable</code>.
- */
- public void compose(ComponentManager manager) throws ComponentException {
-
- this.manager=manager;
- }
-
-
public void configure(Configuration config) throws
ConfigurationException {
@@ -124,57 +83,6 @@
}
-
- public void initialize() {
-
- try {
- // obtain input module
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null &&
- this.inputSelector != null &&
- this.inputSelector.hasComponent(this.defaultInput)
- ){
- this.input = (InputModule)
this.inputSelector.select(this.defaultInput);
- if (!(this.input instanceof ThreadSafe && this.inputSelector
instanceof ThreadSafe) ) {
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- this.input = null;
- this.inputSelector = null;
- }
- this.initialized = true;
- } else {
- if (this.defaultInput != null)
- if (getLogger().isErrorEnabled())
- getLogger().error("A problem occurred setting up '"
+ this.defaultInput
- +"': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
- this.initialized = true;
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
this.defaultInput + "': " + e.getMessage());
- }
- }
-
-
-
- public void dispose() {
-
- if (!this.initialized)
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- else
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
- }
-
-
-
-
public Object[] getAttributeValues( String name, Configuration modeConf,
Map objectModel )
throws ConfigurationException {
@@ -210,87 +118,31 @@
} else {
formatter = new SimpleDateFormat(format);
}
-
- // done reading configuration
- // setup modules and read values
- Object[] values = null;
- try {
- if (this.defaultInput != null || inputName != null) {
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- values =
input.getAttributeValues(parameter,this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (inputName != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule)
iputSelector.select(inputName);
- }
- if (iput != null) {
- values = iput.getAttributeValues(parameter,
inputConfig, objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
value from '"
- + inputName + "' for
'"+name+"': " + e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
-
+
+ Object[] values = getValues(parameter, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, mConf);
+
+ Object[] dates = null;
+ if (values != null) {
+ dates = new Object[values.length];
+ for (int i=0; i<values.length; i++)
+ try {
+ dates[i] = formatter.parse(String.valueOf(values[i]));
+ } catch (Exception e) {
+ if(getLogger().isWarnEnabled())
+ getLogger().warn("Problem: Aquired '"+values[i]+"'
from '" + inputName + "' for '"
+ +name+"' using format '"+format+"'
: "+e.getMessage());
}
- }
-
- // done reading values
- // start converting values and assemble array
-
- Object[] dates = null;
- if (values != null) {
- dates = new Object[values.length];
- for (int i=0; i<values.length; i++)
- try {
- dates[i] =
formatter.parse(String.valueOf(values[i]));
- } catch (Exception e) {
- if(getLogger().isWarnEnabled())
- getLogger().warn("Problem: Aquired
'"+values[i]+"' from '" + inputName + "' for '"
- +name+"' using format
'"+format+"' : "+e.getMessage());
- }
- }
- return dates;
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+name+"': " + e.getMessage());
}
- return null;
+ return dates;
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -318,61 +170,10 @@
// done reading configuration
// setup modules and read values
- Enumeration enum = null;
- try {
- if (this.defaultInput != null || inputName != null) {
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- enum =
input.getAttributeNames(this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule)
iputSelector.select(inputName);
- }
- if (iput != null) {
- enum = iput.getAttributeNames(inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring
names from '"
- + inputName + "' : " +
e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
-
- }
- }
- return enum;
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring names from '"
+ inputName
- + "' : " + e.getMessage());
- }
- return null;
+ Iterator enum = getNames(objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, mConf);
+ return enum;
}
1.5 +4 -4
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DefaultsMetaModule.java
Index: DefaultsMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DefaultsMetaModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultsMetaModule.java 18 Oct 2002 14:29:21 -0000 1.4
+++ DefaultsMetaModule.java 28 Oct 2002 14:43:40 -0000 1.5
@@ -69,7 +69,7 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -277,7 +277,7 @@
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -300,7 +300,7 @@
for (int i=0; i<consts.length; i++)
matchset.add(consts[i].getName());
}
- return new EnumerationHelper(matchset.iterator());
+ return matchset.iterator();
}
1.6 +59 -305
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
Index: DigestMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DigestMetaModule.java 18 Oct 2002 14:29:21 -0000 1.5
+++ DigestMetaModule.java 28 Oct 2002 14:43:40 -0000 1.6
@@ -50,35 +50,17 @@
*/
package org.apache.cocoon.components.modules.input;
-
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-
-import org.apache.cocoon.components.modules.input.InputModule;
-
-import org.apache.cocoon.matching.AbstractWildcardMatcher;
import java.net.URLEncoder;
-import java.util.ArrayList;
import java.util.Map;
-import java.util.Enumeration;
import java.util.Iterator;
-import java.util.SortedSet;
-import java.util.TreeSet;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
/** Meta module that obtains values from other module and returns
* message digest of value. Very useful for storing and checking
@@ -91,21 +73,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class DigestMetaModule extends AbstractLogEnabled
- implements InputModule, Configurable, Initializable, Composable,
Disposable {
-
- /** The component manager instance */
- protected ComponentManager manager;
-
- private String defaultInput = "request-param"; // default to request
parameters
- private Configuration inputConf = null; // will become an empty
configuration object
- // during configure() so why
bother here...
- String INPUT_MODULE_ROLE = InputModule.ROLE;
- String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
-
- private boolean initialized = false;
- private InputModule input = null;
- private ComponentSelector inputSelector = null;
+public class DigestMetaModule extends AbstractMetaModule {
private String defaultAlgorithm = "SHA";
private String defaultProvider = null;
@@ -113,17 +81,6 @@
private boolean defaultEncode = false;
- /**
- * Set the current <code>ComponentManager</code> instance used by this
- * <code>Composable</code>.
- */
- public void compose(ComponentManager manager) throws ComponentException {
-
- this.manager=manager;
- }
-
-
-
public void configure(Configuration config) throws
ConfigurationException {
this.inputConf = config.getChild("input-module");
@@ -134,55 +91,6 @@
}
-
- public void initialize() {
-
- try {
- // obtain input module
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null &&
- this.inputSelector != null &&
- this.inputSelector.hasComponent(this.defaultInput)
- ){
- this.input = (InputModule)
this.inputSelector.select(this.defaultInput);
- if (!(this.input instanceof ThreadSafe && this.inputSelector
instanceof ThreadSafe) ) {
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- this.input = null;
- this.inputSelector = null;
- }
- this.initialized = true;
- } else {
- if (getLogger().isErrorEnabled())
- getLogger().error("A problem occurred setting up '" +
this.defaultInput
- + "': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
this.defaultInput + "': " + e.getMessage());
- }
- }
-
-
-
- public void dispose() {
-
- if (!this.initialized)
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- else
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
- }
-
-
-
-
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
@@ -214,82 +122,33 @@
String salt = modeConf.getAttribute("salt" ,this.defaultSalt );
boolean encode = modeConf.getAttributeAsBoolean("encode"
,this.defaultEncode );
- // done reading configuration
- // setup modules and read values
- Object result = null;
- try {
- Object value = null;
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- value = input.getAttribute(name,this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- if (iput != null) {
- value = iput.getAttribute(name, inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
value from '"
- + inputName + "' for '"+name+"': "
+ e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
+ Object result = null;
+ Object value = getValue(name, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, inputConfig);
+
+ if (value != null)
+ try {
+ MessageDigest md = (provider==null ?
MessageDigest.getInstance(algorithm) :
+
MessageDigest.getInstance(algorithm,provider));
+
+ md.update((salt+(value instanceof String? (String)value :
value.toString())).getBytes());
+ if (encode) {
+ return URLEncoder.encode(new String(md.digest()));
+ } else {
+ return md.digest();
+ }
+ } catch (NoSuchAlgorithmException nsae) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred acquiring digest
algorithm '" + algorithm
+ + (provider==null?"":"' from
'"+provider) +"': " + nsae.getMessage());
+ } catch (NoSuchProviderException nspe) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred acquiring digest
algorithm '" + algorithm
+ + (provider==null?"":"' from
'"+provider) +"': " + nspe.getMessage());
}
-
- // done reading value
- // get message digest implementation and compute hash
-
- if (value != null) {
-
- try {
- MessageDigest md = (provider==null ?
MessageDigest.getInstance(algorithm) :
-
MessageDigest.getInstance(algorithm,provider));
-
- md.update((salt+(value instanceof String? (String)value
: value.toString())).getBytes());
- if (encode) {
- return URLEncoder.encode(new String(md.digest()));
- } else {
- return md.digest();
- }
- } catch (NoSuchAlgorithmException nsae) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring
digest algorithm '" + algorithm
- + (provider==null?"":"' from
'"+provider) +"': " + nsae.getMessage());
- }
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+name+"': " + e.getMessage());
- }
+
return null;
}
@@ -297,7 +156,7 @@
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -322,68 +181,12 @@
}
}
- // read necessary parameters
-
- // done reading configuration
- // setup modules and read values
- Object result = null;
- try {
- Enumeration names = null;
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- names = input.getAttributeNames(this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- if (iput != null) {
- names = iput.getAttributeNames(inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
names from '"
- + inputName + "': " +
e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
+ Iterator names = getNames(objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, inputConfig);
+
+ return names;
- }
-
- // done reading value
-
- return names;
-
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring names from '"
+ inputName
- + "' : " + e.getMessage());
- }
- return null;
}
@@ -420,87 +223,38 @@
String salt = modeConf.getAttribute("salt" ,this.defaultSalt );
boolean encode = modeConf.getAttributeAsBoolean("encode"
,this.defaultEncode );
- // done reading configuration
- // setup modules and read values
+ Object[] values = getValues(name, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, inputConfig);
Object[] result = null;
- try {
- Object[] values = null;
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- values =
input.getAttributeValues(name,this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- if (iput != null) {
- values = iput.getAttributeValues(name, inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
value from '"
- + inputName + "' for '"+name+"': "
+ e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
- }
-
- // done reading value
- // get message digest implementation and compute hash
-
- if (values != null) {
- try {
- MessageDigest md = (provider==null ?
MessageDigest.getInstance(algorithm) :
-
MessageDigest.getInstance(algorithm,provider));
-
- result = new Object[values.length];
- for (int i=0; i<values.length; i++) {
- md.update((salt + (values[i] instanceof String?
(String)values[i] :
- values[i].toString())).getBytes());
- if (encode) {
- result[i] = URLEncoder.encode(new
String(md.digest()));
- } else {
- result[i] = md.digest();
- }
+ if (values != null) {
+ try {
+ MessageDigest md = (provider==null ?
MessageDigest.getInstance(algorithm) :
+
MessageDigest.getInstance(algorithm,provider));
+
+ result = new Object[values.length];
+ for (int i=0; i<values.length; i++) {
+ md.update((salt + (values[i] instanceof String?
(String)values[i] :
+ values[i].toString())).getBytes());
+ if (encode) {
+ result[i] = URLEncoder.encode(new
String(md.digest()));
+ } else {
+ result[i] = md.digest();
}
- } catch (NoSuchAlgorithmException nsae) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring
digest algorithm '" + algorithm
- + (provider==null?"":"' from
'"+provider) +"': " + nsae.getMessage());
}
return result;
+ } catch (NoSuchAlgorithmException nsae) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred acquiring digest
algorithm '" + algorithm
+ + (provider==null?"":"' from
'"+provider) +"': " + nsae.getMessage());
+ } catch (NoSuchProviderException nspe) {
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("A problem occurred acquiring digest
algorithm '" + algorithm
+ + (provider==null?"":"' from
'"+provider) +"': " + nspe.getMessage());
}
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+name+"': " + e.getMessage());
}
- return null;
+ return result;
}
}
1.3 +4 -4
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java
Index: GlobalInputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/GlobalInputModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GlobalInputModule.java 9 Oct 2002 06:39:24 -0000 1.2
+++ GlobalInputModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -58,7 +58,7 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Map;
/**
@@ -111,14 +111,14 @@
/**
- * Returns an Enumeration of String objects containing the names
+ * Returns an Iterator of String objects containing the names
* of the attributes available. If no attributes are available,
- * the method returns an empty Enumeration.
+ * the method returns an empty Iterator.
* @param modeConf column's mode configuration from resource
* description. This argument is optional.
* @param objectModel
*/
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
SitemapVariableHolder holder = null;
try {
1.3 +4 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/HeaderAttributeModule.java
Index: HeaderAttributeModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/HeaderAttributeModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HeaderAttributeModule.java 28 May 2002 13:41:28 -0000 1.2
+++ HeaderAttributeModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -52,6 +52,7 @@
package org.apache.cocoon.components.modules.input;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
@@ -84,10 +85,10 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- return ObjectModelHelper.getRequest(objectModel).getHeaderNames();
+ return new
IteratorHelper(ObjectModelHelper.getRequest(objectModel).getHeaderNames());
}
1.6 +5 -5
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/InputModule.java
Index: InputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/InputModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InputModule.java 12 Aug 2002 07:50:53 -0000 1.5
+++ InputModule.java 28 Oct 2002 14:43:40 -0000 1.6
@@ -52,7 +52,7 @@
package org.apache.cocoon.components.modules.input;
import java.util.SortedSet;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
@@ -90,14 +90,14 @@
/**
- * Returns an Enumeration of String objects containing the names
+ * Returns an Iterator of String objects containing the names
* of the attributes available. If no attributes are available,
- * the method returns an empty Enumeration.
+ * the method returns an empty Iterator.
* @param modeConf column's mode configuration from resource
* description. This argument is optional.
* @param objectModel
*/
- Enumeration getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException;
+ Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException;
/**
1.4 +14 -190
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/MapMetaModule.java
Index: MapMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/MapMetaModule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MapMetaModule.java 18 Oct 2002 14:29:21 -0000 1.3
+++ MapMetaModule.java 28 Oct 2002 14:43:40 -0000 1.4
@@ -50,27 +50,11 @@
*/
package org.apache.cocoon.components.modules.input;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-
-import org.apache.cocoon.components.modules.input.InputModule;
-
-import org.apache.cocoon.matching.AbstractWildcardMatcher;
-
-import java.net.URLEncoder;
import java.util.Map;
-import java.util.Enumeration;
+import java.util.Iterator;
/**
* Meta module that obtains an Object from another module, assumes
@@ -83,37 +67,14 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class MapMetaModule extends AbstractLogEnabled
- implements InputModule, Configurable, Initializable, Composable,
Disposable {
-
- /** The component manager instance */
- protected ComponentManager manager;
-
- protected String defaultInput = "request-attr"; // default to request
attributes
- protected Configuration inputConf = null; // will become an empty
configuration object
- // during configure() so why
bother here...
- protected String INPUT_MODULE_ROLE = InputModule.ROLE;
- protected String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
+public class MapMetaModule extends AbstractMetaModule {
private boolean initialized = false;
- protected InputModule input = null;
- protected ComponentSelector inputSelector = null;
protected String objectName = null;
protected String parameter = null;
- /**
- * Set the current <code>ComponentManager</code> instance used by this
- * <code>Composable</code>.
- */
- public void compose(ComponentManager manager) throws ComponentException {
-
- this.manager=manager;
- }
-
-
-
public void configure(Configuration config) throws
ConfigurationException {
this.inputConf = config.getChild("input-module");
@@ -122,54 +83,6 @@
}
- public void initialize() {
-
- try {
- // obtain input module
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null &&
- this.inputSelector != null &&
- this.inputSelector.hasComponent(this.defaultInput)
- ){
- this.input = (InputModule)
this.inputSelector.select(this.defaultInput);
- if (!(this.input instanceof ThreadSafe && this.inputSelector
instanceof ThreadSafe) ) {
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- this.input = null;
- this.inputSelector = null;
- }
- this.initialized = true;
- } else {
- if (getLogger().isErrorEnabled())
- getLogger().error("A problem occurred setting up '" +
this.defaultInput
- + "': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
this.defaultInput + "': " + e.getMessage());
- }
- }
-
-
-
- public void dispose() {
-
- if (!this.initialized)
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- else
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
- }
-
-
-
-
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
@@ -200,56 +113,12 @@
}
parameter = (parameter != null? parameter : name);
- // done reading configuration
- // setup modules and read values
- InputModule iput = this.input;
- ComponentSelector iputSelector = null;
- StringBuffer sb = new StringBuffer();
- Object value = null;
- try {
- if (this.input != null && inputName == null) {
- // thread safe input module
- // use existing reference
- iput = this.input;
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- iputSelector = null;
- iput = null;
-
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- }
- if (iput != null) {
- value = iput.getAttribute(objectName, inputConfig,
objectModel);
- value = (value!=null? ((Map) value).get(parameter) : null);
- }
-
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+name+"': " + e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
+ Object value = getValue(objectName, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, modeConf);
+
+ value = (value!=null? ((Map) value).get(parameter) : null);
+
return value;
}
@@ -257,7 +126,7 @@
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -284,55 +153,10 @@
}
}
- // done reading configuration
- // setup modules and read values
- InputModule iput = this.input;
- ComponentSelector iputSelector = null;
- StringBuffer sb = new StringBuffer();
- Enumeration keys = null;
- try {
- if (this.input != null && inputName == null) {
- // thread safe input module
- // use existing reference
- iput = this.input;
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- iputSelector = null;
- iput = null;
-
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- }
- if (iput != null) {
- keys = new EnumerationHelper(((Map)
iput.getAttribute(objectName, inputConfig, objectModel)).keySet().iterator());
- }
-
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a names from
'" + inputName
- + "' " + e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
+ Iterator keys = ((Map) getValue(objectName, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName,
inputConfig)).keySet().iterator();
+
return keys;
}
1.3 +3 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/NullInputModule.java
Index: NullInputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/NullInputModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NullInputModule.java 28 May 2002 13:41:28 -0000 1.2
+++ NullInputModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -51,7 +51,7 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.StringTokenizer;
@@ -79,7 +79,7 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
return null;
}
1.4 +11 -5
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java
Index: RandomNumberModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RandomNumberModule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RandomNumberModule.java 18 Oct 2002 14:29:21 -0000 1.3
+++ RandomNumberModule.java 28 Oct 2002 14:43:40 -0000 1.4
@@ -51,11 +51,12 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Map;
+import java.util.Vector;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Component;
@@ -72,7 +73,12 @@
*/
public class RandomNumberModule extends AbstractInputModule implements
ThreadSafe {
- final static Enumeration returnNames = new
StringTokenizer("stringConstant");
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("randomNumber");
+ returnNames = tmp;
+ }
public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {
@@ -87,9 +93,9 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
- return RandomNumberModule.returnNames;
+ return RandomNumberModule.returnNames.iterator();
}
1.3 +4 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java
Index: RequestAttributeModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestAttributeModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestAttributeModule.java 28 May 2002 13:41:28 -0000 1.2
+++ RequestAttributeModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -52,6 +52,7 @@
package org.apache.cocoon.components.modules.input;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
@@ -85,10 +86,10 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- return ObjectModelHelper.getRequest(objectModel).getAttributeNames();
+ return new
IteratorHelper(ObjectModelHelper.getRequest(objectModel).getAttributeNames());
}
1.2 +11 -5
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestContextPathModule.java
Index: RequestContextPathModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestContextPathModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestContextPathModule.java 16 Sep 2002 23:28:50 -0000 1.1
+++ RequestContextPathModule.java 28 Oct 2002 14:43:40 -0000 1.2
@@ -51,11 +51,12 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Map;
+import java.util.Vector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.avalon.framework.configuration.Configuration;
@@ -73,7 +74,12 @@
*/
public class RequestContextPathModule extends AbstractInputModule implements
ThreadSafe {
- final static Enumeration returnNames = new
StringTokenizer("contextPath");
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("contextPath");
+ returnNames = tmp;
+ }
public Object getAttribute(String name, Configuration modeConf, Map
objectModel) throws ConfigurationException {
@@ -83,9 +89,9 @@
}
- public Enumeration getAttributeNames(Configuration modeConf, Map
objectModel) throws ConfigurationException {
+ public Iterator getAttributeNames(Configuration modeConf, Map
objectModel) throws ConfigurationException {
- return RequestContextPathModule.returnNames;
+ return RequestContextPathModule.returnNames.iterator();
}
1.3 +4 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java
Index: RequestParameterModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestParameterModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestParameterModule.java 28 May 2002 13:41:28 -0000 1.2
+++ RequestParameterModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -52,6 +52,7 @@
package org.apache.cocoon.components.modules.input;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
@@ -86,9 +87,9 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
- return ObjectModelHelper.getRequest(objectModel).getParameterNames();
+ return new
IteratorHelper(ObjectModelHelper.getRequest(objectModel).getParameterNames());
}
1.3 +12 -7
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestURIModule.java
Index: RequestURIModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/RequestURIModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestURIModule.java 28 May 2002 13:41:28 -0000 1.2
+++ RequestURIModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -51,11 +51,11 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.Map;
import java.util.List;
import java.util.LinkedList;
-import java.util.StringTokenizer;
-import java.util.Map;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.avalon.framework.configuration.Configuration;
@@ -71,7 +71,12 @@
*/
public class RequestURIModule extends AbstractInputModule implements
ThreadSafe {
- final static Enumeration returnNames = new StringTokenizer("requestURI");
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("requestURI");
+ returnNames = tmp;
+ }
public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {
@@ -85,9 +90,9 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
- return RequestURIModule.returnNames;
+ return RequestURIModule.returnNames.iterator();
}
1.3 +4 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java
Index: SessionAttributeModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SessionAttributeModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SessionAttributeModule.java 28 May 2002 13:41:28 -0000 1.2
+++ SessionAttributeModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -52,6 +52,7 @@
package org.apache.cocoon.components.modules.input;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
@@ -86,10 +87,10 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- return
ObjectModelHelper.getRequest(objectModel).getSession().getAttributeNames();
+ return new
IteratorHelper(ObjectModelHelper.getRequest(objectModel).getSession().getAttributeNames());
}
1.3 +11 -5
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/StringConstantModule.java
Index: StringConstantModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/StringConstantModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StringConstantModule.java 28 May 2002 13:41:28 -0000 1.2
+++ StringConstantModule.java 28 Oct 2002 14:43:40 -0000 1.3
@@ -51,8 +51,9 @@
package org.apache.cocoon.components.modules.input;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
+import java.util.Vector;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Map;
@@ -70,7 +71,12 @@
*/
public class StringConstantModule extends AbstractInputModule implements
ThreadSafe {
- final static Enumeration returnNames = new
StringTokenizer("stringConstant");
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("stringConstant");
+ returnNames = tmp;
+ }
public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {
@@ -82,9 +88,9 @@
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
- return StringConstantModule.returnNames;
+ return StringConstantModule.returnNames.iterator();
}
1.4 +38 -152
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLMetaModule.java
Index: XMLMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLMetaModule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLMetaModule.java 18 Oct 2002 14:29:21 -0000 1.3
+++ XMLMetaModule.java 28 Oct 2002 14:43:40 -0000 1.4
@@ -50,28 +50,12 @@
*/
package org.apache.cocoon.components.modules.input;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-
-import org.apache.cocoon.components.modules.input.InputModule;
-
-import org.apache.cocoon.matching.AbstractWildcardMatcher;
-
-import java.net.URLEncoder;
import java.util.Map;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
+import java.util.Iterator;
+import java.util.Vector;
/**
* Meta module that obtains values from other module and returns all
@@ -119,36 +103,18 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class XMLMetaModule extends AbstractLogEnabled
- implements InputModule, Configurable, Initializable, Composable,
Disposable {
-
- /** The component manager instance */
- protected ComponentManager manager;
-
- protected String defaultInput = "request-param"; // default to request
parameters
- protected Configuration inputConf = null; // will become an empty
configuration object
- // during configure() so why
bother here...
- protected String INPUT_MODULE_ROLE = InputModule.ROLE;
- protected String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
-
- private boolean initialized = false;
- protected InputModule input = null;
- protected ComponentSelector inputSelector = null;
+public class XMLMetaModule extends AbstractMetaModule {
protected String rootName = "root";
protected String ignore = null;
protected String use = null;
protected String strip = null;
- final static Enumeration returnNames = new StringTokenizer("XML");
-
- /**
- * Set the current <code>ComponentManager</code> instance used by this
- * <code>Composable</code>.
- */
- public void compose(ComponentManager manager) throws ComponentException {
-
- this.manager=manager;
+ final static Vector returnNames;
+ static {
+ Vector tmp = new Vector();
+ tmp.add("XML");
+ returnNames = tmp;
}
@@ -163,53 +129,7 @@
}
- public void initialize() {
-
- try {
- // obtain input module
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null &&
- this.inputSelector != null &&
- this.inputSelector.hasComponent(this.defaultInput)
- ){
- this.input = (InputModule)
this.inputSelector.select(this.defaultInput);
- if (!(this.input instanceof ThreadSafe && this.inputSelector
instanceof ThreadSafe) ) {
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- this.input = null;
- this.inputSelector = null;
- }
- this.initialized = true;
- } else {
- if (getLogger().isErrorEnabled())
- getLogger().error("A problem occurred setting up '" +
this.defaultInput
- + "': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
this.defaultInput + "': " + e.getMessage());
- }
- }
-
-
- public void dispose() {
-
- if (!this.initialized)
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- else
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
- }
-
-
-
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
@@ -244,74 +164,40 @@
}
}
- // done reading configuration
- // setup modules and read values
- InputModule iput = this.input;
- ComponentSelector iputSelector = null;
+ InputModule input = null;
+ if (inputName != null) input = obtainModule(inputName);
+
StringBuffer sb = new StringBuffer();
sb.append('<').append(rootName).append('>');
- try {
- if (this.input != null && inputName == null) {
- // thread safe input module
- // use existing reference
- iput = this.input;
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- iputSelector = null;
- iput = null;
-
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- }
- if (iput != null) {
- Enumeration names = iput.getAttributeNames(inputConfig,
objectModel);
- while (names.hasMoreElements()){
- String attribute = (String) names.nextElement();
- if ((use == null || attribute.startsWith(use)) &&
- (ignore == null || !attribute.startsWith(ignore))) {
- Object[] values = iput.getAttributeValues(attribute,
inputConfig, objectModel);
- if (strip != null && attribute.startsWith(strip))
- attribute = attribute.substring(strip.length());
- sb.append("<item
name=\"").append(attribute).append("\">");
- if (values.length == 1) {
- sb.append(values[0]);
- } else {
- for (int i=0;i<values.length;i++){
-
sb.append("<value>").append(values[i]).append("</value>");
- }
- }
- sb.append("</item>");
+
+ Iterator names = getNames(objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ input, inputName, inputConfig);
+ while (names.hasNext()){
+ String attribute = (String) names.next();
+ if ((use == null || attribute.startsWith(use)) &&
+ (ignore == null || !attribute.startsWith(ignore))) {
+ Object[] values = getValues(attribute, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ input, inputName, inputConfig);
+
+ if (strip != null && attribute.startsWith(strip))
+ attribute = attribute.substring(strip.length());
+ sb.append("<item name=\"").append(attribute).append("\">");
+ if (values.length == 1) {
+ sb.append(values[0]);
+ } else {
+ for (int i=0;i<values.length;i++){
+
sb.append("<value>").append(values[i]).append("</value>");
}
}
- }
-
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+name+"': " + e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
+ sb.append("</item>");
}
}
+ if (input != null) releaseModule(input);
+
sb.append('<').append('/').append(rootName).append('>');
+
return sb.toString();
}
@@ -319,7 +205,7 @@
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -333,7 +219,7 @@
return null;
}
- return XMLMetaModule.returnNames;
+ return XMLMetaModule.returnNames.iterator();
}
1.1
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/IteratorHelper.java
Index: IteratorHelper.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
[EMAIL PROTECTED]
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 <[EMAIL PROTECTED]>. 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.Iterator;
/**
* Wraps an Enumeration and provides Iterator interface.
*
*/
class IteratorHelper implements Iterator {
Enumeration enum = null;
public IteratorHelper( Enumeration e ) { this.enum = e; }
public boolean hasNext() { return this.enum.hasMoreElements(); }
public Object next() { return this.enum.nextElement(); }
/** ignored */
public void remove() {};
}
1.6 +4 -4
xml-cocoon2/src/java/org/apache/cocoon/acting/modular/TestAction.java
Index: TestAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/TestAction.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestAction.java 21 Oct 2002 07:46:13 -0000 1.5
+++ TestAction.java 28 Oct 2002 14:43:41 -0000 1.6
@@ -70,7 +70,7 @@
import org.apache.cocoon.components.modules.input.InputModule;
import org.apache.cocoon.components.modules.output.OutputModule;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
@@ -149,9 +149,9 @@
if (getLogger().isDebugEnabled())
getLogger().debug("reading all parameter values");
// for a test, read all parameters from input and write
them to outout
// get names first, then (one) value per name
- Enumeration enum =
input.getAttributeNames(this.inputConf,objectModel);
- while (enum.hasMoreElements()) {
- parameterName = (String) enum.nextElement();
+ Iterator iter =
input.getAttributeNames(this.inputConf,objectModel);
+ while (iter.hasNext()) {
+ parameterName = (String) iter.next();
Object value = input.getAttribute(parameterName,
this.inputConf, objectModel);
output.setAttribute(this.outputConf, objectModel,
parameterName, value);
1.2 +56 -250
xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/modules/input/CollectionMetaModule.java
Index: CollectionMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/modules/input/CollectionMetaModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CollectionMetaModule.java 18 Oct 2002 14:04:26 -0000 1.1
+++ CollectionMetaModule.java 28 Oct 2002 14:43:41 -0000 1.2
@@ -50,28 +50,14 @@
*/
package org.apache.cocoon.components.modules.input;
-
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.modules.input.InputModule;
import org.apache.cocoon.util.JDBCTypeConversions;
-import org.apache.cocoon.matching.AbstractWildcardMatcher;
-
import java.util.ArrayList;
import java.util.Map;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -95,37 +81,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class CollectionMetaModule extends AbstractLogEnabled
- implements InputModule, Configurable, Initializable, Composable,
Disposable {
-
- /** The component manager instance */
- protected ComponentManager manager;
+public class CollectionMetaModule extends AbstractMetaModule {
protected Configuration memberConf = null;
- private String defaultInput = "request-param"; // default to request
parameters
- private Configuration inputConf = null; // will become an empty
configuration object
- // during configure() so why
bother here...
- String INPUT_MODULE_ROLE = InputModule.ROLE;
- String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector";
-
- private boolean initialized = false;
- private InputModule input = null;
- private ComponentSelector inputSelector = null;
-
-
-
- /**
- * Set the current <code>ComponentManager</code> instance used by this
- * <code>Composable</code>.
- */
- public void compose(ComponentManager manager) throws ComponentException {
-
- this.manager=manager;
- }
-
-
+
public void configure(Configuration config) throws
ConfigurationException {
this.memberConf = config.getChild("member");
@@ -135,53 +96,6 @@
- public void initialize() {
-
- try {
- // obtain input module
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null &&
- this.inputSelector != null &&
- this.inputSelector.hasComponent(this.defaultInput)
- ){
- this.input = (InputModule)
this.inputSelector.select(this.defaultInput);
- if (!(this.input instanceof ThreadSafe && this.inputSelector
instanceof ThreadSafe) ) {
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- this.input = null;
- this.inputSelector = null;
- }
- this.initialized = true;
- } else {
- if (getLogger().isErrorEnabled())
- getLogger().error("A problem occurred setting up '" +
this.defaultInput
- + "': Selector is
"+(this.inputSelector!=null?"not ":"")
- +"null, Component is "
-
+(this.inputSelector!=null&&this.inputSelector.hasComponent(this.defaultInput)?"known":"unknown"));
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred setting up '" +
this.defaultInput + "': " + e.getMessage());
- }
- }
-
-
-
- public void dispose() {
-
- if (!this.initialized)
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- else
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
- }
-
-
-
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
@@ -226,83 +140,29 @@
getLogger().debug("jType "+jType);
- // done reading configuration
- // setup modules and read values
- Object result = null;
- try {
- Object[] values = null;
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- values =
input.getAttributeValues(pName,this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
-
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- if (iput != null) {
- values = iput.getAttributeValues(pName, inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
value from '"
- + inputName + "' for '"+pName+"': "
+ e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
+ Object[] values = getValues(pName, objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, inputConfig);
+ Object[] objects = null;
- }
+ if (values != null) {
- // done reading values
- // start converting values and assemble array
-
- if (values != null) {
-
- Object[] objects = new Object[values.length];
-
- // FIXME: should put this into helper class
- for (int i = 0; i<values.length; i++) {
- Object value = values[i];
- objects[i] = JDBCTypeConversions.convert(value, jType);
- }
- return objects;
+ objects = new Object[values.length];
+
+ for (int i = 0; i<values.length; i++) {
+ Object value = values[i];
+ objects[i] = JDBCTypeConversions.convert(value, jType);
}
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a value from
'" + inputName
- + "' for '"+pName+"': " + e.getMessage());
}
- return null;
+
+ return objects;
}
- public Enumeration getAttributeNames( Configuration modeConf, Map
objectModel )
+ public Iterator getAttributeNames( Configuration modeConf, Map
objectModel )
throws ConfigurationException {
if (!this.initialized) {
@@ -330,103 +190,49 @@
}
}
- // done reading configuration
- // setup modules and read attribute names
- Object result = null;
- try {
- Enumeration names = null;
- if (this.input != null && inputName == null) {
- // input module is thread safe
- // thus we still have a reference to it
- // and
- // no other module is configured dynamically
- names = input.getAttributeNames(this.inputConf,objectModel);
- } else {
- // input was not thread safe
- // or
- // another module is configured dynamically
- // so acquire it again
- ComponentSelector iputSelector = null;
- InputModule iput = null;
- try {
- // obtain input module
- if (inputName == null) {
- inputName = this.defaultInput;
- inputConfig = this.inputConf;
- }
- iputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.defaultInput != null
- && iputSelector != null
- && iputSelector.hasComponent(inputName)) {
-
- iput = (InputModule) iputSelector.select(inputName);
- }
- if (iput != null) {
- names = iput.getAttributeNames(inputConfig,
objectModel);
- }
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring a
names from '" + inputName + "': " + e.getMessage());
- } finally {
- // release components
- if (iputSelector != null) {
- if (iput != null)
- iputSelector.release(iput);
- this.manager.release(iputSelector);
- }
- }
-
- }
+ Iterator names = getNames(objectModel,
+ this.input, this.defaultInput,
this.inputConf,
+ null, inputName, inputConfig);
+
+ if (names != null) {
+ SortedSet matchset = new TreeSet();
+ String pName = mConf.getAttribute("name");
+ int index = pName.indexOf("*");
+
+ if (index>-1) {
+ // parameter name contains '*'
+ // find all strings that match this '*'
+ // return them in an enumeration
- // done reading names
- // find attribute names matching configuration
- // and return an enumeration
-
- if (names != null) {
- SortedSet matchset = new TreeSet();
- String pName = mConf.getAttribute("name");
- int index = pName.indexOf("*");
-
- if (index>-1) {
- // parameter name contains '*'
- // find all strings that match this '*'
- // return them in an enumeration
-
- String prefix = (index > 0 ? pName.substring(0,index) :
null);
- String suffix = (index < (pName.length() -1) ?
pName.substring(index+1,pName.length()) : null);
-
- while (names.hasMoreElements()) {
- String name = (String)names.nextElement();
- if (name.startsWith(prefix) &&
name.endsWith(suffix)) {
- String wildcard =
name.substring(prefix.length());
- wildcard =
wildcard.substring(0,wildcard.length()-suffix.length());
- matchset.add(wildcard);
- }
- }
- } else {
- // parameter name without wildcard
- // check that name is among available names
- // and return it in that case
- boolean done=false;
- while (!done && names.hasMoreElements()) {
- String name = (String)names.nextElement();
- if (name.equals(pName)) {
- matchset.add(pName);
- done = true;
- }
+ String prefix = (index > 0 ? pName.substring(0,index) :
null);
+ String suffix = (index < (pName.length() -1) ?
pName.substring(index+1,pName.length()) : null);
+
+ while (names.hasNext()) {
+ String name = (String)names.next();
+ if (name.startsWith(prefix) && name.endsWith(suffix)) {
+ String wildcard = name.substring(prefix.length());
+ wildcard =
wildcard.substring(0,wildcard.length()-suffix.length());
+ matchset.add(wildcard);
}
}
- return new EnumerationHelper(matchset.iterator());
} else {
- return null;
+ // parameter name without wildcard
+ // check that name is among available names
+ // and return it in that case
+ boolean done=false;
+ while (!done && names.hasNext()) {
+ String name = (String)names.next();
+ if (name.equals(pName)) {
+ matchset.add(pName);
+ done = true;
+ }
+ }
}
-
- } catch (Exception e) {
- if (getLogger().isWarnEnabled())
- getLogger().warn("A problem occurred acquiring names from '"
+ inputName + "': " + e.getMessage());
+ return matchset.iterator();
+ } else {
+ return null;
}
- return null;
}
@@ -435,10 +241,10 @@
public Object[] getAttributeValues( String name, Configuration modeConf,
Map objectModel )
throws ConfigurationException {
- Enumeration names = this.getAttributeNames( modeConf, objectModel );
+ Iterator names = this.getAttributeNames( modeConf, objectModel );
ArrayList values = new ArrayList();
- while (names.hasMoreElements()) {
- values.add(this.getAttribute((String)
names.nextElement(),modeConf,objectModel));
+ while (names.hasNext()) {
+ values.add(this.getAttribute((String)
names.next(),modeConf,objectModel));
}
return values.toArray();
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]