You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Kris Nuttycombe <Kr...@noaa.gov> on 2004/06/25 16:43:07 UTC

Register a dynamically generated Velocimacro?

Hello,

Is there any way to register a dynamically generated Velocimacro? I 
found the Velocity.invokeVelocimacro(...) method by looking at the 
javadocs, and it looks like precisely what I need except for the fact 
that I'm dynamically generating the vtml for the velocimacro and haven't 
been able to figure out how to register it.

Any suggestions?

Thanks,

Kris

-- 
=====================================================
Kris Nuttycombe
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6337
Kris.Nuttycombe@noaa.gov

Every problem has an elegant solution.
If you cannot conceive of an elegant solution,
you have not yet correctly understood the problem.
=====================================================



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


Re: Register a dynamically generated Velocimacro?

Posted by Christoph Reck <ap...@recks.org>.
Hi,

there is a RenderTool in the velocity tools subproject that you can
reuse to do the Velocity.evalute(...) for you.

Cheers,
Christoph

Kris Nuttycombe wrote:
> So, just to clarify, the tool I put into the context will invoke 
> Velocity.evaluate(...) on the string containing the new macro? And I'll 
> use a simple template that just looks like:
> 
> $mytool.register()
> 
> and merge that template?
> 
> Thanks for your help. It seems a little strange that there's not a 
> method to load a template directly from a string rather than from some 
> ResourceLoader. I guess that this is what Velocity.evaluate(...) is  
> there for, but it doesn't make sense to have to regenerate the parse 
> tree for the template each time since I need to merge the template as 
> many as 10,000 times with different data in the context, and I can't 
> just stick it all in a list and use #foreach because creating the list 
> causes OutOfMemoryErrors.
> 
> Kris
> 
> Geir Magnusson Jr wrote:
> 
>>
>> On Jun 25, 2004, at 10:43 AM, Kris Nuttycombe wrote:
>>
>>> Hello,
>>>
>>> Is there any way to register a dynamically generated Velocimacro? I 
>>> found the Velocity.invokeVelocimacro(...) method by looking at the 
>>> javadocs, and it looks like precisely what I need except for the fact 
>>> that I'm dynamically generating the vtml for the velocimacro and 
>>> haven't been able to figure out how to register it.
>>>
>>> Any suggestions?
>>
>>
>>
>> My canonical one - put a tool in the context that allows you to merge 
>> template on a string.  Then put the dynamically generated macro in a 
>> string and just merge it.  That will register it.
>>
>> geir
>>
> =====================================================
> Kris Nuttycombe
> Associate Scientist
> Geospatial Data Services Group
> CIRES, National Geophysical Data Center/NOAA
> (303) 497-6337
> Kris.Nuttycombe@noaa.gov
> 
> Every problem has an elegant solution.
> If you cannot conceive of an elegant solution,
> you have not yet correctly understood the problem.
> =====================================================
> 
> 
> 
> ---------------------------------------------------------------------
> 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-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Register a dynamically generated Velocimacro?

Posted by Kris Nuttycombe <Kr...@noaa.gov>.
So, just to clarify, the tool I put into the context will invoke 
Velocity.evaluate(...) on the string containing the new macro? And I'll 
use a simple template that just looks like:

$mytool.register()

and merge that template?

Thanks for your help. It seems a little strange that there's not a 
method to load a template directly from a string rather than from some 
ResourceLoader. I guess that this is what Velocity.evaluate(...) is  
there for, but it doesn't make sense to have to regenerate the parse 
tree for the template each time since I need to merge the template as 
many as 10,000 times with different data in the context, and I can't 
just stick it all in a list and use #foreach because creating the list 
causes OutOfMemoryErrors.

Kris

Geir Magnusson Jr wrote:

>
> On Jun 25, 2004, at 10:43 AM, Kris Nuttycombe wrote:
>
>> Hello,
>>
>> Is there any way to register a dynamically generated Velocimacro? I 
>> found the Velocity.invokeVelocimacro(...) method by looking at the 
>> javadocs, and it looks like precisely what I need except for the fact 
>> that I'm dynamically generating the vtml for the velocimacro and 
>> haven't been able to figure out how to register it.
>>
>> Any suggestions?
>
>
> My canonical one - put a tool in the context that allows you to merge 
> template on a string.  Then put the dynamically generated macro in a 
> string and just merge it.  That will register it.
>
> geir
>
=====================================================
Kris Nuttycombe
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6337
Kris.Nuttycombe@noaa.gov

Every problem has an elegant solution.
If you cannot conceive of an elegant solution,
you have not yet correctly understood the problem.
=====================================================



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


Re: Register a dynamically generated Velocimacro?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jun 25, 2004, at 10:43 AM, Kris Nuttycombe wrote:

> Hello,
>
> Is there any way to register a dynamically generated Velocimacro? I 
> found the Velocity.invokeVelocimacro(...) method by looking at the 
> javadocs, and it looks like precisely what I need except for the fact 
> that I'm dynamically generating the vtml for the velocimacro and 
> haven't been able to figure out how to register it.
>
> Any suggestions?

My canonical one - put a tool in the context that allows you to merge 
template on a string.  Then put the dynamically generated macro in a 
string and just merge it.  That will register it.

geir

>
> Thanks,
>
> Kris
>
> -- 
> =====================================================
> Kris Nuttycombe
> Associate Scientist
> Geospatial Data Services Group
> CIRES, National Geophysical Data Center/NOAA
> (303) 497-6337
> Kris.Nuttycombe@noaa.gov
>
> Every problem has an elegant solution.
> If you cannot conceive of an elegant solution,
> you have not yet correctly understood the problem.
> =====================================================
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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