For the string #TestString (test-string this is random string), the velocity engine while evaluating throws following parsing exception.
org.apache.velocity.exception.ParseErrorException: Encountered "-" at PERSONALISATION[line 1, column 18]
Was expecting one of:
<RPAREN> ...
<WHITESPACE> ...
<WHITESPACE> ...
Velocity 1.7 is being used, and the context passed while evaluating is empty except the Escape Tool.
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("esc", new EscapeTool());
StringWriter writer = new StringWriter();
getVelocityEngine().evaluate(velocityContext, writer, "TEST-TEMPLATE", text);
In Velocity, the directives begin with
#like#if,#foreach, etc. The#at the beginning of the line makes Velocity think that#TestStringis a directive and so after it encounters the open parenthesis, it is looking for a closing parenthesis and encounters the-instead. Hence the parsing error. Something like#TestString(test),#TestString('test-string this is random string')orTestString#wouldn't cause any parsing errors. If your rendered string needs to look exactly like#TestString (test-string this is random string), you can use something like the below: