The backslash behaviour is somehow unpredictable with the current
parser. But you can use the "poor man's escaping":

#set($dol='$')
$dol{FOO:?Foo is not set}


  Claude

Le mercredi 13 février 2008 à 20:34 -0800, Bryan Castillo a écrit :
> I am trying to generate some shell scripts with a parameter expansion
> of the the form ${parameter:?word}.
> 
> For a test case, I tried to get Velocity to generate a String with the 
> content:
> 
> ${FOO:?Foo is not set}
> 
> 
> I tried the following templates:
> 
>           ${FOO:?Foo is not set}   ->  Produces an exception.
>           \${FOO:?Foo is not set}  ->  Also produces an exception.
>           $\{FOO:?Foo is not set}  ->  Produces:  $\{FOO:?Foo is not
> set}   (Why is the backslash still there?)
> 
> 
> 
> When I run the template   \$FOO    I still get the output  \$FOO.  I
> thought that I would get $FOO.
> 
> 
> 
> If anyone could help me out with this, I would appreciate it.
> Thanks.
> 
> 
> Test Code:
> 
> 
> 
> package com.amazonaws.mturk.build;
> 
> import java.io.StringWriter;
> 
> import org.apache.velocity.VelocityContext;
> import org.apache.velocity.app.VelocityEngine;
> 
> 
> public class TestVelocityShellConstruct {
> 
>     public static void main(String[] args) {
>         String[] templates = new String[] {
>           "${FOO:?Foo is not set}",
>           "\\${FOO:?Foo is not set}",
>           "$\\{FOO:?Foo is not set}"
>         };
>         String expected = "${FOO:?Foo is not set}";
> 
>         VelocityEngine engine = new VelocityEngine();
>         for (String template : templates) {
>             
> System.out.println("-----------------------------------------------");
>             System.out.println("Executing template:");
>             System.out.println("-------------------");
>             System.out.println(template);
>             System.out.println();
>             System.out.println("Output:");
>             System.out.println("-------");
>             try {
>                 StringWriter out = new StringWriter();
>                 engine.evaluate(new VelocityContext(), out,
> "velocity", template);
>                 System.out.println(out);
>                 if (!expected.equals(out.toString())) {
>                     System.out.println("DOES NOT MATCH EXPECTED OUTPUT.");
>                 }
>             }
>             catch (Exception e) {
>                 e.printStackTrace(System.out);
>             }
>         }
> 
>     }
> 
> }
> 
> 
> 
> Output:
> 
> 
> 
> -----------------------------------------------
> Executing template:
> -------------------
> ${FOO:?Foo is not set}
> 
> Output:
> -------
> org.apache.velocity.exception.ParseErrorException: Encountered ":?Foo
> is not set}" at line 1, column 6 of velocity
> Was expecting one of:
>     "}" ...
>     <DOT> ...
> 
>       at 
> org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:311)
>       at 
> org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:228)
>       at 
> com.amazonaws.mturk.build.TestVelocityShellConstruct.main(TestVelocityShellConstruct.java:30)
> -----------------------------------------------
> Executing template:
> -------------------
> \${FOO:?Foo is not set}
> 
> Output:
> -------
> org.apache.velocity.exception.ParseErrorException: Encountered ":?Foo
> is not set}" at line 1, column 7 of velocity
> Was expecting one of:
>     "}" ...
>     <DOT> ...
> 
>       at 
> org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:311)
>       at 
> org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:228)
>       at 
> com.amazonaws.mturk.build.TestVelocityShellConstruct.main(TestVelocityShellConstruct.java:30)
> -----------------------------------------------
> Executing template:
> -------------------
> $\{FOO:?Foo is not set}
> 
> Output:
> -------
> $\{FOO:?Foo is not set}
> DOES NOT MATCH EXPECTED OUTPUT.
> 
> ---------------------------------------------------------------------
> 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