|
From: <jue...@we...> - 2003-08-07 18:03:53
|
Hi Darren,
Thanks for the patch. I've just incorporated the idea into =
VelocityConfigurer itself. Generally, VelocityConfigurer offers more =
options now:
- by default, reads "WEB-INF/velocity.properties"
- different config file via "configLocation"
- "velocityProperties" to override certain properties in the bean =
definition
- or "velocityProperties" to specify all necessary properties in the =
bean definition
- a "webAppRootMarker" that gets replaced with the web app root =
directory in Velocity property values
- an "overrideLogging" flag to redirect Velocity log output to Commons =
logging (true by default)
This can look as follows:
<bean id=3D"velocityConfigurer" =
class=3D"com.interface21.web.servlet.view.velocity.VelocityConfigurer">
<!--
<property =
name=3D"configLocation"><value>WEB-INF/my-velocity.properties</value></pr=
operty>
-->
<property name=3D"velocityProperties">
<props>
<prop key=3D"resource.loader">file</prop>
<prop =
key=3D"file.resource.loader.class">org.apache.velocity.runtime.resource.l=
oader.FileResourceLoader</prop>
<prop key=3D"file.resource.loader.path">${webapp.root}</prop>
</props>
</property>
</bean>
The "webAppRootMarker" mechanism works for both local properties and =
Velocity config files. The default marker is "${webapp.root}", same as =
the default marker for the respective system property that gets used in =
Log4J config files to refer to the web app resource base (see =
WebAppRootListener and Log4jConfigListener). All occurences of this =
marker in Velocity property values get replaced with the web app root =
directory. Obviously, this just makes sense in path definitions.
I consider this more flexible than patching the path properties by =
resource loader name. For example, you might define not one resource =
loader but a chain of them. Your code wouldn't have worked then.
I hope you like the new mechanism - of course I'm open for feedback!
Regards,
Juergen
-----Original Message-----
From: dar...@hs... [mailto:dar...@hs...]
Sent: Wednesday, August 06, 2003 2:07 PM
To: spr...@li...
Subject: [Springframework-developer] Velocity configuration patch (MVC
framework)
I know you guys are busy with imminent package renames and releases, so
apologies in advance if this is the wrong time to be sending patches!
Attached is a class that extends
com.interface21.web.servlet.view.velocity.VelocityConfigurer in order to
permit velocity templates to be portably loaded from within the WAR =
without
having them in the source tree (and thereby the classpath). The =
overridden
initApplicationContext() method prefixes the template path root with the
real path to the WAR root. The javadoc for the class should make it =
clear.
In order for this to work, the superclass (VelocityConfigurer) needs to
have the location field promoted from private to protected. The only
alternative would be to override the setLocation() method in
WarVelocityConfigurer too which is the wrong way to do it I think. The
very trivial patch file for this change is also attached.
The code relies on the web container using exploded WAR files. Tomcat =
and
WebSphere both do by default, but I'm not sure that WebLogic does.
Both changes are based on the 0.9 release (I've no access to CVS at =
present
to see if updates are available to this part of Spring) and have been
tested successfully in the following locations:
WebSphere 4.0.4 on Windows
WebSphere 5.0 on Windows
Tomcat 4.1.18 on Windows
Tomcat 4.1.24 on Linux
Regards,
Darren Davison
CIBM Intranet Team
int> 799 19431
ext> +44 (0)20 7991 9431
(See attached file: WarVelocityConfigurer.java)(See attached file:
VelocityConfigurer.patch)
_____________________________________________________
This transmission has been issued by a member of the HSBC Group=20
"HSBC" for the information of the addressee only and should not be=20
reproduced and / or distributed to any other person. Each page attached=20
hereto must be read in conjunction with any disclaimer which forms part=20
of it. Unless otherwise stated, this transmission is neither an offer =
nor the=20
solicitation of an offer to sell or purchase any investment. Its =
contents are=20
based on information obtained from sources believed to be reliable but
HSBC makes no representation and accepts no responsibility or liability =
as=20
to its completeness or accuracy.
|