You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Edgar Poce <ep...@fibertel.com.ar> on 2004/12/09 05:12:32 UTC

standalone toolbox loader

I'm trying to make a standalone toolbox loader and I have a question.

is necessary in a standalone application to create a new instance of 
each Velocity Tool each time a Context is created?

is a good idea to add a "singleton" parameter to toolbox.xml and thus 
create instances only if necessary?

Regards
Edgar

Mike Kienenberger wrote:
>>> What's the best practice for adding a Velocity Tool to the context in
>>>a standalone app?
>>>is it manually with something like "context.put("tool", new *Tool())" or
>>>there's a configuration setting I'm missing?
> 
> 
> Shinobu Kawai <sh...@gmail.com> wrote:
> 
>>I guess that's the normal method.  Or, you can use the toolbox
>>strategy like VelocityViewServlet and DVSL.
>>## It's not built into Velocity, so you'll have to implement if
>>yourself, though.
> 
> 
> If you came up with a standalone toolbox loader using the same format as 
> toolbox.xml and posted it, it might end up in the next version of velocity 
> tools :)
> 
> XMLToolboxManager probably does most if not all of what you need already.
> 
> -Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 

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


Re: standalone toolbox loader

Posted by Mike Kienenberger <mk...@alaska.net>.
Edgar Poce <ed...@gmail.com> wrote:
> I tried to post it but I get "You are not allowed to edit this page.". 

Click on "UserPreferences" in the upper-right-hand corner to log in.
Once you've done that, you can edit and add pages.

-Mike

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


Re: standalone toolbox loader

Posted by Edgar Poce <ed...@gmail.com>.
 >
 > Or, you can post it to the wiki page.
 >   http://wiki.apache.org/jakarta-velocity/
 >   http://wiki.apache.org/jakarta-velocity/VelocityTools
 >
 > ## I like the wiki page because it's easier to modify the code 
afterwards.  :)
 >
I tried to post it but I get "You are not allowed to edit this page.". 
So, I attach the patch. If anyone want to give it a try apply it on 
org.apache.velocity.tools.

In order to work the engine runtime property "standalone.toolbox.path" 
must return the path to the file with toolbox.xml format.  The 
toolbox.xml format is slightly modified to accept singleton lifecycle 
for tools.

Usage:
// Velocity Singleton model
VelocityContext ctx = new StandaloneContext() ;

// Velocity separate instance
VelocityEngine engine = new VelocityEngine();
engine.addProperty(StandaloneContext.PATH_KEY, "path");
engine.init();
StandaloneContext ctx = new StandaloneContext() ;
ctx.setToolbox(StandaloneToolboxManager.getToolbox(engine));

I also made a simple test case but I guess the subscribers won't be very 
happy if I send many attachments.

Thanks
Edgar



Shinobu Kawai wrote:
> Hi Edgar,
> 
> 
>>I made a StandaloneContext which contains a set of tools defined in
>>the toolbox.xml format and I extended a couple of ViewTool classes for
>>adding a property called singleton. The usage is: VelocityContext ctx =
>>new StandaloneContext().
>>
>>Uploading a patch to bugzilla is the proper way to propose contributions?
> 
> 
> Or, you can post it to the wiki page.
>   http://wiki.apache.org/jakarta-velocity/
>   http://wiki.apache.org/jakarta-velocity/VelocityTools
> 
> ## I like the wiki page because it's easier to modify the code afterwards.  :)
> 
> Best regards,
> -- Shinobu Kawai
> 
> --
> Shinobu Kawai <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 

Re: standalone toolbox loader

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Edgar,

> The patch I sent contains 6 classes. How should I upload this to the
> wiki? one class per page?

I think you can put it all in one page, using separate source code blocks.
{{{
class 1
}}}

{{{
class 2
}}}

and so on.
You can also attach the file to the page (though I've never tried it before).

> Sorry about the unexperience but it's my first attempt to contribute and
> I don't want to mess up the wiki.

If you mess things up, you can put it back again.  After all, it's a wiki.  :)
## or is it impossible to delete a page?

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


Re: standalone toolbox loader

Posted by Edgar Poce <ed...@gmail.com>.
 > Click on "UserPreferences" in the upper-right-hand corner to log in.
 > Once you've done that, you can edit and add pages.
Now I know how to upload it to the wiki. Thanks, mike.

 > ## I like the wiki page because it's easier to modify the code 
afterwards.  :)
 >
The patch I sent contains 6 classes. How should I upload this to the 
wiki? one class per page?

Sorry about the unexperience but it's my first attempt to contribute and 
I don't want to mess up the wiki.

Best regards
Edgar

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


Re: standalone toolbox loader

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Edgar,

> I made a StandaloneContext which contains a set of tools defined in
> the toolbox.xml format and I extended a couple of ViewTool classes for
> adding a property called singleton. The usage is: VelocityContext ctx =
> new StandaloneContext().
> 
> Uploading a patch to bugzilla is the proper way to propose contributions?

Or, you can post it to the wiki page.
  http://wiki.apache.org/jakarta-velocity/
  http://wiki.apache.org/jakarta-velocity/VelocityTools

## I like the wiki page because it's easier to modify the code afterwards.  :)

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


Re: standalone toolbox loader

Posted by Edgar Poce <ed...@gmail.com>.
I made a StandaloneContext which contains a set of tools defined in
the toolbox.xml format and I extended a couple of ViewTool classes for
adding a property called singleton. The usage is: VelocityContext ctx =
new StandaloneContext().

Uploading a patch to bugzilla is the proper way to propose contributions?

Nathan Bubna wrote:
> On Thu, 09 Dec 2004 01:12:32 -0300, Edgar Poce <ep...@fibertel.com.ar> wrote:
> 
>>I'm trying to make a standalone toolbox loader and I have a question.
>>
>>is necessary in a standalone application to create a new instance of
>>each Velocity Tool each time a Context is created?
> 
> 
> it depends on the application and the tools.
> 
> 
>>is a good idea to add a "singleton" parameter to toolbox.xml and thus
>>create instances only if necessary?
> 
> 
> hmm.  again, i'd say it probably depends.  if you've looked at the
> ServletToolboxManager (which extends XMLToolboxManager), you'll see it
> extends the toolbox.xml format to support a "scope" element that
> allows you to put singleton-ish tools in the application scope and
> thus only be instantiated once.
> 
> if it suits your application's purposes, then adding a "singleton"
> parameter shouldn't be too hard and could be quite useful.
> 
> 
>>Regards
>>Edgar
>>
>>Mike Kienenberger wrote:
>>
>>>>>What's the best practice for adding a Velocity Tool to the context in
>>>>>a standalone app?
>>>>>is it manually with something like "context.put("tool", new *Tool())" or
>>>>>there's a configuration setting I'm missing?
>>>
>>>
>>>Shinobu Kawai <sh...@gmail.com> wrote:
>>>
>>>
>>>>I guess that's the normal method.  Or, you can use the toolbox
>>>>strategy like VelocityViewServlet and DVSL.
>>>>## It's not built into Velocity, so you'll have to implement if
>>>>yourself, though.
>>>
>>>
>>>If you came up with a standalone toolbox loader using the same format as
>>>toolbox.xml and posted it, it might end up in the next version of velocity
>>>tools :)
>>>
>>>XMLToolboxManager probably does most if not all of what you need already.
>>>
>>>-Mike
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 


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


Re: standalone toolbox loader

Posted by Nathan Bubna <nb...@gmail.com>.
On Thu, 09 Dec 2004 01:12:32 -0300, Edgar Poce <ep...@fibertel.com.ar> wrote:
> I'm trying to make a standalone toolbox loader and I have a question.
> 
> is necessary in a standalone application to create a new instance of
> each Velocity Tool each time a Context is created?

it depends on the application and the tools.

> is a good idea to add a "singleton" parameter to toolbox.xml and thus
> create instances only if necessary?

hmm.  again, i'd say it probably depends.  if you've looked at the
ServletToolboxManager (which extends XMLToolboxManager), you'll see it
extends the toolbox.xml format to support a "scope" element that
allows you to put singleton-ish tools in the application scope and
thus only be instantiated once.

if it suits your application's purposes, then adding a "singleton"
parameter shouldn't be too hard and could be quite useful.

> Regards
> Edgar
> 
> Mike Kienenberger wrote:
> >>> What's the best practice for adding a Velocity Tool to the context in
> >>>a standalone app?
> >>>is it manually with something like "context.put("tool", new *Tool())" or
> >>>there's a configuration setting I'm missing?
> >
> >
> > Shinobu Kawai <sh...@gmail.com> wrote:
> >
> >>I guess that's the normal method.  Or, you can use the toolbox
> >>strategy like VelocityViewServlet and DVSL.
> >>## It's not built into Velocity, so you'll have to implement if
> >>yourself, though.
> >
> >
> > If you came up with a standalone toolbox loader using the same format as
> > toolbox.xml and posted it, it might end up in the next version of velocity
> > tools :)
> >
> > XMLToolboxManager probably does most if not all of what you need already.
> >
> > -Mike
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
>

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