You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Apache Wiki <wi...@apache.org> on 2007/10/27 00:38:41 UTC

[Velocity Wiki] Update of "VelocityTools2/ConfigJava" by NathanBubna

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Velocity Wiki" for change notification.

The following page has been changed by NathanBubna:
http://wiki.apache.org/velocity/VelocityTools2/ConfigJava

The comment on the change is:
rough draft of veltools2 java config

New page:
Of course, it is possible to configure things purely via Java, though this too is much easier than it was in VelocityTools 1.x. Here again, is an example that is equivalent to those above:

{{{
EasyFactoryConfiguration config = new EasyFactoryConfiguration();
config.toolbox("request").property("xhtml", true)
    .tool("toytool", ToyTool.class).restrictTo("index.vm")
    .tool("custom", CustomTool.class).property("randomProperty", "whatever");
config.toolbox("session").property("create-session", true)
    .tool("map", HashMap.class);
config.toolbox("application")
    .tool(DateTool.class);
config.number("version", 1.1);
config.data("date", "Mon Sep 17 10:08:03 PDT 2007")
    .target(Date.class)
    .converter(DateLocaleConverter.class);
config.bool("isSimple", true);
config.string("foo", "this is foo.");
config.string("bar", "this is bar.");
config.data("dataKeys", "list", "version,date,isSimple,foo,bar,dataKeys,switches");
config.data("switches", "list.boolean", "true,false,false,true");
}}}

This example uses the EasyFactoryConfiguration API for brevity, but you can also directly use the FactoryConfiguration/ToolboxConfiguration/ToolConfiguration/Data API, as you would probably do if you were to construct your configuration via an dependency injection framework (such as Spring).

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org