velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: How to use EscapeTool
Date Wed, 30 Aug 2006 15:08:17 GMT
Since you are defining the EscapeTool in your toolbox, it should be
automatically put in the context for you (assuming you have Spring's
Velocity support configured for that).  And it looks like this is
already the case.  Since, $esc.xml($foo) renders as "This is Foo",
then we know the EscapeTool is present in the context; if it were not,
then $esc.xml($foo) would render as "$esc.xml($foo)".

Everything that you sent in your email looked like it was configured
and used perfectly.  So, i have no idea why the ampersand was not
escaped.

On 8/30/06, Duttaroy, Debasish <debasish.duttaroy@fmr.com> wrote:
> Hmm...
> I think I do not quite understand all the aspects yet.
>
> What exactly do you mean by "having EscapeTool in context". I assume
> that I need to put EscapeTool into VelocityContext. How do I do that? Or
> how do I ensure that I have EscapeTool in the VelocityContext.
>
> Thanks
> Debasish
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: Tuesday, August 29, 2006 5:10 PM
> To: Velocity Users List
> Subject: Re: How to use EscapeTool
>
>
> That is highly perplexing.  The code as you show it should work
> perfectly as long as the EscapeTool is present in the context.  And if
> it were not, the key part of the result would look like:
>
> ${esc.xml(...)}
>
> Since EscapeTool is basically just a wrapper for Common Lang's
> StringEscapeUtils, you might check that you have a working version of
> that in the classpath (though to my knowledge, it has never been
> broken).
>
> Given what you say, i really have no idea what could be causing the
> escaping to fail.  All i can suggest is that you double check that
> everything is as you describe and nothing is cached.
>
> On 8/29/06, Duttaroy, Debasish <debasish.duttaroy@fmr.com> wrote:
> > Hi
> > I am new to Velocity. Here is my requirement.
> >
> > I want the velocity template to spit out a xml output. Basically, my
> .vm
> > file is a xml template. I am able to achieve this. Now I want the data
> > inside this xml document to be escaped.
> >
> > What is the best way to do this.
> >
> > My understanding is this should be done with the help of EscapeTool.
> > BTW, I use Spring MVC. This is what I do:
> >
> > My hello.vm
> >
> > ## Velocity Hello World
> > <?xml version="1.0"?>
> > <headlines>
> >         <lineitem>
> >
> > <headlinetext>${esc.xml($headline.headlineText)}</headlinetext>
> >         </lineitem>
> > </headlines>
> >
> > Required output
> >
> > <headlines>
> >         <lineitem>
> >                 <headlinetext>Times &amp; Warner</headlinetext>
> >         </lineitem>
> > </headlines>
> >
> >
> > Actual Output
> >
> > <headlines>
> >         <lineitem>
> >                 <headlinetext>Times & Warner</headlinetext>
> >         </lineitem>
> > </headlines>
> >
> >
> > I put toolbox.xml inside WEB-INF
> >
> > <?xml version="1.0"?>
> > <tool>
> >         <key>esc</key>
> >         <scope>application</scope>
> >         <class>org.apache.velocity.tools.generic.EscapeTool</class>
> > </tool>
> >
> >
> > What else do I need to do. If anyone can provide a step by step method
> > to best way of doing escaping that will be great. I can achieve what I
> > want by some crude means, but I want the best practice not the hack.
> >
> > Thanks in advance
> > Debasish
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message