Re: svn commit: r593549 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: generic/ValueParser.java view/ParameterTool.java

2007-11-09 Thread Nathan Bubna
hey Claude, i'm not sure if you're done with this or if it's still in
process, but there's a few problems so far (in decreasing order of
importance):
- ant test is now failing
- the hasSubKeys things doesn't make any sense to me
- stylistically, the practice for Velocity projects is to keep braces
on their own lines

i'm also curious about what the advantages are of this approach (as
opposed to a ValueParserSub).  it's been a while since i've thought
through the implementation options for this.

On Nov 9, 2007 7:15 AM, Claude Brisson <[EMAIL PROTECTED]> wrote:
> 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.
>
>Claude
>
>
> Le vendredi 09 novembre 2007 à 14:49 +, [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 values = null;
> > +subkey = subkey.concat(".");
> > +for(Map.Entry 
> > entry:(Set)getSource().entrySet()) {
> > +if(entry.getKey().startsWith(subkey)) {
> > +if(values == null) {
> > +values = new HashMap();
> > +}
> > +
> > 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)
> >  {

Re: svn commit: r593549 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: generic/ValueParser.java view/ParameterTool.java

2007-11-09 Thread Claude Brisson
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 +, [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 values = null;
> > +subkey = subkey.concat(".");
> > +for(Map.Entry 
> > entry:(Set)getSource().entrySet()) {
> > +if(entry.getKey().startsWith(subkey)) {
> > +if(values == null) {
> > +values = new HashMap();
> > +}
> > +
> > 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 un

Re: svn commit: r593549 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: generic/ValueParser.java view/ParameterTool.java

2007-11-09 Thread Claude Brisson
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.

   Claude


Le vendredi 09 novembre 2007 à 14:49 +, [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 values = null;
> +subkey = subkey.concat(".");
> +for(Map.Entry 
> entry:(Set)getSource().entrySet()) {
> +if(entry.getKey().startsWith(subkey)) {
> +if(values == null) {
> +values = new HashMap();
> +}
> +
> 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]