velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject [Proposed] changes to VelocityServlet
Date Thu, 01 Mar 2001 14:58:03 GMT

Opinions :

1) I think we should change the error() method from private final to
protected.  That way, a derived class can do the error handling and do
something useful (log, send email, panic...).   Currently it just spews
some HTML.

2)  I would like to change init() to turn the properties file into a
j.u.Properties, and then pass that to a routine :

  protected void alterInitProps( ServletConfig config, Properties props

before calling Runtime.init(), something like

  Properties p = new Properties();
  p.load( propsFile);
  alterInitProps( config, p);
  Runtime.init( p );

where the default impl of alterInitPropse does nothing.

The reason is so you can do fancy-schmancy things, such as change the
template path from relative to your webapp root to absolute.  That way
you can make portable vel.props files and webapps.  So in your derived
class, do something like the following in alterInitProps() :

	for( Enumeration e = props.propertyNames(); e.hasMoreElements(); )
	    String s = (String) e.nextElement() ;
	    String su = s.toUpperCase();

	    if (su.startsWith("RESOURCE.LOADER") &&
		String templatePath = props.getProperty( s );
		templatePath = config.getServletContext().getRealPath( templatePath );

		props.setProperty( s, templatePath );
	    else if (su.equals("RUNTIME.LOG"))
		String runtimelog = props.getProperty( s );
		runtimelog = config.getServletContext().getRealPath( runtimelog );
		props.setProperty( s, runtimelog);

I use this - I set my resource.path to something relative to my webapp
root, and then staple it down.

Again - I am not proposing we add the above impl code to VelocityServlet
- just add the calling of the alterInitProps() call to init().
This would also allow you to do your velocity configuration from an
application or framework properties set, so you only would have to worry
about one. (I am sure that Turbine does this...)


Geir Magnusson Jr.                     
Developing for the web?  See

View raw message