You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "George, Nixon" <Ge...@sutterhealth.org> on 2010/01/05 02:26:26 UTC

Get hold of RuntimeInstance

I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks


Re: Get hold of RuntimeInstance

Posted by Nathan Bubna <nb...@gmail.com>.
Well, hopefully you're running on a system where you control the
security permissions.  You'll have to use reflection to get the
RuntimeInstance out of the VelocityEngine, which is private.  Either
that or use a custom build of Velocity that gives access to the
RuntimeInstance.

On Wed, Jan 6, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
> This is VelocityEngine 1.6.2. I am using a custom cache implementation that also has a custom way of loading the template. The RuntimeInstance is then attached to the template which I now realize is the wrong runtimeinstance and instead should be the VelocityViewServlet's runtiminstance. Here is the code:
>
> <code>---------------------
> public static Template convertStringToTemplate(String input) throws ParseException, Exception {
>        Template template = new Template();
>        RuntimeServices runtimeServices =                                       RuntimeSingleton.getRuntimeServices();
>      StringReader reader = new StringReader(input);
>      SimpleNode node = runtimeServices.parse(reader, "UnusedTemplateName");
>      template.setRuntimeServices(runtimeServices);
>      template.setData(node);
>      template.initDocument();
>      return template;
> }
> ------------------</code>
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: Tuesday, January 05, 2010 7:49 PM
> To: Velocity Users List
> Subject: Re: Get hold of RuntimeInstance
>
> subclasses have access to the getVelocityEngine() method.  though, it
> returns the VelocityEngine wrapper instance, not the RuntimeInstance.
> If that's not enough, then what version of Velocity Engine are you
> using and what are you trying to do that needs RuntimeInstance
> directly?
>
> On Tue, Jan 5, 2010 at 5:00 PM, George, Nixon <Ge...@sutterhealth.org> wrote:
>> I am using the 1.4 version of the tool.
>>
>> I am trying to access the RuntimeInstance from a subclass of VelocityViewServlet.
>>
>> -----Original Message-----
>> From: Nathan Bubna [mailto:nbubna@gmail.com]
>> Sent: Tuesday, January 05, 2010 1:16 PM
>> To: Velocity Users List
>> Subject: Re: Get hold of RuntimeInstance
>>
>> Yeah, the VelocityViewServlet uses a VelocityEngine instance, not the singleton.
>>
>> What version of VelocityTools are you using?  And, in what class are
>> you trying to do this retrieval?  A subclass of VelocityViewServlet?
>> A tool class?  A template?  An "action" class in a framework?  Your
>> answers to these questions can greatly change the answer.
>>
>> On Tue, Jan 5, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
>>> Some comments in addition to my question:
>>>
>>> Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.
>>>
>>> -----Original Message-----
>>> From: George, Nixon [mailto:GeorgeN@sutterhealth.org]
>>> Sent: Monday, January 04, 2010 5:26 PM
>>> To: 'user@velocity.apache.org'
>>> Subject: Get hold of RuntimeInstance
>>>
>>> I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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: Get hold of RuntimeInstance

Posted by "George, Nixon" <Ge...@sutterhealth.org>.
This is VelocityEngine 1.6.2. I am using a custom cache implementation that also has a custom way of loading the template. The RuntimeInstance is then attached to the template which I now realize is the wrong runtimeinstance and instead should be the VelocityViewServlet's runtiminstance. Here is the code:

<code>---------------------
public static Template convertStringToTemplate(String input) throws ParseException, Exception {
	Template template = new Template();
	RuntimeServices runtimeServices = 					RuntimeSingleton.getRuntimeServices();            
      StringReader reader = new StringReader(input);
      SimpleNode node = runtimeServices.parse(reader, "UnusedTemplateName");
      template.setRuntimeServices(runtimeServices);
      template.setData(node);
      template.initDocument();
      return template;
}
------------------</code>

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Tuesday, January 05, 2010 7:49 PM
To: Velocity Users List
Subject: Re: Get hold of RuntimeInstance

subclasses have access to the getVelocityEngine() method.  though, it
returns the VelocityEngine wrapper instance, not the RuntimeInstance.
If that's not enough, then what version of Velocity Engine are you
using and what are you trying to do that needs RuntimeInstance
directly?

On Tue, Jan 5, 2010 at 5:00 PM, George, Nixon <Ge...@sutterhealth.org> wrote:
> I am using the 1.4 version of the tool.
>
> I am trying to access the RuntimeInstance from a subclass of VelocityViewServlet.
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: Tuesday, January 05, 2010 1:16 PM
> To: Velocity Users List
> Subject: Re: Get hold of RuntimeInstance
>
> Yeah, the VelocityViewServlet uses a VelocityEngine instance, not the singleton.
>
> What version of VelocityTools are you using?  And, in what class are
> you trying to do this retrieval?  A subclass of VelocityViewServlet?
> A tool class?  A template?  An "action" class in a framework?  Your
> answers to these questions can greatly change the answer.
>
> On Tue, Jan 5, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
>> Some comments in addition to my question:
>>
>> Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.
>>
>> -----Original Message-----
>> From: George, Nixon [mailto:GeorgeN@sutterhealth.org]
>> Sent: Monday, January 04, 2010 5:26 PM
>> To: 'user@velocity.apache.org'
>> Subject: Get hold of RuntimeInstance
>>
>> I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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


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


Re: Get hold of RuntimeInstance

Posted by Nathan Bubna <nb...@gmail.com>.
subclasses have access to the getVelocityEngine() method.  though, it
returns the VelocityEngine wrapper instance, not the RuntimeInstance.
If that's not enough, then what version of Velocity Engine are you
using and what are you trying to do that needs RuntimeInstance
directly?

On Tue, Jan 5, 2010 at 5:00 PM, George, Nixon <Ge...@sutterhealth.org> wrote:
> I am using the 1.4 version of the tool.
>
> I am trying to access the RuntimeInstance from a subclass of VelocityViewServlet.
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: Tuesday, January 05, 2010 1:16 PM
> To: Velocity Users List
> Subject: Re: Get hold of RuntimeInstance
>
> Yeah, the VelocityViewServlet uses a VelocityEngine instance, not the singleton.
>
> What version of VelocityTools are you using?  And, in what class are
> you trying to do this retrieval?  A subclass of VelocityViewServlet?
> A tool class?  A template?  An "action" class in a framework?  Your
> answers to these questions can greatly change the answer.
>
> On Tue, Jan 5, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
>> Some comments in addition to my question:
>>
>> Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.
>>
>> -----Original Message-----
>> From: George, Nixon [mailto:GeorgeN@sutterhealth.org]
>> Sent: Monday, January 04, 2010 5:26 PM
>> To: 'user@velocity.apache.org'
>> Subject: Get hold of RuntimeInstance
>>
>> I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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: Get hold of RuntimeInstance

Posted by "George, Nixon" <Ge...@sutterhealth.org>.
I am using the 1.4 version of the tool. 

I am trying to access the RuntimeInstance from a subclass of VelocityViewServlet.

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Tuesday, January 05, 2010 1:16 PM
To: Velocity Users List
Subject: Re: Get hold of RuntimeInstance

Yeah, the VelocityViewServlet uses a VelocityEngine instance, not the singleton.

What version of VelocityTools are you using?  And, in what class are
you trying to do this retrieval?  A subclass of VelocityViewServlet?
A tool class?  A template?  An "action" class in a framework?  Your
answers to these questions can greatly change the answer.

On Tue, Jan 5, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
> Some comments in addition to my question:
>
> Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.
>
> -----Original Message-----
> From: George, Nixon [mailto:GeorgeN@sutterhealth.org]
> Sent: Monday, January 04, 2010 5:26 PM
> To: 'user@velocity.apache.org'
> Subject: Get hold of RuntimeInstance
>
> I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks
>
>
> ---------------------------------------------------------------------
> 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


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


Re: Get hold of RuntimeInstance

Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, the VelocityViewServlet uses a VelocityEngine instance, not the singleton.

What version of VelocityTools are you using?  And, in what class are
you trying to do this retrieval?  A subclass of VelocityViewServlet?
A tool class?  A template?  An "action" class in a framework?  Your
answers to these questions can greatly change the answer.

On Tue, Jan 5, 2010 at 9:42 AM, George, Nixon <Ge...@sutterhealth.org> wrote:
> Some comments in addition to my question:
>
> Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.
>
> -----Original Message-----
> From: George, Nixon [mailto:GeorgeN@sutterhealth.org]
> Sent: Monday, January 04, 2010 5:26 PM
> To: 'user@velocity.apache.org'
> Subject: Get hold of RuntimeInstance
>
> I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks
>
>
> ---------------------------------------------------------------------
> 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: Get hold of RuntimeInstance

Posted by "George, Nixon" <Ge...@sutterhealth.org>.
Some comments in addition to my question: 

Strangely enough the command RuntimeSingleton.getRuntimeServices() gives me a different RuntimeInstance than that held by the VelocityViewServlet.

-----Original Message-----
From: George, Nixon [mailto:GeorgeN@sutterhealth.org] 
Sent: Monday, January 04, 2010 5:26 PM
To: 'user@velocity.apache.org'
Subject: Get hold of RuntimeInstance

I am using VelocityViewServlet and need to get hold of its RuntimeInstance object. How do I get to it? Thanks


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