I had the same question before, finally I still chose VelocityView. Since VelocityView is for webapp, I had to use MockServletContext and MockServletConfig:
public MyVelocityEngine(ServletContext servletContext, String velocityPropertiesFile) throws ServletException { MockServletConfig msc = new MockServletConfig(); msc.addInitParameter("org.apache.velocity.properties", velocityPropertiesFile); msc.addInitParameter("org.apache.velocity.tools.loadDefaults", "false"); msc.setServletContext(servletContext); JeeConfig config = new JeeConfig(msc); _view = new VelocityView(config); } MockServletContext msc = new MockServletContext(appRoot, new FileSystemResourceLoader()); MyVelocityEngine engine = new MyVelocityEngine(msc, "..."); Then, when I want to load tools from xml files, use VelocityView.configure(): public void loadTools(File toolXml) throws FileNotFoundException, IOException { XmlFactoryConfiguration conf = new XmlFactoryConfiguration(); conf.read(new FileInputStream(toolXml)); _view.configure(conf); } I am not sure if I am using Velocity in a good manner, but MyVelocityEngine works well. Maybe there are better ways:) yours, bluejoe ----- Original Message ----- From: "Steve Cohen" <sco...@javactivity.org> To: "Velocity Users List" <user@velocity.apache.org> Sent: Tuesday, July 21, 2009 5:51 AM Subject: Re: Escaping question > Okay, I found THIS: > > http://www.mailinglistarchive.com/velocity-u...@jakarta.apache.org/msg00552.html > > and it works, but I'd still rather load the tool at the time the Engine > is initialized, rather than have to put it in the context everywhere I > want to use it. So what I'm really looking for is a way to do that. > > > > Steve Cohen wrote: >> >> Steve Cohen wrote: >> >> ... >> >> (never mind any of what I wrote before, I have now boiled it down to >> one hopefully intelligent question): >> >> >> I am NOT using VelocityView but instantiating, configuring and >> initializing a VelocityEngine in java code. I don't use Velocity View. >> Since I don't use VelocityView, and the documentation for Velocity >> Tools assumes I do >> >> (http://velocity.apache.org/tools/releases/1.4/generic/EscapeTool.html) >> telling me this: >> >>> *Toolbox Configuration Example* >>> >>> <tool> >>> <key>esc</key> >>> <scope>application</scope> >>> <class>org.apache.velocity.tools.generic.EscapeTool</class> >>> </tool> >>> >> how do I perform this same step in java code (i.e. what >> applicationAttributes or runtime Properties must I set, in order for >> my VelocityEngine to see the Tools generally or the EscapeTool in >> particular (which is all I need)? >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org >> For additional commands, e-mail: user-h...@velocity.apache.org >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org > For additional commands, e-mail: user-h...@velocity.apache.org >