You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Haberman <mi...@ncsa.uiuc.edu> on 2004/07/22 21:34:35 UTC

Help needed for application scoped velocity tools (toolbox.xml)

I need to have an application scoped tool (i.e. via toolbox.xml) that 
can get at the servlet config/context.  


public class MyTool
{
   public void init(Object obj)
   {
      String name = obj.getClass().getName();
      log.info("tool init " + name);
   }

   // blah blah
}

   The initialization of this application-scoped tool shows:
    --> tool init com.caucho.server.webapp.Application

   But I won't always be using caucho.

   Looking at the other application-scoped tools (e.g. MathTool)
   there is no init() method.

   What am I missing?  It won't be init'd with a ViewContext so how
   do I get at the necessary resources ?

   thanks a ton!

   mike

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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Mike Haberman <mi...@ncsa.uiuc.edu>.
Thanks a ton.... It works like a charm.

mike

On Thu, Jul 22, 2004 at 03:15:02PM -0700, Nathan Bubna wrote:
> Mike Haberman said:
> > So inside my web.xml file (within the <servlet> config) :
> >
> > <init-param>
> >    <param-name>menuXML</param-name>
> >    <param-value>/conf/template.xml</param-value>
> > </init-param>
> >
> > So, (perhaps there is a better way), but I need to get at the
> > value attached to <menuXML>
> >
> > My tool needs to parse /conf/template.xml (it's a tool that one can
> > use to assign roles to templates).
> >
> > Is there a way to put config info inside the <tool>..</tool> tags ?
> 
> yes, actually.  but this function hasn't made it into a release yet. it's only
> in 1.2-dev (the current CVS head).  so, i can't promise that the new interface
> for this is entirely stable.  (in fact, i'm 95% sure it will switch packages,
> because right now this function is in the o.a.v.tools.view.tools.* package
> when it should be available to tools in the generic package as well.)
> 
> nonetheless, we're always happy to have more people working on/with the latest
> code.  so, if you're up to it, all you have to do is build the lastest code
> from CVS, and have your tool implement the new
> o.a.v.tools.view.tools.Configurable interface.  then you just add the
> configuration data to your tool definition like this:
> 
> <tool>
>     <key>mytool</key>
>     <scope>application</scope>
>     <class>com.org.net.MyTool</class>
>     <parameter name="menuXML" value="/conf/template.xml" />
> </tool>
> 
> and your tool's configure(Map) method will be pass a map of the specified
> parameter names/values after it has been created and before it is initialized.
> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

-- 
-------------------------------------------------
Mike Haberman
Senior Research Engineer
NCSA
-------------------------------------------------

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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Nathan Bubna <na...@esha.com>.
Mike Haberman said:
> So inside my web.xml file (within the <servlet> config) :
>
> <init-param>
>    <param-name>menuXML</param-name>
>    <param-value>/conf/template.xml</param-value>
> </init-param>
>
> So, (perhaps there is a better way), but I need to get at the
> value attached to <menuXML>
>
> My tool needs to parse /conf/template.xml (it's a tool that one can
> use to assign roles to templates).
>
> Is there a way to put config info inside the <tool>..</tool> tags ?

yes, actually.  but this function hasn't made it into a release yet. it's only
in 1.2-dev (the current CVS head).  so, i can't promise that the new interface
for this is entirely stable.  (in fact, i'm 95% sure it will switch packages,
because right now this function is in the o.a.v.tools.view.tools.* package
when it should be available to tools in the generic package as well.)

nonetheless, we're always happy to have more people working on/with the latest
code.  so, if you're up to it, all you have to do is build the lastest code
from CVS, and have your tool implement the new
o.a.v.tools.view.tools.Configurable interface.  then you just add the
configuration data to your tool definition like this:

<tool>
    <key>mytool</key>
    <scope>application</scope>
    <class>com.org.net.MyTool</class>
    <parameter name="menuXML" value="/conf/template.xml" />
</tool>

and your tool's configure(Map) method will be pass a map of the specified
parameter names/values after it has been created and before it is initialized.

Nathan Bubna
nathan@esha.com


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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Mike Haberman <mi...@ncsa.uiuc.edu>.
So inside my web.xml file (within the <servlet> config) :

<init-param>
   <param-name>menuXML</param-name>
   <param-value>/conf/template.xml</param-value>
</init-param>

So, (perhaps there is a better way), but I need to get at the
value attached to <menuXML>

My tool needs to parse /conf/template.xml (it's a tool that one can
use to assign roles to templates).


Is there a way to put config info inside the <tool>..</tool> tags ?


thanks again!

mike


 


On Thu, Jul 22, 2004 at 02:29:00PM -0700, Nathan Bubna wrote:
> Mike Haberman said:
> ...
> > So if the [application-scoped] tool is initialized with a ServletContext,
> > how does one get the ServletConfig ?
> ...
> 
> my first question would be, "why do you need it?"
> 
> but assuming you have a good reason...  you would probably have to put the
> config into the ServletContext's attributes during servlet init().  then your
> tool(s) can pull it from the ServletContext attributes.
> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

-- 
-------------------------------------------------
Mike Haberman
Senior Research Engineer
NCSA
-------------------------------------------------

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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Nathan Bubna <na...@esha.com>.
Mike Haberman said:
...
> So if the [application-scoped] tool is initialized with a ServletContext,
> how does one get the ServletConfig ?
...

my first question would be, "why do you need it?"

but assuming you have a good reason...  you would probably have to put the
config into the ServletContext's attributes during servlet init().  then your
tool(s) can pull it from the ServletContext attributes.

Nathan Bubna
nathan@esha.com


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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Mike Haberman <mi...@ncsa.uiuc.edu>.
thanks for taking time to answer.

So if the tool is initialized with a ServletContext,  how does one
get the ServletConfig ?  

thanks

mike

On Thu, Jul 22, 2004 at 01:18:32PM -0700, Nathan Bubna wrote:
> Mike Haberman said:
> > I need to have an application scoped tool (i.e. via toolbox.xml) that
> > can get at the servlet config/context.
> >
> > public class MyTool
> > {
> >    public void init(Object obj)
> >    {
> >       String name = obj.getClass().getName();
> >       log.info("tool init " + name);
> >    }
> >
> >    // blah blah
> > }
> >
> >    The initialization of this application-scoped tool shows:
> >     --> tool init com.caucho.server.webapp.Application
> >
> >    But I won't always be using caucho.
> 
> then it'll be whatever class implements javax.servlet.ServletContext in the
> servlet engine that you're using.
> 
> >    Looking at the other application-scoped tools (e.g. MathTool)
> >    there is no init() method.
> 
> not all tools need initialization.
> 
> >    What am I missing?  It won't be init'd with a ViewContext so how
> >    do I get at the necessary resources ?
> 
> only session and request scoped tools are init'd with a ViewContext.
> application scoped tools are init'd with the ServletContext.  for more on tool
> scoping and use/purpose of the ViewTool interface, read:
> 
> http://jakarta.apache.org/velocity/tools/view/index.html#Installation
> 
> particularly the "Tool Scopes" section.
> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

-- 
-------------------------------------------------
Mike Haberman
Senior Research Engineer
NCSA
-------------------------------------------------

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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Nathan Bubna <na...@esha.com>.
Mike Haberman said:
> I need to have an application scoped tool (i.e. via toolbox.xml) that
> can get at the servlet config/context.
>
> public class MyTool
> {
>    public void init(Object obj)
>    {
>       String name = obj.getClass().getName();
>       log.info("tool init " + name);
>    }
>
>    // blah blah
> }
>
>    The initialization of this application-scoped tool shows:
>     --> tool init com.caucho.server.webapp.Application
>
>    But I won't always be using caucho.

then it'll be whatever class implements javax.servlet.ServletContext in the
servlet engine that you're using.

>    Looking at the other application-scoped tools (e.g. MathTool)
>    there is no init() method.

not all tools need initialization.

>    What am I missing?  It won't be init'd with a ViewContext so how
>    do I get at the necessary resources ?

only session and request scoped tools are init'd with a ViewContext.
application scoped tools are init'd with the ServletContext.  for more on tool
scoping and use/purpose of the ViewTool interface, read:

http://jakarta.apache.org/velocity/tools/view/index.html#Installation

particularly the "Tool Scopes" section.

Nathan Bubna
nathan@esha.com


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


Re: Help needed for application scoped velocity tools (toolbox.xml)

Posted by Mike Haberman <mi...@ncsa.uiuc.edu>.
Answered my own question:  the init object implements ServletContext.



On Thu, Jul 22, 2004 at 02:34:35PM -0500, Mike Haberman wrote:
> 
> I need to have an application scoped tool (i.e. via toolbox.xml) that 
> can get at the servlet config/context.  
> 
> 
> public class MyTool
> {
>    public void init(Object obj)
>    {
>       String name = obj.getClass().getName();
>       log.info("tool init " + name);
>    }
> 
>    // blah blah
> }
> 
>    The initialization of this application-scoped tool shows:
>     --> tool init com.caucho.server.webapp.Application
> 
>    But I won't always be using caucho.
> 
>    Looking at the other application-scoped tools (e.g. MathTool)
>    there is no init() method.
> 
>    What am I missing?  It won't be init'd with a ViewContext so how
>    do I get at the necessary resources ?
> 
>    thanks a ton!
> 
>    mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

-- 
-------------------------------------------------
Mike Haberman
Senior Research Engineer
NCSA
-------------------------------------------------

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