You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by David Parks <da...@yahoo.com> on 2010/11/03 12:00:45 UTC

Documentation for tools xml configuration?

I see an example configuration file on the website, but no docs that explain
the configuration format. Is there something I missed? There are a lot of
options there and I'm having troubles figuring it all out. 



A few specific questions:

What is the scope parameter, I see request|session|application? Do new
objects get created per request/scope if you select request or session? 
<toolbox scope=. />

How can I extend a class (for example I want to extend MathTool to correct
the rounding problems noted previously). I can add my own $mymath custom
class (there's an example of that), but if I try to change the name to
"math" it doesn't seem to override the existing $math class.

There is this example:
   <tool class="org.apache.velocity.tools.generic.DateTool"/>
Can someone just explain what that's doing period? 

In this example:
   <tool key="custom" class="org.mine.CustomTool"
randomProperty="whatever"/>
Does the "randomProperty" get called as a setter of org.mine.CustomTool
(e.g. upon creating the object does it then call
customTool.setRandomProperty(...) )?

I see an example "restrictTo" property of <tool ...> but what is possible in
that field? A comma separated list, are regular expressions of any kind
supported?


Perhaps some comments in that example file would be enough to make
everything clear.


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


Re: Documentation for tools xml configuration?

Posted by Nathan Bubna <nb...@gmail.com>.
On Wed, Nov 3, 2010 at 5:34 AM, Claude Brisson <cl...@renegat.net> wrote:
> On 03/11/2010 12:00, David Parks wrote:
>>
>> I see an example configuration file on the website, but no docs that
>> explain
>> the configuration format. Is there something I missed? There are a lot of
>> options there and I'm having troubles figuring it all out.
>>   A few specific questions:
>>
>> What is the scope parameter, I see request|session|application? Do new
>> objects get created per request/scope if you select request or session?
>> <toolbox scope=. />
>>
>>
>
> Those scopes only make sense in the context of a web application. Toolboxes
> gather tools within a same scope.
> Request-scoped toolboxes get created for each request, session-scoped tools
> get created only once per session, and application-scoped tools are only
> created once for the lifetime of the application.

Not quite.  Session only makes sense in a webapp, but both request and
application scope are legitimate for any app.  Application scope means
that the tool instances are created once and used throughout the life
of the app.  Request scope means that you get new tool instances for
every call to toolManager.createContext(...).  Obviously, this aligns
with a servletrequest in a webapp, but in a generic app, people might
still call createContext multiple times (say, once per template
merge).

>> How can I extend a class (for example I want to extend MathTool to correct
>> the rounding problems noted previously). I can add my own $mymath custom
>> class (there's an example of that), but if I try to change the name to
>> "math" it doesn't seem to override the existing $math class.
>>
>>
>
> Do you mean that you had an entry like:
> <tool key="math" class="my.custom.math.Class"/>
> and that $math were still referring to the original math tool?
> It should not hapen.
>>
>> There is this example:
>>    <tool class="org.apache.velocity.tools.generic.DateTool"/>
>> Can someone just explain what that's doing period?
>>
>>
>
> The DateTool has a default key: "date" (see
> http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/DateTool.html
> )
> so this line will add an instance of this class in the containing toolbox
> (typically an application-scoped toolbox).
>>
>> In this example:
>>    <tool key="custom" class="org.mine.CustomTool"
>> randomProperty="whatever"/>
>> Does the "randomProperty" get called as a setter of org.mine.CustomTool
>> (e.g. upon creating the object does it then call
>> customTool.setRandomProperty(...) )?
>>
>>
>
> Exactly, but if the tool also has the following method:
>  public void configure(Map params)
> then it will also be called with all configuration parameters (plus other
> standard properties detailed here:
> http://velocity.apache.org/tools/releases/2.0/creatingtools.html )
>>
>> I see an example "restrictTo" property of<tool ...>  but what is possible
>> in
>> that field? A comma separated list, are regular expressions of any kind
>> supported?
>>
>
> This property is detailed in this page:
> http://velocity.apache.org/tools/releases/2.0/view.servlet.html
> It can be an exact path or a path ending with *.
>>
>> Perhaps some comments in that example file would be enough to make
>> everything clear.
>>
>>
>>
>
> You are most welcome if you want to improve us writing this documentation.
> We all have daily jobs...
>
>
>   Claude
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: Documentation for tools xml configuration?

Posted by Claude Brisson <cl...@renegat.net>.
On 03/11/2010 12:00, David Parks wrote:
> I see an example configuration file on the website, but no docs that explain
> the configuration format. Is there something I missed? There are a lot of
> options there and I'm having troubles figuring it all out.
>    
> A few specific questions:
>
> What is the scope parameter, I see request|session|application? Do new
> objects get created per request/scope if you select request or session?
> <toolbox scope=. />
>
>    
Those scopes only make sense in the context of a web application. 
Toolboxes gather tools within a same scope.
Request-scoped toolboxes get created for each request, session-scoped 
tools get created only once per session, and application-scoped tools 
are only created once for the lifetime of the application.
> How can I extend a class (for example I want to extend MathTool to correct
> the rounding problems noted previously). I can add my own $mymath custom
> class (there's an example of that), but if I try to change the name to
> "math" it doesn't seem to override the existing $math class.
>
>    
Do you mean that you had an entry like:
<tool key="math" class="my.custom.math.Class"/>
and that $math were still referring to the original math tool?
It should not hapen.
> There is this example:
>     <tool class="org.apache.velocity.tools.generic.DateTool"/>
> Can someone just explain what that's doing period?
>
>    
The DateTool has a default key: "date" (see 
http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/DateTool.html 
)
so this line will add an instance of this class in the containing 
toolbox (typically an application-scoped toolbox).
> In this example:
>     <tool key="custom" class="org.mine.CustomTool"
> randomProperty="whatever"/>
> Does the "randomProperty" get called as a setter of org.mine.CustomTool
> (e.g. upon creating the object does it then call
> customTool.setRandomProperty(...) )?
>
>    
Exactly, but if the tool also has the following method:
   public void configure(Map params)
then it will also be called with all configuration parameters (plus 
other standard properties detailed here:
http://velocity.apache.org/tools/releases/2.0/creatingtools.html )
> I see an example "restrictTo" property of<tool ...>  but what is possible in
> that field? A comma separated list, are regular expressions of any kind
> supported?
>    
This property is detailed in this page:
http://velocity.apache.org/tools/releases/2.0/view.servlet.html
It can be an exact path or a path ending with *.
> Perhaps some comments in that example file would be enough to make
> everything clear.
>
>
>    
You are most welcome if you want to improve us writing this 
documentation. We all have daily jobs...


    Claude


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