Hi Ravikanth,

there is no such list of unallowed characthers in a string. Only the
velocity syntax exists. Therefore up to Velocity 1.4, a string may not
contain the quote character itself and a new-line character.
Additionally you need care with the other symbols: \ $ #
which have a meaning to velocity during string interpolation - plus
some minor bugs (see below or look at http://issues.apache.org/jira ).

With the 1.5 version coming up (nightly snapshot), to my knowledge,
you will be able to have multi-line strings, quotes witin quoted
strings (by doubling the quote character! - like in excel CSV exports).

In your use-case you might need a filter (like a simple reg-ex
replacing) to filter out things that make problems in velocity before
you forward things to your render recursion, example:
  #set( $str = $theValue.replaceall("##\)", "$H$H)") )
  $render.recurse( $ctx, '\#set($$nameObj = "$str")' )
Maybe replace all #s altogehter , if you are not using macros or
directives in your recursion evaluation.

If you provide patches or vote on the below stated issues, there are
chances that the 1.5 final will not choke on the ## within a string.
(Please be aware that Apache Jakarta projects are done on a free will
 basis and contributions are welcome. People who have an itch are
 kindly asked to help on solutions.)

Cheers,
Christoph


Ravikanth L wrote:
Hi Christoph,
 Thanks a lot for replying back.
As far as the suggestions you gave, i can't use failsafe escaping apporoach as i am not hardcoding the values in the template. As i said earlier, we are having an xml file where in we define element name and its value as
<element name="myvar">
 <value>User can enter what ever text they want here</value>
</element>
And we are reading the xml and dynamically creating the variables and associating them with the values to the context using renderTool as below in template
$render.recurse($ctx, '\#set($$nameObj = "$theValue")' )
where $nameObj contains the variable name and the $theValue contains the text between <value> and </value>. And regarding using single quote approach, as the recurse has to evaluate my #set, i think the syntax i have given is correct. Tried changing the syntax also by giving single qoutes with escaping for $theValue, but getting some parser errors. So, if i can get a list of characters which will create problems in #set directive like ##, newline etc... i can ask the users not to use them or try to escape them in the xml itself.... Any suggetions will be of great help.

[snip]
I am aware of some issues that are related to the problem (maybe you can vote 
on them):
http://issues.apache.org/jira/browse/VELOCITY-126 "String containing '##' is treated 
as unterminated String"
http://issues.apache.org/jira/browse/VELOCITY-355 "lost '#'s inside 
#literal()/#end"
http://issues.apache.org/jira/browse/VELOCITY-272 "EOF exception when last line is 
commented out and has no new line at end"
http://issues.apache.org/jira/browse/VELOCITY-253 "Enhance whitespace gobbling" 
- involves parser syntax simplification

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

Reply via email to