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 ?
> This is what the stack looks like:
>
> ------------------------------------------------------------------------------
> ERROR [2008-04-03 12:40:52,224] (CommonsLoggingLogSystem.java:43) -
> ResourceManager : unable to find resource '/acegilogin.vm' in any resource
> loader.
> ERROR [2008-04-03 12:40:52,228] (StandardWrapperValve.java:253) -
> Servlet.service() for servlet newtimesheets threw exception
> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> resource '/acegilogin.vm'
> at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
> at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1077)
> at
> org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:528)
> at
> org.springframework.web.servlet.view.velocity.VelocityView.getTemplate(VelocityView.java:535)
> at
> org.springframework.web.servlet.view.velocity.VelocityView.getTemplate(VelocityView.java:520)
> at
> org.springframework.web.servlet.view.velocity.VelocityView.checkTemplate(VelocityView.java:293)
> at
> org.springframework.web.servlet.view.velocity.VelocityLayoutView.checkTemplate(VelocityLayoutView.java:122)
>
> ------------------------------------------------------------------------------
odd. i would have expected an issue with tool management, not resource finding.
> How does the VelocityLayoutServlet configure which ResourceManager it will
> use?
> I have been looking at the code and I can't seem to figure that part out.
> Does
> it use the WebappResourceLoader? If so, where does that get configured?
>
> If I mess with the properties and make Velocity use the FileResourceLoader
> and put
> in the whole path to the webapp, it finds the files. Yippie! But, it
> doesn't know
> what to do with the references to the tools. :(
>
> 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);
> }
this is not only the old way of doing things, but not surprisingly, it
uses parts of the old API that just couldn't be transitioned neatly to
the new tool management API. basically, all this code is the same as
in Tools 1.4, but deprecated. so, even if we got this Spring code to
run with the Tools 2 jar, it won't be taking advantage of any new
code. even if we get it to that point, there really isn't much point
until Spring is updated to recognize and support the new tool
management API.
> ------------------------------------------------------------------------------
>
> Is that how the new VelocityTools does it? Or the old VelocityTools?
old way
> 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?
>
> Sorry, that's a lot of questions in a lot of text. Here is a summary:
>
> 1) If I use the FileResourceManager specifically, it finds templates.
> 2) But, the path to the webapp can change, so I have to find the right way.
definitely!
> 3) Even when I get templates to load, tools do not.
> 4) What is the new implementation for loading the tools so I can write my
> own
> Spring file to replace what they have?
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).
if not, then things are a bit trickier. the template loading question
is particularly perplexing, as not much has changed there in Tools 2.
all i did was deprecate the o.a.v.tools.view.servlet.WebappLoader and
make it extend its replacement
(o.a.v.tools.view.WebappResourceLoader). i'm really confused as to
why WebappLoader doesn't still work. or perhaps Spring didn't ever
use WebappLoader? how does Spring configure Velocity's resource
loaders?
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.
>
>
> Thanks so much.
>
>
> Charlie
>
>
>
>
> Nathan Bubna said the following on 4/2/2008 2:05 PM:
>
>
>
> > hmm. i haven't yet heard or seen any support for Tools 2 from the
> > Spring folks. i would at least just try swapping in the tools 2 jar.
> > if that works, then you might as well just try replacing your
> > toolbox.xml with a tools.xml. i'm really not deeply familiar with how
> > Spring went about integrating toolbox support into their views.
> >
> > i would try bringing this up in their forums. if they aren't already
> > watching Tools 2, it'd be good for them to be aware that its API has
> > stabilized and it's pretty much just waiting on docs, updated examples
> > and maybe further feedback before final release.
> >
> > though Spring is largely SpringSource's baby, it is still open source.
> > so i suppose you could just try writing/contributing a
> > VelocityTools2View or a patch for VelocityToolboxView yourself. i
> > wish i could offer time to help with that, but i've got higher
> > priorities at the moment.
> >
> > feel free to keep up with more specific questions on this. i am also
> > planning to write a doc to help framework devs (like the Spring guys)
> > integrate Tools 2 into their Velocity support.
> >
> > On Wed, Apr 2, 2008 at 10:44 AM, Charles Harvey III <[EMAIL PROTECTED]>
> wrote:
> >
> >
> > > Ok. Tougher question. I use Spring as my framework so I never actually
> put
> > > the VelocityLayoutServlet in my web.xml. Instead, I have something
> like so
> > > in my whatever-servlet.xml file:
> > >
> > > <bean id="viewResolver"
> > >
> class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
> > > <property name="viewClass"
> > >
> value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"/>
> > > <property name="cache" value="true"/>
> > > <property name="prefix" value=""/>
> > > <property name="suffix" value=".vm"/>
> > > <property name="exposeRequestAttributes" value="true"/>
> > > <property name="exposeSessionAttributes" value="true"/>
> > > <property name="exposeSpringMacroHelpers" value="true"/>
> > > <property name="layoutUrl" value="/layouts/default_layout.vm"/>
> > > <property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/>
> > > </bean>
> > >
> > > So, what changes? How do I make Spring aware that I am using the new
> > > tools-2.0?
> > > The VelocityToolboxView seems to accommodate the tools-1.2 and
> tools-1.3
> > > when configuring
> > > a tool:
> > >
> > >
> http://springframework.cvs.sourceforge.net/springframework/spring/src/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java?view=markup
> > >
> > > So do I just need the change the above to point to /WEB-INF/tools.xml
> > > instead of toolbox.xml?
> > >
> > > Does anyone else use Spring? Has anyone tried the new tools setup with
> > > Spring?
> > >
> > > Thanks again.
> > >
> > >
> > > Charlie
> > >
> > >
> > > Nathan Bubna said the following on 4/1/2008 3:16 PM:
> > >
> > >
> > >
> > >
> > >
> > > > yep, that's the idea. as for the init() method, you only need it if
> > > > your tool needs access to the initData for that scope (ServletContext
> > > > for application scope and ViewContext for request or session scope).
> > > > if your tool doesn't need access to any of those things, then it
> > > > doesn't need an init(Object) method.
> > > >
> > > > of course, this is all with Tools 1.3 or Tools 1.4. with Tools 2,
> > > > things get even easier. :)
> > > >
> > > > On Tue, Apr 1, 2008 at 12:05 PM, Charles Harvey III
> <[EMAIL PROTECTED]>
> > > >
> > > >
> > > wrote:
> > >
> > >
> > > >
> > > >
> > > > > As far as your own tools goes, I want to make sure I've got it
> right:
> > > > >
> > > > > Old:
> > > > > -------------------------------------------------------------
> > > > > public class MyTool implements ViewTool
> > > > > {
> > > > > private String theString;
> > > > >
> > > > > public void init( Object o )
> > > > > {
> > > > > if( !( obj instanceof ViewContext ) )
> > > > > {
> > > > > throw new IllegalArgumentException( "Tool can only be
> > > > > initialized with a ViewContext" );
> > > > > }
> > > > > }
> > > > >
> > > > > public String getTheString()
> > > > > {
> > > > > return "this string comes from a velocity tool";
> > > > > }
> > > > > }
> > > > > -------------------------------------------------------------
> > > > >
> > > > >
> > > > > New:
> > > > > -------------------------------------------------------------
> > > > > public class MyTool
> > > > > {
> > > > > private String theString;
> > > > >
> > > > > public void init( Object o )
> > > > > {
> > > > > if( !( obj instanceof ViewContext ) )
> > > > > {
> > > > > throw new IllegalArgumentException( "Tool can only be
> > > > > initialized with a ViewContext" );
> > > > > }
> > > > > }
> > > > >
> > > > > public String getTheString()
> > > > > {
> > > > > return "this string comes from a velocity tool";
> > > > > }
> > > > > }
> > > > > -------------------------------------------------------------
> > > > >
> > > > >
> > > > > Do I still need the init method? Or can I skip that too?
> > > > >
> > > > > Thanks.
> > > > >
> > > > >
> > > > > Charlie
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Nathan Bubna said the following on 4/1/2008 1:06 PM:
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > > there are some issues with multi-line comments within macros in
> > > > > >
> > > > > >
> > > > >
> > > >
> > > Velocity 1.5
> > >
> > >
> > > >
> > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > if you have written your own custom tools, then you'll find the
> > > > > > ViewTool and Configurable interfaces have been axed in
> VelocityTools
> > > > > > 1.4. just remove the implements declarations for those
> interfaces.
> > > > > > they are unnecessary, as Tools 1.4 will automatically look for
> their
> > > > > > methods in any tool class. if you haven't written any tools of
> your
> > > > > > own, i don't think there's anything to be concerned about.
> > > > > >
> > > > > > that's all i can think of right now, but of course, feel free to
> ask
> > > > > > questions/report problems here.
> > > > > >
> > > > > > On Tue, Apr 1, 2008 at 8:49 AM, Glenn Holmer
> <[EMAIL PROTECTED]>
> > > > >
> > > > >
> > > >
> > > wrote:
> > >
> > >
> > > >
> > > > > >
> > > > > >> I'm doing maintenance on an app that uses Velocity 1.4 and
> > > > >
> > > > >
> > > >
> > > VelocityTools
> > >
> > >
> > > >
> > > > > >> 1.1, and would like to upgrade to Velocity 1.5 and tools 1.4.
> Are
> > > > >
> > > > >
> > > >
> > > there
> > >
> > >
> > > >
> > > > > >> any gotchas I should watch out for?
> > > > > >>
> > > > > >> --
> > > > > >> ____________________________________________________________
> > > > > >> Glenn Holmer [EMAIL PROTECTED]
> > > > > >> Software Engineer phone: 414-908-1809
> > > > > >> Weyco Group, Inc. fax: 414-908-1601
> > > > > >>
> > > > > >>
> > > > > >>
> > > > >
> > > > >
> > > >
> > > ---------------------------------------------------------------------
> > >
> > >
> > > >
> > > > > >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > >> For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > >>
> > > > > >>
> > > > > >>
> > > > > >
> > > > > >
> ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]