Hi Travis,
There's some terminology confusion. Data are values meant to be
directly put into the context, they are not tool properties. Tool
properties are configured like this:
<tools>
<toolbox scope="request" thisIsAPropertyForAllToolsInThisToolbox="hello">
<property name="aTypedPropertyForAllToolsInThisToolbox"
value="true" type="boolean"/>
<tool key="my" class="org.mine.MyTool"
thisIsAPropertyForThisToolOnly="world"/>
</toolbox>
<property name="aPropertyForAllToolsInAnyToolbox" value="10" type="number"/>
</tools>
See: http://velocity.apache.org/tools/devel/config.xml.html
On Thu, Mar 18, 2010 at 10:56 AM, Travis P <[email protected]> wrote:
> I'm using VelocityTool 2.0-beta4 with Velocity 1.6.3 under Tomcat 6.0.24.
>
> I'm trying to figure out how I can pass some configuration info into my
> velocity tool.
>
> I expected the data to be passed to the configure routine, but I don't see
> it in the property map that is passed, or any other map that I could find to
> look at.
>
> Below is simple tools.xml and MyTool.java that pretty much show what I've
> tried. I do get output showing that MyTool's constructor and configure()
> method are called. I just get null from all property lookups. I also see
> Velocity printing this in the log output:
> Data 'GENERIC_TOOLS_AVAILABLE' -boolean-> true
> Data 'TOOLS_VERSION' -number-> 2.0
> Data 'VIEW_TOOLS_AVAILABLE' -boolean-> true
> Data 'my_data' -auto-> data 1
>
> That looks promising. But where can I query the value of "my_data"?
>
> -Travis
>
>
> I've got a configuration like this:
> =================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <tools>
>
> <toolbox scope="application">
> <tool key="my" class="MyTool" />
> <data key="my_data" value="data 2" />
> </toolbox>
>
> <data key="my_data" value="data 1" />
> </tools>
> =================
>
>
> =================
> @DefaultKey("my")
> public class MyTool
> {
> public MyTool()
> {
> System.err.println("MyTool init");
> }
>
> public void configure(Map props)
> {
> System.err.println("[my-conf] configure");
> for (Object meo : props.entrySet()) {
> Map.Entry me = (Map.Entry)meo;
> System.err.println("[my-conf] "+me.getKey()+" : " + me.getValue());
> }
>
> VelocityEngine ve = (VelocityEngine)props.get("velocityEngine");
>
> System.err.println("[my-conf] PG my_data=>'"+
> ve.getProperty("my_data")+"'");
>
> System.err.println("[my-conf] RS my_data=>'"+
>
> org.apache.velocity.runtime.RuntimeSingleton.getProperty("my_data")+"'");
>
> System.err.println("[my-conf] SY my_data=>'"+
> System.getProperty("my_data")+"'");
>
> }
> }
> ================
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]