Ok. looking back at your original code again (I didn't see the diff notation as important in my quick glance)...
$context isn't likely to exist. "$x" translates to "context.get(x)" There's no line to configure (load the tools into) your ToolManager. >From the link you provided it's done with: manager.configure("/path/to/my/configuration.xml"); Looking further here shows that you need a more extensive constructor to pick up a default set of tools without providing configuration: https://velocity.apache.org/tools/3.1/generic.html /* Create the manager. autoConfigure and includeDefaults are both booleans which default to true. */ ToolManager manager = new ToolManager(autoConfigure, includeDefaults); On Fri, Feb 4, 2022 at 2:08 AM Stefan Großhauser < stefan.grosshau...@hammerbachergmbh.de> wrote: > > Hello Mike, > > > my code listing was rather a patch, note the - und + symbols at the > beginning of each line. > It was meant to indicate that the - line is replaced by the + lines. > > > Thank you very much for showing that the tools can be put() manually like > that, so that I can get away without using ToolManager. > That answers my question. > > > > Thank you! > > > cheers > Stefan > > > > Von: Mike Kienenberger <mkien...@gmail.com> > An: Velocity Users List <user@velocity.apache.org> > Kopie: Stefan Großhauser <stefan.grosshau...@hammerbachergmbh.de> > Gesendet: 03.02.2022 15:20 > Betreff: Re: Usage of ToolManager > > I haven't used Velocity 2 or ToolManager 3, but the basics of Velocity are > very simple. > > You create a VelocityContext (which is effectively a Java.util.Map). > You "put" objects into it with String keys. > You reference these string keys in your template. > > In the setup code: > > VelocityContext context = ... > context.put("anything", new Object()); > > in the template: > > $anything > > > VelocityContexts differ from Maps in that they can also wrap one or more > other VelocityContexts to which they will delegate lookups. > > Generally it works along the lines of > > VelocityContext myAppContext is created with a delegate of ToolContext. > So it first tries to find your key in myAppContext. If not found, it > will > try to find your key in ToolContext. > > So a ToolManager context for Velocity 1.x is just another > VelocityContext. > > Glancing at your code, I see that you first created a myAppContext. > Then you create a ToolManager context (with the same name?) > > But I don't see that you've linked these together. > > Normally, you'd do something like this to create your myAppContext: > > ToolboxContext toolCtx = mgr.getToolboxContext(null); > VelocityContext myAppContext = new VelocityContext(toolCtx); > > Again, though, the only reason to use a ToolManager is to make it easier > to > configure a context. > Either because the ToolManager supports grabbing the objects from file > (ie, > XMLToolboxManager.class) > or because it grabs them from a hardcoded list or reflectively-generated > list. And then it "put"s these object into a VelocityContext that it > makes available to you via getToolboxContext(); > > You can certainly start by just dumping objects directly into your > context. > > context.put("esc", new EscapeTool()); > context.put("request", httpRequest); > context.put("context", context); > > Or creating your own ToolManager: > > class MyToolManager implements ToolManager { > ToolboxContext getToolboxContext(Object initData) { > VelocityContext context = new VelocityContext(); > context.put("esc", new EscapeTool()); > context.put("request", httpRequest); > context.put("context", context); > return context; > } > > void addTool(ToolInfo info) { > // you can get more fancy by implementing this to fetch tool > config rather than hard coding classes above > }; > } > > Because Velocity is such a simple idea, you can review the Velocity source > code if you want to see what's going on internally with Velocity contexts > and ToolManagers.. > > > > > > > > JETZT NEWSLETTER ABONNIEREN: > https://hammerbacher.com/newsletter-anmeldung/ > Hammerbacher GmbH Geschäftsführer Bernhard Hammerbacher, Ursula > Hammerbacher Registergericht Nürnberg HRB 10908 > Hausanschrift > Daimlerstraße 4-6 > D 92318 Neumarkt Telefon > +49(0)9181 > 2592-0 Telefax > +49(0)9181 > 2592-28 E-Mail > i...@hammerbachergmbh.de > www.hammerbacher.com > > > > Haftungsausschluss / Disclaimer > Die Informationen, die in dieser Kommunikation enthalten sind, sind > ausschließlich und allein für den Empfänger bestimmt. Die Verwendung durch > Dritte ist untersagt. Die Firma Hammerbacher GmbH ist nur für die von ihr > eingegeben Informationen verantwortlich, jedoch nicht für die einwandfreie > Übertragung oder im Zusammenhang mit der Übertragung oder dem Empfang > eingetretene Veränderungen oder Verzögerungen. > Diese E-Mail enthält vetrtrauliche und/oder rechtlich geschützte > Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail > irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und > vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte > Weitergabe dieser Mail ist nicht gestattet. >