You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/11/28 03:29:13 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node ASTStringLiteral.java NodeUtils.java

jvanzyl     00/11/27 18:29:13

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTStringLiteral.java NodeUtils.java
  Log:
  - added simple string interpolation to all string literals wherever
    they occur: in parameters to methods, and parameters to directives.
  
    right only the $foo.bar("my name is $name") case is being handled. not the
    $foo.bar("${foo}man!") case. will add that shortly.
  
  Revision  Changes    Path
  1.2       +8 -1      jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
  
  Index: ASTStringLiteral.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTStringLiteral.java	2000/10/20 19:14:02	1.1
  +++ ASTStringLiteral.java	2000/11/28 02:29:12	1.2
  @@ -25,6 +25,13 @@
   
       public Object value(Context context)
       {
  -        return getFirstToken().image.substring(1, getFirstToken().image.length() - 1);
  +        /*
  +         * This will remove the quotes and then interpolate
  +         * any variables from the context into the
  +         * the string.
  +         */
  +        return NodeUtils.interpolate(
  +            getFirstToken().image.substring(
  +                1, getFirstToken().image.length() - 1), context);
       }
   }
  
  
  
  1.6       +5 -5      jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/NodeUtils.java
  
  Index: NodeUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/NodeUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NodeUtils.java	2000/11/28 00:55:41	1.5
  +++ NodeUtils.java	2000/11/28 02:29:12	1.6
  @@ -62,7 +62,7 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  - * @version $Id: NodeUtils.java,v 1.5 2000/11/28 00:55:41 jvanzyl Exp $
  + * @version $Id: NodeUtils.java,v 1.6 2000/11/28 02:29:12 jvanzyl Exp $
    */
   public class NodeUtils
   {
  @@ -108,7 +108,7 @@
        * be transformed into "candy.jpg" before
        * the method is executed.
        */
  -    public String interpolate(String argStr, Context vars)
  +    public static String interpolate(String argStr, Context vars)
       {
           StringBuffer argBuf = new StringBuffer();
   
  @@ -133,10 +133,10 @@
                       {
                           String value = (String) vars.get(nameBuf.toString());
   
  -                        if (value != null)
  -                        {
  +                        if (value == null)
  +                            argBuf.append("$").append(nameBuf.toString());
  +                        else
                               argBuf.append(value);
  -                        }
                       }
                       break;