Nathan Bubna said the following on 4/3/2008 2:29 PM:
On Thu, Apr 3, 2008 at 10:09 AM, Charles Harvey III <[EMAIL PROTECTED]> wrote:
Well, I tried the drop-in replacement and it failed. It can't find the
template. Not sure why yet. I'm digging through the Spring code to see
what it is doing differently than Velocity.
that's a bummer. and the only thing changed was replacing the tools
1.x jar with the 2.0-beta.jar ?
Actually, I had moved from spring-1.2.9 to spring-2.5.2. But I did this
because
fixes to how spring loads up Velocity were made to the 2.x branch and
not the 1.x
branch. All I ever put into the spring config was the
resourceLoaderPath so I
have never been sure how spring loads up templates. Total mystery.
But, for some
reason, it started failing. It's all action-at-a-distance to me. So, I
figured
out how to set the FileResourceLoader and use the ${webapp.root} key to
do so.
Now all template loading works on spring-1.2.9 and spring-2.5.2 with
tools-1.2,
tools-1.3, tools-1.4 and tools-2.0-beta1. Whoopie!
So, I also have to look into how the new VelocityTools loads tools and how
it is
different from Spring. I'm sure Spring is calling Velocity to do this,
just not sure
where yet. I can setup a VelocityEngine in the configs, but that isn't
where the
tools.xml gets passed.
It has to be in this section of VelocityToolboxView:
------------------------------------------------------------------------------
// Load a Velocity Tools toolbox, if necessary.
if (getToolboxConfigLocation() != null) {
ToolboxManager toolboxManager = ServletToolboxManager.getInstance(
getServletContext(), getToolboxConfigLocation());
Map toolboxContext = toolboxManager.getToolbox(velocityContext);
velocityContext.setToolbox(toolboxContext);
}
Can
I simply
replace the ServletToolboxManager with XmlFactoryConfiguration? Is
ToolboxManager
still used?
no, there's no one-to-one correspondence between the old way and the
new way. but if you are willing to hack on Spring (or copy this View
class into your own version and hack that), i can probably help. what
is the method you got that code from trying to return? is it called
per request? what's the lifecycle of the class it belongs to?
That method returns a org.apache.velocity.context.Context.
--------------------------------------------------------------------------
protected Context createVelocityContext(
Map model, HttpServletRequest request, HttpServletResponse
response) throws Exception {
// Create a ChainedContext instance.
ChainedContext velocityContext = new ChainedContext(
new VelocityContext(model), getVelocityEngine(), request,
response, getServletContext());
// Load a Velocity Tools toolbox, if necessary.
if (getToolboxConfigLocation() != null) {
ToolboxManager toolboxManager = ServletToolboxManager.getInstance(
getServletContext(), getToolboxConfigLocation());
Map toolboxContext = toolboxManager.getToolbox(velocityContext);
velocityContext.setToolbox(toolboxContext);
}
return velocityContext;
}
--------------------------------------------------------------------------
The class itself is
org.springframework.web.servlet.view.velocity.VelocityToolboxView
http://springframework.cvs.sourceforge.net/springframework/spring/src/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java?view=markup
which extends
org.springframework.web.servlet.view.VelocityView:
http://springframework.cvs.sourceforge.net/springframework/spring/src/org/springframework/web/servlet/view/velocity/VelocityView.java?view=markup
Either of these two classes is used only once, it is the
VelocityViewResolver and
the VelocityLayoutViewResolver that are used on each request.
ideally, 1 thru 4 are all handled through a VelocityView object that
can be stored in the ServletContext and used to both retrieve
templates and create tool-supporting contexts. if you can access to
the ServletConfig instance in your replacement/hacked Spring MVC
classes that do template loading and context creation, then this could
be as simple as a call to
o.a.v.tools.view.ServletUtils.getVelocityView(servletConfig).
as for creating a tool-supporting context, that is more work without
being able to use a VelocityView instance, but is still do-able.
rather than explain all the options there, i'll wait to see if you
need such explanation. the basic idea is to create a
FactoryConfiguration object (probably XmlFactoryConfiguration will be
most familiar to you). then use that to configure a ToolboxFactory
instance. keep the ToolboxFactory around, don't re-init on each
request! then have your class do the same work as
VelocityView.prepareToolboxes(request) on each request. then create a
ViewToolContext instance and use that as the context for that request.
looking through the VelocityView methods for configuring the
ToolboxFactory might also be enlightening.
Well, I am going to try replacing Spring's VelocityToolboxView with my
own. From above
it looks as though I should be able to get at the ServletConfig if I
need to. I
will try figure out how to create a FactoryConfiguration object and then
setup
a ToolboxFactory. I'll post if I get it all figured out.
Charlie
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]