You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by angelcervera <an...@acervera.com> on 2007/08/28 23:47:18 UTC

RE: How to keep '$' Char in .vm files?


Marco Schoolenberg wrote:
> 
> I seem to remember that escaping the character is the Normal thing to
> do...
> 

In "User Guide" said:

Velocity User Guide wrote:
> 
> VTL directives can be escaped with the backslash character ("\") in a
> manner similar to valid VTL references.
> 

But using this template:


> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> Commons Validator Rules Configuration 1.1.3//EN"
> "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> <form-validation>
> <arg2 key="\${var:maxlength}" name="maxlength" resource="false" />
> </form-validation>
> 

Return this error:


> org.apache.velocity.exception.ParseErrorException: Encountered
> ":maxlength}\" name=\"maxlength\" resource=\"false\"
> />\n</form-validation>\n" at line 4, column 18.
> Was expecting one of:
>     "}" ...
>     <DOT> ...
>     
>         at org.apache.velocity.Template.process(Template.java:141)
> 

Using this template all go ok (special attention in removed character $):


> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> Commons Validator Rules Configuration 1.1.3//EN"
> "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> <form-validation>
> <arg2 key="{var:maxlength}" name="maxlength" resource="false" />
> </form-validation>
> 

So, in conclusion, "$" it's not escaped with "\" character.

I'm using velocity 1.4

Thank's
-- 
View this message in context: http://www.nabble.com/How-to-keep-%27%24%27-Char-in-.vm-files--tf4038353.html#a12376953
Sent from the Velocity - User mailing list archive at Nabble.com.


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


RE: How to dynamically reload settings

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
The advice Nathan gave me for reloading the VelocityEngine at runtime,
worked exactly as he predicted.  Excellent, I can now turn caching
on/off from within the application at runtime.  Makes a huge difference
to performance.

I use Log4j and my own resource loader so the advice about
LogSystemCommonsLog and WebAppLoader were not applicable in my
particular situation.

Thanks,

Steve

-----Original Message-----
From:
user-return-19278-sohara=pivotal-solutions.co.uk@velocity.apache.org
[mailto:user-return-19278-sohara=pivotal-solutions.co.uk@velocity.apache
.org] On Behalf Of Steve O'Hara
Sent: 05 September 2007 20:21
To: Velocity Users List
Subject: RE: How to dynamically reload settings

Blimey.....
The mere mention of "...race condition..." is enough to keep me awake at
night, or at the very least visit the pub for a few large ones!  I'll
give it a go at some stage and let the list know when/if I'm successful.
Thanks for the very detailed and thorough explanation Nathan.

Cheers,
Steve


-----Original Message-----
From:
user-return-19277-sohara=pivotal-solutions.co.uk@velocity.apache.org
[mailto:user-return-19277-sohara=pivotal-solutions.co.uk@velocity.apache
.org] On Behalf Of Nathan Bubna
Sent: 04 September 2007 17:44
To: Velocity Users List
Subject: Re: How to dynamically reload settings

Forcing a call to the loadConfiguration method won't help.  That would
only try to re-init() the servlet's VelocityEngine (or something like
that), and it's not currently possible to do that.  In order to change
settings, you'll need to replace the VelocityEngine.  This is
possible, but it'll probably take a bit of work on your part.  You
need to change your VelocityViewServlet class to recognize some sort
of special "reset" servlet request. When it handles that request, it
should create a new VelocityEngine, load and set the properties on it,
call init() on that new engine, and then pass that already initialized
engine to the setVelocityEngine() method.

and wait, there's more...

if you are pointing commons-logging to the LogSystemCommonsLog class,
you will also want to pass your new engine to that class's static
setVelocityEngine() method.  and...

if you are using the WebappLoader as your ResourceLoader (which is the
default for the VVS), then you will need to set the ServletContext as
an application attribute via a call like this.

myNewEngine.setApplicationAttribute(SERVLET_CONTEXT_KEY,
getServletContext());

oh, and these things should all be done *BEFORE* passing the new
engine to the VVS's setVelocityEngine() method, or else you will get
weird race condition stuff.

and of course, i've never done any of this, but it should work.  just
be sure to do all the config and setup of the new VelocityEngine
before you pass it to the setVelocityEngine() method.

On 9/3/07, Steve O'Hara <so...@pivotal-solutions.co.uk> wrote:
> I'm extending the VelocityViewServlet class and overriding the
> loadConfiguration method to load properties from my own storage area.
> This is fine and works great, but there are circumstances within the
> application where I need to change some settings dynamically e.g.
> cacheing.
>
> Is there a way in which I can force Velocity to reload itself? i.e.
> force a call to the loadConfiguration method
>
> Thanks,
> Steve
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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




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




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


RE: How to dynamically reload settings

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
Blimey.....
The mere mention of "...race condition..." is enough to keep me awake at
night, or at the very least visit the pub for a few large ones!  I'll
give it a go at some stage and let the list know when/if I'm successful.
Thanks for the very detailed and thorough explanation Nathan.

Cheers,
Steve


-----Original Message-----
From:
user-return-19277-sohara=pivotal-solutions.co.uk@velocity.apache.org
[mailto:user-return-19277-sohara=pivotal-solutions.co.uk@velocity.apache
.org] On Behalf Of Nathan Bubna
Sent: 04 September 2007 17:44
To: Velocity Users List
Subject: Re: How to dynamically reload settings

Forcing a call to the loadConfiguration method won't help.  That would
only try to re-init() the servlet's VelocityEngine (or something like
that), and it's not currently possible to do that.  In order to change
settings, you'll need to replace the VelocityEngine.  This is
possible, but it'll probably take a bit of work on your part.  You
need to change your VelocityViewServlet class to recognize some sort
of special "reset" servlet request. When it handles that request, it
should create a new VelocityEngine, load and set the properties on it,
call init() on that new engine, and then pass that already initialized
engine to the setVelocityEngine() method.

and wait, there's more...

if you are pointing commons-logging to the LogSystemCommonsLog class,
you will also want to pass your new engine to that class's static
setVelocityEngine() method.  and...

if you are using the WebappLoader as your ResourceLoader (which is the
default for the VVS), then you will need to set the ServletContext as
an application attribute via a call like this.

myNewEngine.setApplicationAttribute(SERVLET_CONTEXT_KEY,
getServletContext());

oh, and these things should all be done *BEFORE* passing the new
engine to the VVS's setVelocityEngine() method, or else you will get
weird race condition stuff.

and of course, i've never done any of this, but it should work.  just
be sure to do all the config and setup of the new VelocityEngine
before you pass it to the setVelocityEngine() method.

On 9/3/07, Steve O'Hara <so...@pivotal-solutions.co.uk> wrote:
> I'm extending the VelocityViewServlet class and overriding the
> loadConfiguration method to load properties from my own storage area.
> This is fine and works great, but there are circumstances within the
> application where I need to change some settings dynamically e.g.
> cacheing.
>
> Is there a way in which I can force Velocity to reload itself? i.e.
> force a call to the loadConfiguration method
>
> Thanks,
> Steve
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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




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


Re: How to dynamically reload settings

Posted by Nathan Bubna <nb...@gmail.com>.
Forcing a call to the loadConfiguration method won't help.  That would
only try to re-init() the servlet's VelocityEngine (or something like
that), and it's not currently possible to do that.  In order to change
settings, you'll need to replace the VelocityEngine.  This is
possible, but it'll probably take a bit of work on your part.  You
need to change your VelocityViewServlet class to recognize some sort
of special "reset" servlet request. When it handles that request, it
should create a new VelocityEngine, load and set the properties on it,
call init() on that new engine, and then pass that already initialized
engine to the setVelocityEngine() method.

and wait, there's more...

if you are pointing commons-logging to the LogSystemCommonsLog class,
you will also want to pass your new engine to that class's static
setVelocityEngine() method.  and...

if you are using the WebappLoader as your ResourceLoader (which is the
default for the VVS), then you will need to set the ServletContext as
an application attribute via a call like this.

myNewEngine.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext());

oh, and these things should all be done *BEFORE* passing the new
engine to the VVS's setVelocityEngine() method, or else you will get
weird race condition stuff.

and of course, i've never done any of this, but it should work.  just
be sure to do all the config and setup of the new VelocityEngine
before you pass it to the setVelocityEngine() method.

On 9/3/07, Steve O'Hara <so...@pivotal-solutions.co.uk> wrote:
> I'm extending the VelocityViewServlet class and overriding the
> loadConfiguration method to load properties from my own storage area.
> This is fine and works great, but there are circumstances within the
> application where I need to change some settings dynamically e.g.
> cacheing.
>
> Is there a way in which I can force Velocity to reload itself? i.e.
> force a call to the loadConfiguration method
>
> Thanks,
> Steve
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


How to dynamically reload settings

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
I'm extending the VelocityViewServlet class and overriding the
loadConfiguration method to load properties from my own storage area.
This is fine and works great, but there are circumstances within the
application where I need to change some settings dynamically e.g.
cacheing.  

Is there a way in which I can force Velocity to reload itself? i.e.
force a call to the loadConfiguration method

Thanks,
Steve


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


Re: How to keep '$' Char in .vm files?

Posted by Nathan Bubna <nb...@gmail.com>.
On 8/28/07, angelcervera <an...@acervera.com> wrote:
>
>
> Marco Schoolenberg wrote:
> >
> > I seem to remember that escaping the character is the Normal thing to
> > do...
> >
>
> In "User Guide" said:
>
> Velocity User Guide wrote:
> >
> > VTL directives can be escaped with the backslash character ("\") in a
> > manner similar to valid VTL references.
> >
>
> But using this template:
>
>
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> > Commons Validator Rules Configuration 1.1.3//EN"
> > "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> > <form-validation>
> > <arg2 key="\${var:maxlength}" name="maxlength" resource="false" />
> > </form-validation>
> >
>
> Return this error:
>
>
> > org.apache.velocity.exception.ParseErrorException: Encountered
> > ":maxlength}\" name=\"maxlength\" resource=\"false\"
> > />\n</form-validation>\n" at line 4, column 18.
> > Was expecting one of:
> >     "}" ...
> >     <DOT> ...
> >
> >         at org.apache.velocity.Template.process(Template.java:141)
> >
>
> Using this template all go ok (special attention in removed character $):
>
>
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> > Commons Validator Rules Configuration 1.1.3//EN"
> > "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> > <form-validation>
> > <arg2 key="{var:maxlength}" name="maxlength" resource="false" />
> > </form-validation>
> >
>
> So, in conclusion, "$" it's not escaped with "\" character.

correct.  the escaping is for "VTL references" as opposed to escaping
the $ char, and unfortunately ${var:maxlength} is not a valid VTL
reference.

to properly escape the $ char, you simply need to do

#set( $D = '$' )

and then do ${D}{var:maxlength}

> I'm using velocity 1.4

this is true for all versions.

> Thank's
> --
> View this message in context: http://www.nabble.com/How-to-keep-%27%24%27-Char-in-.vm-files--tf4038353.html#a12376953
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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