You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2002/12/16 10:57:05 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/modules/input SimpleMappingMetaModule.java

haul        2002/12/16 01:57:05

  Modified:    src/java/org/apache/cocoon/components/modules/input
                        SimpleMappingMetaModule.java
  Log:
    <action dev="CH" type="add">
      SimpleMappingMetaModule: added feature to remove a prefix / suffix.
    </action>
  
   plus some debug statements
  
  Revision  Changes    Path
  1.4       +61 -11    xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java
  
  Index: SimpleMappingMetaModule.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleMappingMetaModule.java	5 Dec 2002 10:01:04 -0000	1.3
  +++ SimpleMappingMetaModule.java	16 Dec 2002 09:57:05 -0000	1.4
  @@ -75,8 +75,11 @@
    * 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.</p>
  + * "yeeha". "shopping.cart" does not contain the pre-/ suffix and thus
  + * is dropped.</p> 
  + *
  + * <p>Similarily, rm-prefix and rm-suffix will be removed from the
  + * attribute name.</p>
    *
    * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
    * @version CVS $Id$
  @@ -85,6 +88,8 @@
   
       String prefix = null;
       String suffix = null;
  +    String rmPrefix = null;
  +    String rmSuffix = null;
       Mapping mapping = null;
   
       protected class Mapping {
  @@ -140,6 +145,8 @@
           this.inputConf = config.getChild("input-module");
           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);
       }
   
  @@ -163,6 +170,9 @@
           Mapping mapping = this.mapping;
           String prefix = this.prefix;
           String suffix = this.suffix;
  +        String rmPrefix = this.rmPrefix;
  +        String rmSuffix = this.rmSuffix;
  +
           if (modeConf!=null) {
               inputName   = modeConf.getChild("input-module").getAttribute("name",null);
               if (inputName != null) {
  @@ -171,17 +181,33 @@
               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+"']");
   
  -        return getValue(param, objectModel,
  -                        this.input, this.defaultInput, this.inputConf,
  -                        null, inputName, inputConfig);
  +        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;
       }
   
   
  @@ -207,6 +233,9 @@
           Mapping mapping = this.mapping;
           String prefix = this.prefix;
           String suffix = this.suffix;
  +        String rmPrefix = this.rmPrefix;
  +        String rmSuffix = this.rmSuffix;
  +
           if (modeConf!=null) {
               inputName   = modeConf.getChild("input-module").getAttribute("name",null);
               if (inputName != null) {
  @@ -215,17 +244,32 @@
               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+"']");
   
  -        return getValues(param, objectModel,
  -                         this.input, this.defaultInput, this.inputConf,
  -                         null, inputName, inputConfig);
  +        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;
       }
   
   
  @@ -249,6 +293,8 @@
           Mapping mapping = this.mapping;
           String prefix = this.prefix;
           String suffix = this.suffix;
  +        String rmPrefix = this.rmPrefix;
  +        String rmSuffix = this.rmSuffix;
           if (modeConf!=null) {
               inputName   = modeConf.getChild("input-module").getAttribute("name",null);
               if (inputName != null) {
  @@ -257,6 +303,8 @@
               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, 
  @@ -291,6 +339,9 @@
   
               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+"']");
   
  @@ -299,7 +350,6 @@
   
           return set.iterator();
   
  -   }
  -
  +    }
   
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org