Thanks, Nathan for your fine reply!  I had looked at the toolbox API and had
similar impression but hoped I was missing something.

I need to limit the scope of which tools are available when, so I probably
need ServletToolboxManager.

I wish to forego web.xml as well.  I am using Jetty 6.1.1 and I am pretty
sure this can support fully programmatic configuration of a WebAppContext
(not exactly sure how yet).

I look forward to your further explanation, and to Tools 2.0 as well!
David


On 3/27/07, Nathan Bubna <[EMAIL PROTECTED]> wrote:

On 3/27/07, David Donohue <[EMAIL PROTECTED]> wrote:
> Sorry if this has been addressed but I have searched and cannot find the
> complete answer.

Unfortunately, i don't think there is any tutorial or example code out
there for what you ask.      Not much effort has been put into
supporting this (though i'm looking to change that in VelocityTools
2.0).

> Can anyone kindly point me to a tutorial or example code showing how I
would
> completely configure Velocity programmatically?
> Specifically, I wish to configure a VelocityViewServlet with a toolbox,
but
> without using any of these configuration files:
> web.xml
> toolbox.xml
> velocity.properties

This is doable, but with limits.  I can try to point you in the right
direction and help you out where you get stuck.  Here's a start:

First, you need to create your own subclass of VelocityViewServlet.
There's really no way around that.  In that subclass, there are two
methods you will especially want to override:

loadConfiguration(ServletConfig)

and

initToolbox(ServletConfig)

These are your best opportunities to configure the VelocityEngine and
ToolboxManager.

Basically what you want to do in loadConfiguration() is return a new
ExtendedProperties
(
http://jakarta.apache.org/commons/collections/api/org/apache/commons/collections/ExtendedProperties.html
)
object upon which you have set your velocity properties
programmatically.  It's pretty simple, just create an instance, set
your props using addProperty(String,Object), then return it.   Don't
worry about calling super.loadConfiguration(), it doesn't matter if
you don't have a velocity.properties file defined.

In initToolbox(), things are a little trickier.  Support for
programmatically creating a toolbox is particularly poor, and creating
a ServletToolboxManager without at least an empty toolbox xml file is
sadly impossible as things stand.  So, you face a choice, you must
either create an empty toolbox.xml such as:

<toolbox>
</toolbox>

So that you may create a ServletToolboxManager and programmatically
configure the tools for it, or else you must forgo the extra servlet
support for the ServletToolboxManager and simply create an
XMLToolboxManager, which offers no ability to put tools in varying
scopes and may also limit which tools will work.  Make that decision
and then i can help you from there.  I don't have time to fully
describe both paths.

Oh, and know that there are improvements in this area on the horizon.
We're working on VelocityTools 2.0, including full, easy support for
programmatically creating toolboxes.

Oh, and finally, the web.xml is not something specific to the
VelocityViewServlet.  That is used by the servlet engine (e.g. Tomcat)
to initialize the servlet.  I don't know if you can skip on that, it
may depend on the nature of your webapp and the servlet engine used.

> Thanks for any direction!
> David
>

Reply via email to