velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: loadConfiguration() equivalent in Velocity Tools 2.0
Date Tue, 22 Jun 2010 18:17:47 GMT
Unfortunately, in the quest to simplify other things and improve
performance, this particular sort of customization is now a little
more complicated.   There are two ways to do it:

Subclass VelocityView with the following:

protected void configure(final JeeConfig config, final VelocityEngine
velocity) {
  super.configure(config, velocity);
  //do your stuff here
}

and tell your VelocityView[Servlet/Filter/Tag]s to use it via:

<context-param>
  <param-name>org.apache.velocity.tools.view.class</param-name>
  <param-value>com.foo.MyVelocityView</param-value>
</context-param>

or alternately, you can try subclassing your
VelocityView[Servlet/Filter/Tag](s) directly and creating your own
VelocityEngine during init and then calling
getVelocityView().setVelocityEngine(myEngine), but then, of course,
you will not be taking advantage of all the VelocityEngine
configuration done by VelocityView and friends.  So i recommend the
former option.

On Tue, Jun 22, 2010 at 9:22 AM, B. Scott Smith <scott@smithdomain.com> wrote:
> Hi, I am trying to migrate to Velocity Tools 2.0. My application currently
> needs to set a Velocity Property to a value that is determined at run-time.
> For example, I would like to set a property to one of two possible values,
> based on the current setting of my application's debug value. Before, I did
> this by simply overwriting the loadConfiguration() method:
>
>   protected Properties loadConfiguration( ServletConfig config )
>        throws IOException, FileNotFoundException
>   {
>        Properties velocityProps = new Properties(  );
>        if ( localDir != null ) {
>            velocityProps.setProperty(
>   Velocity.FILE_RESOURCE_LOADER_PATH, localDir );
>        }
>        velocityProps.setProperty( Velocity.RUNTIME_LOG, localDir +
>   "velocity.log" );
>        velocityProps.setProperty(
>   Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, debugFlag ?
>
> "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" :
>
> "org.apache.velocity.runtime.log.NullLogSystem" );
>        return velocityProps;
>   }
>
>
> How can I accomplish the same thing in Tools 2.0?
> Thanks in advance for your help.
>  - Scott Smith
>
>

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


Mime
View raw message