You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/03/01 15:58:03 UTC
[Proposed] changes to VelocityServlet
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") &&
su.endsWith("RESOURCE.PATH"))
{
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
--
Geir Magnusson Jr. geirm@optonline.com
Developing for the web? See http://jakarta.apache.org/velocity/
Re: [Proposed] changes to VelocityServlet
Posted by Daniel Rall <dl...@collab.net>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:
> 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
> )
Good suggestions, +1.
--
Daniel Rall <dl...@collab.net>
Re: [Proposed] changes to VelocityServlet
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Christoph Reck wrote:
> I have a counter suggestion: make the properties loading an overridable
> method:
>
> ...
> Properties p = new loadProperties(propsFilename);
> Runtime.init( p );
Yep, will do that. Good one. +1
geir
--
Geir Magnusson Jr. geirm@optonline.com
Developing for the web? See http://jakarta.apache.org/velocity/
Re: [Proposed] changes to VelocityServlet
Posted by Christoph Reck <Ch...@dlr.de>.
"Geir Magnusson Jr." wrote:
>
> 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
> )
>
+1, but use a nicer name, e.g. prepareProperties.
I have a counter suggestion: make the properties loading an overridable
method:
...
Properties p = new loadProperties(propsFilename);
Runtime.init( p );
...
protected Properties loadProperties( propsFilename )
{
Properties p = new Properties();
p.load(propsFilename);
return p;
}
In this way you can do fancy setup, merge you own stuff in, etc.
Your subclass would just do:
protected Properties loadProperties( propsFilename )
{
Properties p = super.loadProperties(propsFilename);
... do you stuff here
}
:) Chirstoph