org.apache.cocoon.components.modules.input
public class: SimpleMappingMetaModule [javadoc |
source]
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.components.modules.input.AbstractInputModule
org.apache.cocoon.components.modules.input.AbstractMetaModule
org.apache.cocoon.components.modules.input.SimpleMappingMetaModule
All Implemented Interfaces:
org.apache.avalon.framework.thread.ThreadSafe, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, InputModule, org.apache.avalon.framework.configuration.Configurable
Meta module that obtains values from an other module and by
replacing the requested attribute name with another name. This is
done first through a replacement table and may additionally prepend
or append a string. Replacement works in both ways, it is applied
to the returned attribute names as well.
Example configuration:
<prefix>cocoon.</prefix>
<suffix>.attr</suffix>
<mapping in="foo" out="bar"/>
<mapping in="yuk" out="yeeha"/>
Will map a parameter "foo" to the real one named
"cocoon.bar.attr". If parameters "coocoon.yeeha.attr" and
"shopping.cart" exist, the iterator will return
"yeeha". "shopping.cart" does not contain the pre-/ suffix and thus
is dropped.
Similarily, rm-prefix and rm-suffix will be removed from the
attribute name.
- author:
< - a href="mailto:haul@apache.org">Christian Haul
- version:
$ - Id: SimpleMappingMetaModule.java 433543 2006-08-22 06:22:54Z crossley $
| Field Summary |
|---|
| String | prefix | |
| String | suffix | |
| String | rmPrefix | |
| String | rmSuffix | |
| SimpleMappingMetaModule.Mapping | mapping | |
| Methods from org.apache.cocoon.components.modules.input.AbstractMetaModule: |
|---|
|
compose, dispose, getNames, getNames, getValue, getValue, getValue, getValue, getValues, getValues, getValues, getValues, lazy_initialize, obtainModule, releaseModule |
| Method from org.apache.cocoon.components.modules.input.SimpleMappingMetaModule Detail: |
public void configure(Configuration config) throws ConfigurationException {
// It seems that even if there is no config, we'll get an empty
// input-module element here, so it will never be null (JT)
this.inputConf = config.getChild("input-module");
this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput);
this.prefix = config.getChild("prefix").getValue(null);
this.suffix = config.getChild("suffix").getValue(null);
this.rmPrefix = config.getChild("rm-prefix").getValue(null);
this.rmSuffix = config.getChild("rm-suffix").getValue(null);
this.mapping = new Mapping(config);
}
|
public Object getAttribute(String name,
Configuration modeConf,
Map objectModel) throws ConfigurationException {
if (!this.initialized) {
this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
getLogger().warn("No input module given. FAILING");
return null;
}
Configuration inputConfig = null;
String inputName=null;
Mapping mapping = this.mapping;
String prefix = this.prefix;
String suffix = this.suffix;
String rmPrefix = this.rmPrefix;
String rmSuffix = this.rmSuffix;
if (modeConf!=null && modeConf.getChildren().length > 0) {
inputName = modeConf.getChild("input-module").getAttribute("name",null);
if (inputName != null) {
inputConfig = modeConf.getChild("input-module");
}
mapping = new Mapping(modeConf);
prefix = modeConf.getChild("prefix").getValue(null);
suffix = modeConf.getChild("suffix").getValue(null);
rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
}
// remove rm-prefix and rm-suffix
if (rmPrefix != null && name.startsWith(rmPrefix)) {
name = name.substring(rmPrefix.length());
}
if (rmSuffix != null && name.endsWith(rmSuffix)) {
name = name.substring(0,name.length() - rmSuffix.length());
}
// map
String param = mapping.mapTo(name);
// add prefix and suffix
if (prefix != null) param = prefix + param;
if (suffix != null) param = param + suffix;
if (getLogger().isDebugEnabled())
getLogger().debug("mapping ['"+name+"'] to ['"+param+"']");
Object res = getValue(param, objectModel,
this.input, this.defaultInput, this.inputConf,
null, inputName, inputConfig);
if (getLogger().isDebugEnabled())
getLogger().debug("getting for real attribute ['"+param+"'] value: "+res);
return res;
}
|
public Iterator getAttributeNames(Configuration modeConf,
Map objectModel) throws ConfigurationException {
if (!this.initialized) {
this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
getLogger().warn("No input module given. FAILING");
return null;
}
Configuration inputConfig = null;
String inputName=null;
Mapping mapping = this.mapping;
String prefix = this.prefix;
String suffix = this.suffix;
String rmPrefix = this.rmPrefix;
String rmSuffix = this.rmSuffix;
if (modeConf!=null && modeConf.getChildren().length > 0) {
inputName = modeConf.getChild("input-module").getAttribute("name",null);
if (inputName != null) {
inputConfig = modeConf.getChild("input-module");
}
mapping = new Mapping(modeConf);
prefix = modeConf.getChild("prefix").getValue(null);
suffix = modeConf.getChild("suffix").getValue(null);
rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
}
Iterator names = getNames(objectModel,
this.input, this.defaultInput, this.inputConf,
null, inputName, inputConfig);
Set set = new HashSet();
while (names.hasNext()) {
String param = (String) names.next();
if (getLogger().isDebugEnabled())
getLogger().debug("reverse mapping starts with ['"+param+"']");
if (prefix != null)
if (param.startsWith(prefix))
param = param.substring(prefix.length());
else
continue; // prefix is set but parameter does not start with it.
//if (getLogger().isDebugEnabled())
// getLogger().debug("reverse mapping after remove prefix ['"+param+"']");
if (suffix != null)
if (param.endsWith(suffix))
param = param.substring(0,param.length() - suffix.length());
else
continue; // suffix is set but parameter does not end with it.
//if (getLogger().isDebugEnabled())
// getLogger().debug("reverse mapping after remove suffix ['"+param+"']");
if (param.length() < 1)
continue; // nothing left
String newName = mapping.mapFrom(param);
if (rmPrefix != null) newName = rmPrefix + newName;
if (rmSuffix != null) newName = newName + rmSuffix;
if (getLogger().isDebugEnabled())
getLogger().debug("reverse mapping results in ['"+newName+"']");
set.add(newName);
}
return set.iterator();
}
|
public Object[] getAttributeValues(String name,
Configuration modeConf,
Map objectModel) throws ConfigurationException {
if (!this.initialized) {
this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
getLogger().warn("No input module given. FAILING");
return null;
}
Configuration inputConfig = null;
String inputName=null;
Mapping mapping = this.mapping;
String prefix = this.prefix;
String suffix = this.suffix;
String rmPrefix = this.rmPrefix;
String rmSuffix = this.rmSuffix;
if (modeConf!=null && modeConf.getChildren().length > 0) {
inputName = modeConf.getChild("input-module").getAttribute("name",null);
if (inputName != null) {
inputConfig = modeConf.getChild("input-module");
}
mapping = new Mapping(modeConf);
prefix = modeConf.getChild("prefix").getValue(null);
suffix = modeConf.getChild("suffix").getValue(null);
rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
}
// remove rm-prefix and rm-suffix
if (rmPrefix != null && name.startsWith(rmPrefix)) {
name = name.substring(rmPrefix.length());
}
if (rmSuffix != null && name.endsWith(rmSuffix)) {
name = name.substring(0,name.length() - rmSuffix.length());
}
// map
String param = mapping.mapTo(name);
// add prefix and suffix
if (prefix != null) param = prefix + param;
if (suffix != null) param = param + suffix;
if (getLogger().isDebugEnabled())
getLogger().debug("mapping ['"+name+"'] to ['"+param+"']");
Object[] res = getValues(param, objectModel,
this.input, this.defaultInput, this.inputConf,
null, inputName, inputConfig);
if (getLogger().isDebugEnabled())
getLogger().debug("getting for real attribute ['"+param+"'] value: "+res);
return res;
}
|