Re: Usage of ToolManager

Stefan Großhauser <[email protected]> Fri, 4 Feb 2022 08:08:28 +0100
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
--=-fcDRP9IC+ZFUUp8YC1LV
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable


Hello Mike=2C


my code listing was rather a patch=2C note the - und + symbols at the begin=
ning of each line=2E
It was meant to indicate that the - line is replaced by the + lines=2E


Thank you very much for showing that the tools can be put=28=29 manually li=
ke that=2C so that I can get away without using ToolManager=2E
That answers my question=2E



Thank you!


cheers
Stefan



 Von=3A   Mike Kienenberger =3Cmkienenb=40gmail=2Ecom=3E=20
 An=3A   Velocity Users List =3Cuser=40velocity=2Eapache=2Eorg=3E=20
 Kopie=3A   Stefan Gro=C3=9Fhauser =3Cstefan=2Egrosshauser=40hammerbachergm=
bh=2Ede=3E=20
 Gesendet=3A   03=2E02=2E2022 15=3A20=20
 Betreff=3A   Re=3A Usage of ToolManager=20

I haven=27t used Velocity 2 or ToolManager 3=2C but the basics of Velocity=
 are=20
very simple=2E=20
=20
You create a VelocityContext =28which is effectively a Java=2Eutil=2EMap=29=
=2E=20
You =22put=22 objects into it with String keys=2E=20
You reference these string keys in your template=2E=20
=20
In the setup code=3A=20
=20
VelocityContext context =3D =2E=2E=2E=20
context=2Eput=28=22anything=22=2C new Object=28=29=29=3B=20
=20
in the template=3A=20
=20
=24anything=20
=20
=20
VelocityContexts differ from Maps in that they can also wrap one or more=20=

other VelocityContexts to which they will delegate lookups=2E=20
=20
Generally it works along the lines of=20
=20
VelocityContext myAppContext is created with a delegate of ToolContext=2E=
=20
So it first tries to find your key in myAppContext=2E =C2=A0 If not found=
=2C it will=20
try to find your key in ToolContext=2E=20
=20
So a ToolManager context for Velocity 1=2Ex =C2=A0is just another VelocityC=
ontext=2E=20
=20
Glancing at =C2=A0your code=2C I see that you first created a myAppContext=
=2E=20
Then you create a ToolManager context =28with the same name=3F=29=20
=20
But I don=27t see that you=27ve linked these together=2E=20
=20
Normally=2C you=27d do something like this to create your myAppContext=3A=
=20
=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0ToolboxContext toolCtx =3D mgr=2EgetToolboxCont=
ext=28null=29=3B=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0VelocityContext myAppContext =3D new VelocityCo=
ntext=28toolCtx=29=3B=20
=20
Again=2C though=2C the only reason to use a ToolManager is to make it easie=
r to=20
configure a context=2E=20
Either because the ToolManager supports grabbing the objects from file =28i=
e=2C=20
XMLToolboxManager=2Eclass=29=20
or because it grabs them from a hardcoded list or reflectively-generated=20=

list=2E =C2=A0 And then it =22put=22s these object into a VelocityContext t=
hat it=20
makes available to you via getToolboxContext=28=29=3B=20
=20
You can certainly start by just dumping objects directly into your context=
=2E=20
=20
context=2Eput=28=22esc=22=2C new EscapeTool=28=29=29=3B=20
context=2Eput=28=22request=22=2C httpRequest=29=3B=20
context=2Eput=28=22context=22=2C context=29=3B=20
=20
Or creating your own ToolManager=3A=20
=20
class MyToolManager implements ToolManager =7B=20
 =C2=A0 =C2=A0ToolboxContext getToolboxContext=28Object initData=29 =7B=20=

 =C2=A0 =C2=A0 =C2=A0 =C2=A0VelocityContext context =3D new VelocityContext=
=28=29=3B=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0context=2Eput=28=22esc=22=2C new EscapeTool=28=
=29=29=3B=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0context=2Eput=28=22request=22=2C httpRequest=29=
=3B=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0context=2Eput=28=22context=22=2C context=29=3B=
=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0return context=3B=20
 =C2=A0 =C2=A0 =7D=20
=20
 =C2=A0 =C2=A0void addTool=28ToolInfo info=29 =7B=20
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // you can get more fancy by implementing this=
 to fetch tool=20
config rather than hard coding classes above=20
 =C2=A0 =C2=A0=7D=3B=20
=7D=20
=20
Because Velocity is such a simple idea=2C you can review the Velocity sourc=
e=20
code if you want to see what=27s going on internally with Velocity contexts=
=20
and ToolManagers=2E=2E=20
=20
=20
=20


=20

JETZT NEWSLETTER ABONNIEREN=3A https=3A//hammerbacher=2Ecom/newsletter-anme=
ldung/
Hammerbacher GmbH Gesch=C3=A4ftsf=C3=BChrer Bernhard Hammerbacher=2C Ursula=
 Hammerbacher Registergericht N=C3=BCrnberg HRB 10908   =20
 =09Hausanschrift
Daimlerstra=C3=9Fe 4-6
D 92318 Neumarkt =09Telefon
+49=280=299181
2592-0 =09Telefax
+49=280=299181
2592-28 =09E-Mail
info=40hammerbachergmbh=2Ede
www=2Ehammerbacher=2Ecom


=20
Haftungsausschluss / Disclaimer=20
Die Informationen=2C die in dieser Kommunikation enthalten sind=2C sind aus=
schlie=C3=9Flich und allein f=C3=BCr den Empf=C3=A4nger bestimmt=2E Die Ver=
wendung durch Dritte ist untersagt=2E Die Firma Hammerbacher GmbH ist nur f=
=C3=BCr die von ihr eingegeben Informationen verantwortlich=2C jedoch nicht=
 f=C3=BCr die einwandfreie =C3=9Cbertragung oder im Zusammenhang mit der=20=
=C3=9Cbertragung oder dem Empfang eingetretene Ver=C3=A4nderungen oder Verz=
=C3=B6gerungen=2E
Diese E-Mail enth=C3=A4lt vetrtrauliche und/oder rechtlich gesch=C3=BCtzte=
 Informationen=2E Wenn Sie nicht der richtige Adressat sind oder diese E-Ma=
il irrt=C3=BCmlich erhalten=C2=A0 haben=2C informieren Sie bitte sofort den=
 Absender und vernichten Sie diese E-Mail=2E Das unerlaubte Kopieren sowie=
 die unbefugte Weitergabe dieser Mail ist nicht gestattet=2E

--=-fcDRP9IC+ZFUUp8YC1LV--