On 3/15/07, Claude Brisson <[EMAIL PROTECTED]> wrote:
Hi Tim.

The tools can easily be used without the VelocityViewServlet.

        import org.apache.velocity.tools.view.XMLToolboxManager;
        ...
        XMLToolboxManager manager = new XMLToolboxManager();
        manager.load("...../toolbox.xml");
        Map toolbox = manager.getToolbox(null);

this will get you a toolbox of generic tools.  of course, most of
those can be used just by creating an instance and putting them in
your context all manually, if you don't mind hard-coding the work,
rather than putting it in toolbox.xml.

for View Tools (most of which need various servlet dependencies), you
will probably need to use the ServletToolboxManager and pass an
instance of the ChainedContext class (or your own implementation of
the ViewContext interface) as so:

ToolboxManager manager =
ServletToolboxManager.getInstance(servletContext, ".../toolbox.xml");
...
ChainedContext ctx = new ChainedContext(velocityEngine,
httpServletRequest, httpServletResponse, servletContext);
Map toolbox = manager.getToolbox(ctx);
ctx.setToolbox(toolbox);

and again, if you already have a context, you can put it inside the
ChainedContext like so:

ChainedContext ctx = new ChainedContext(myContext, velocityEngine,
httpServletRequest, httpServletResponse, servletContext);

yeah, this is a little more complicated, but it lets you use the
LinkTool and the other VelocityView tools.

You can then create a new Velocity context with:

        VelocityContext context = new VelocityContext(toolbox);

If the context already exists, then you can create a chained context:

        VelocityContext chained = new VelocityContext(toolbox,context);

You'll need the last VelocityTools release to do so (1.3). It may be
possible with 1.2 but with a slightly more complex code.


  Claude

Le jeudi 15 mars 2007 à 15:53 -0600, White, Tim a écrit :
> Hello!
>
>  Is there a straightforward way to add Velocity Tools to a standalone
> Velocity Engine (i.e. not the VelocityViewServlet)?
>
>  We have a custom JSP tag that is pulling in templates from a special
> backend, and we're trying to figure out how to add the Velocity tools to
> the context, without bein able to access toolbox.xml.
>
>  Ideally, if there were some params we could set on the instance or the
> context, that seems like the way to do it.
>
> Thanks in advance!
>
> Tim
>
>
> This communication is the property of Qwest and may contain confidential or
> privileged information. Unauthorized use of this communication is strictly
> prohibited and may be unlawful.  If you have received this communication
> in error, please immediately notify the sender by reply e-mail and destroy
> all copies of the communication and any attachments.


---------------------------------------------------------------------
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]

Reply via email to