Le vendredi 09 novembre 2007 à 16:15 +0100, Claude Brisson a écrit :
> ValueParser now has protected get/setAllowSubkeys() boolean methods.
> 
> The default value of allowSubkey shoud be the value of deprecatedMode,
> but I'm not really sure of how this should be done. But I'm sure Nathan
> will be of some help here.
> 
> Also, since ValueParser is used internally by the Tool.configure method,
> it may be safer to move all this new stuff in ParameterParser only.
(i meant ParameterTool)

Or to introduce a SubkeyValueParser between ValueParser and
ParameterTool inheritance.

> 
>    Claude
> 
> 
> Le vendredi 09 novembre 2007 à 14:49 +0000, [EMAIL PROTECTED] a
> écrit :
> > Author: cbrisson
> > Date: Fri Nov  9 06:49:36 2007
> > New Revision: 593549
> > 
> > URL: http://svn.apache.org/viewvc?rev=593549&view=rev
> > Log:
> > sub keys getter (not yet tested but doesnt break anything at least)
> > 
> > Modified:
> >     
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ValueParser.java
> >     
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java
> > 
> > Modified: 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ValueParser.java
> > URL: 
> > http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ValueParser.java?rev=593549&r1=593548&r2=593549&view=diff
> > ==============================================================================
> > --- 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ValueParser.java
> >  (original)
> > +++ 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ValueParser.java
> >  Fri Nov  9 06:49:36 2007
> > @@ -21,6 +21,9 @@
> >  
> >  import java.util.Map;
> >  import java.util.Locale;
> > +import java.util.Set;
> > +import java.util.HashMap;
> > +
> >  import org.apache.velocity.tools.config.DefaultKey;
> >  
> >  /**
> > @@ -40,6 +43,14 @@
> >  {
> >      private Map source = null;
> >  
> > +    private boolean allowSubkeys = true; /* default to whatever, should be 
> > overridden by depreprecatedMode default value anyway */
> > +
> > +    /* when using subkeys, cache at least the presence of any subkey,
> > +    so that the rendering of templates not using subkeys will only
> > +    look once for subkeys
> > +     */
> > +    private boolean hasSubkeys = true;
> > +
> >      public ValueParser() {}
> >  
> >      public ValueParser(Map source)
> > @@ -98,7 +109,11 @@
> >          {
> >              return null;
> >          }
> > -        return getSource().get(key);
> > +        Object value = getSource().get(key);
> > +        if (value == null && getAllowSubkeys()) {
> > +            value = getSubkey(key);
> > +        }
> > +        return value;
> >      }
> >  
> >      public Object[] getValues(String key)
> > @@ -359,4 +374,29 @@
> >          return toLocales(getValues(key));
> >      }
> >  
> > +    protected boolean getAllowSubkeys() {
> > +        return allowSubkeys;
> > +    }
> > +
> > +    protected void setAllowSubkeys(boolean allow) {
> > +        allowSubkeys = allow;
> > +    }
> > +
> > +    protected Object getSubkey(String subkey) {
> > +        if (!hasSubkeys || subkey == null || subkey.length() == 0) {
> > +            return null;
> > +        }
> > +        Map<String,Object> values = null;
> > +        subkey = subkey.concat(".");
> > +        for(Map.Entry<String,Object> 
> > entry:(Set<Map.Entry>)getSource().entrySet()) {
> > +            if(entry.getKey().startsWith(subkey)) {
> > +                if(values == null) {
> > +                    values = new HashMap<String,Object>();
> > +                }
> > +                
> > values.put(entry.getKey().substring(subkey.length()),entry.getValue());
> > +            }
> > +        }
> > +        hasSubkeys = (values == null);
> > +        return values;
> > +    }
> >  }
> > 
> > Modified: 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java
> > URL: 
> > http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java?rev=593549&r1=593548&r2=593549&view=diff
> > ==============================================================================
> > --- 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java
> >  (original)
> > +++ 
> > velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ParameterTool.java
> >  Fri Nov  9 06:49:36 2007
> > @@ -109,7 +109,11 @@
> >       */
> >      public Object getValue(String key)
> >      {
> > -        return getRequest().getParameter(key);
> > +        Object value = getRequest().getParameter(key);
> > +        if(value == null && getAllowSubkeys()) {
> > +            value = getSubkey(key);
> > +        }
> > +        return value;
> >      }
> >  
> > 
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to