You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Alessandro Novarini <a....@sourcesense.com> on 2009/01/05 15:45:52 UTC

How to load a macro from file (again!!!)

Hi everybody,

I am new to this list, and I need your help.
I've already looked for some tips but I'm still a bit puzzled about this
issue: how to load a velocity macro file.
I know this topic has been discussed for a long time and I think I've search
back and forth enough, there's just a small step to do that's still missing.

This is the environment: Developing a plugin for Jira in Tomcat.
This is out piece of code Java Side:
-------
        Properties customVelocityFile = new Properties();
        InputStream resourceAsStream =
this.getClass().getClassLoader().getResourceAsStream("apt-velocity.properties");
        customVelocityFile.load(resourceAsStream);
        Velocity.init(customVelocityFile);
-------

So that I can load my vmfile from classpath. This is actually working, as I
can see from velocity.log file:
-------
2009-01-05 15:25:37,955 - Velocimacro : initialization starting.
2009-01-05 15:25:37,955 - Velocimacro : adding VMs from VM library template
: templates/action/apt/macros.vm
2009-01-05 15:25:37,956 - Velocimacro : added new VM : #descriptionDivItem(
issue ) : source = templates/action/apt/macros.vm
2009-01-05 15:25:37,956 - ResourceManager : found
templates/action/apt/macros.vm with loader
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2009-01-05 15:25:37,956 - Velocimacro :  VM library template macro
registration complete.
2009-01-05 15:25:37,956 - Velocimacro : allowInline = true : VMs can be
defined inline in templates
2009-01-05 15:25:37,956 - Velocimacro : allowInlineToOverride = true : VMs
defined inline may replace previous VM definitions
2009-01-05 15:25:37,956 - Velocimacro : allowInlineLocal = true : VMs
defined inline will be local to their defining template only.
2009-01-05 15:25:37,956 - Velocimacro : messages on  : VM system will output
logging messages
2009-01-05 15:25:37,956 - Velocimacro : autoload on  : VM system will
automatically reload global library macros
2009-01-05 15:25:37,956 - Velocimacro : initialization complete.
2009-01-05 15:25:37,956 - Velocity successfully started.
-------

In the lines above you can read that the file loaded is
templates/action/apt/macros.vm and it contains the macro
#descriptionDivItem( issue )

After that I tried to call this macro from a velocity template, but the
macro wasn't parsed. Notice that I didn't use the #parse directive, maybe
should I use it?
I think I'm near to the final solution, but at the moment I'm clueless.

I hope I have been clear enough, and that you can give me some advice.

Thank you in advance.

Happy new year
Ale

Re: How to load a macro from file (again!!!)

Posted by Nathan Bubna <nb...@gmail.com>.
I would just make a new engine when adding to the global velocimacro
library.  There is a merge method that allows you to specify macro
libraries at merge time, but they don't stay in memory.  You can set
your properties so that inline macros are always registered as global,
but that has obvious side effects.  I'd recommend just init'ing a new
engine for such a change.  Yes, you will lose already cached
templates, but hopefully this isn't something you do often.

On Mon, Jan 19, 2009 at 3:23 AM, Alessandro Novarini
<a....@sourcesense.com> wrote:
> Hello everybody, it's me again
>
> After a lot of research I've found what I was looking for, but now there's
> another problem...
>
> I can get an already inited VelocityEngine, now I have to add at runtime
> another velocimacro file; how can I do that? Is it possible?
>
> Thank you in advance,
> Ale
>
> On Jan 7, 2009, at 11:33 AM, Alessandro Novarini wrote:
>
>> Ok, I'll check also some JIRA ml, but I am quite sure you're right, there
>> is another VelocityEngine (not singleton) that's doing the dirty job :|
>>
>> I think I need to get it someway, so I'm thinking to change my code
>>
>> Velocity.init(customVelocityFile);
>> Velocity.getProperty(velocimacroLibrary);
>>
>> into
>>
>> VelocityEngine ve =
>> someClass.getCurrentVelocityEngineOrWhateverThisMethodHasBeenNamed();
>> ve..getProperty(velocimacroLibrary);
>>
>>
>> Any suggestion?
>>
>> Thanks again, you've been very helpful
>> Ale
>>
>>
>>
>> On Jan 6, 2009, at 5:12 PM, Nathan Bubna wrote:
>>
>>> On Tue, Jan 6, 2009 at 1:04 AM, Alessandro Novarini
>>> <a....@sourcesense.com> wrote:
>>>>
>>>> Hello Nathan,
>>>>
>>>> On Mon, Jan 5, 2009 at 11:19 PM, Nathan Bubna <nb...@gmail.com> wrote:
>>>>
>>>>> Your properties look fine and the logs confirm that.
>>>>
>>>>
>>>> Glad to read it, it means I'm not totally wrong
>>>>
>>>>
>>>>> I can only guess
>>>>> that whatever VelocityEngine or Velocity singleton that is processing
>>>>> your template is not the same one that you are initializing.  What
>>>>> code/servlet/whatever are you using to process templates?
>>>>
>>>>
>>>> This is a good point; unfortunately I don't know the answer :(
>>>> I'm using the singleton in my Action class, as I said, this is a jira
>>>> plugin, a sort of thing I'm not used to yet and worst of all something
>>>> out
>>>> of my control...
>>>> Can you give me an adivice where to search for what you asked? Should
>>>> there
>>>> be a configuration file somewhere?
>>>
>>> I don't know anything about JIRA, so i'm totally guessing here:  you
>>> could check the web.xml and see if there is a VelocityViewServlet in
>>> sight.  You can also keep an eye out for any other velocity.properties
>>> files, of course, then try editing that.
>>>
>>> if JIRA has a user list, they might have an answer to my question.
>>>
>>>> Thank you for your advices, I'll do further investigation
>>>>
>>>> Ale
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: How to load a macro from file (again!!!)

Posted by Alessandro Novarini <a....@sourcesense.com>.
Hello everybody, it's me again

After a lot of research I've found what I was looking for, but now  
there's another problem...

I can get an already inited VelocityEngine, now I have to add at  
runtime another velocimacro file; how can I do that? Is it possible?

Thank you in advance,
Ale

On Jan 7, 2009, at 11:33 AM, Alessandro Novarini wrote:

> Ok, I'll check also some JIRA ml, but I am quite sure you're right,  
> there is another VelocityEngine (not singleton) that's doing the  
> dirty job :|
>
> I think I need to get it someway, so I'm thinking to change my code
>
> Velocity.init(customVelocityFile);
> Velocity.getProperty(velocimacroLibrary);
>
> into
>
> VelocityEngine ve =  
> someClass.getCurrentVelocityEngineOrWhateverThisMethodHasBeenNamed();
> ve..getProperty(velocimacroLibrary);
>
>
> Any suggestion?
>
> Thanks again, you've been very helpful
> Ale
>
>
>
> On Jan 6, 2009, at 5:12 PM, Nathan Bubna wrote:
>
>> On Tue, Jan 6, 2009 at 1:04 AM, Alessandro Novarini
>> <a....@sourcesense.com> wrote:
>>> Hello Nathan,
>>>
>>> On Mon, Jan 5, 2009 at 11:19 PM, Nathan Bubna <nb...@gmail.com>  
>>> wrote:
>>>
>>>> Your properties look fine and the logs confirm that.
>>>
>>>
>>> Glad to read it, it means I'm not totally wrong
>>>
>>>
>>>> I can only guess
>>>> that whatever VelocityEngine or Velocity singleton that is  
>>>> processing
>>>> your template is not the same one that you are initializing.  What
>>>> code/servlet/whatever are you using to process templates?
>>>
>>>
>>> This is a good point; unfortunately I don't know the answer :(
>>> I'm using the singleton in my Action class, as I said, this is a  
>>> jira
>>> plugin, a sort of thing I'm not used to yet and worst of all  
>>> something out
>>> of my control...
>>> Can you give me an adivice where to search for what you asked?  
>>> Should there
>>> be a configuration file somewhere?
>>
>> I don't know anything about JIRA, so i'm totally guessing here:  you
>> could check the web.xml and see if there is a VelocityViewServlet in
>> sight.  You can also keep an eye out for any other  
>> velocity.properties
>> files, of course, then try editing that.
>>
>> if JIRA has a user list, they might have an answer to my question.
>>
>>> Thank you for your advices, I'll do further investigation
>>>
>>> Ale
>>>
>>
>> ---------------------------------------------------------------------
>> 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: How to load a macro from file (again!!!)

Posted by Alessandro Novarini <al...@gmail.com>.
Ok, I'll check also some JIRA ml, but I am quite sure you're right,  
there is another VelocityEngine (not singleton) that's doing the dirty  
job :|

I think I need to get it someway, so I'm thinking to change my code

Velocity.init(customVelocityFile);
Velocity.getProperty(velocimacroLibrary);

into

VelocityEngine ve =  
someClass.getCurrentVelocityEngineOrWhateverThisMethodHasBeenNamed();
ve..getProperty(velocimacroLibrary);


Any suggestion?

Thanks again, you've been very helpful
Ale



On Jan 6, 2009, at 5:12 PM, Nathan Bubna wrote:

> On Tue, Jan 6, 2009 at 1:04 AM, Alessandro Novarini
> <a....@sourcesense.com> wrote:
>> Hello Nathan,
>>
>> On Mon, Jan 5, 2009 at 11:19 PM, Nathan Bubna <nb...@gmail.com>  
>> wrote:
>>
>>> Your properties look fine and the logs confirm that.
>>
>>
>> Glad to read it, it means I'm not totally wrong
>>
>>
>>> I can only guess
>>> that whatever VelocityEngine or Velocity singleton that is  
>>> processing
>>> your template is not the same one that you are initializing.  What
>>> code/servlet/whatever are you using to process templates?
>>
>>
>> This is a good point; unfortunately I don't know the answer :(
>> I'm using the singleton in my Action class, as I said, this is a jira
>> plugin, a sort of thing I'm not used to yet and worst of all  
>> something out
>> of my control...
>> Can you give me an adivice where to search for what you asked?  
>> Should there
>> be a configuration file somewhere?
>
> I don't know anything about JIRA, so i'm totally guessing here:  you
> could check the web.xml and see if there is a VelocityViewServlet in
> sight.  You can also keep an eye out for any other velocity.properties
> files, of course, then try editing that.
>
> if JIRA has a user list, they might have an answer to my question.
>
>> Thank you for your advices, I'll do further investigation
>>
>> Ale
>>
>
> ---------------------------------------------------------------------
> 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: How to load a macro from file (again!!!)

Posted by Nathan Bubna <nb...@gmail.com>.
On Tue, Jan 6, 2009 at 1:04 AM, Alessandro Novarini
<a....@sourcesense.com> wrote:
> Hello Nathan,
>
> On Mon, Jan 5, 2009 at 11:19 PM, Nathan Bubna <nb...@gmail.com> wrote:
>
>> Your properties look fine and the logs confirm that.
>
>
> Glad to read it, it means I'm not totally wrong
>
>
>>  I can only guess
>> that whatever VelocityEngine or Velocity singleton that is processing
>> your template is not the same one that you are initializing.  What
>> code/servlet/whatever are you using to process templates?
>
>
> This is a good point; unfortunately I don't know the answer :(
> I'm using the singleton in my Action class, as I said, this is a jira
> plugin, a sort of thing I'm not used to yet and worst of all something out
> of my control...
> Can you give me an adivice where to search for what you asked? Should there
> be a configuration file somewhere?

I don't know anything about JIRA, so i'm totally guessing here:  you
could check the web.xml and see if there is a VelocityViewServlet in
sight.  You can also keep an eye out for any other velocity.properties
files, of course, then try editing that.

if JIRA has a user list, they might have an answer to my question.

> Thank you for your advices, I'll do further investigation
>
> Ale
>

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


Re: How to load a macro from file (again!!!)

Posted by Alessandro Novarini <a....@sourcesense.com>.
Hello Nathan,

On Mon, Jan 5, 2009 at 11:19 PM, Nathan Bubna <nb...@gmail.com> wrote:

> Your properties look fine and the logs confirm that.


Glad to read it, it means I'm not totally wrong


>  I can only guess
> that whatever VelocityEngine or Velocity singleton that is processing
> your template is not the same one that you are initializing.  What
> code/servlet/whatever are you using to process templates?


This is a good point; unfortunately I don't know the answer :(
I'm using the singleton in my Action class, as I said, this is a jira
plugin, a sort of thing I'm not used to yet and worst of all something out
of my control...
Can you give me an adivice where to search for what you asked? Should there
be a configuration file somewhere?

Thank you for your advices, I'll do further investigation

Ale

Re: How to load a macro from file (again!!!)

Posted by Alessandro Novarini <a....@sourcesense.com>.
I thouht so, but the library is included in the jira webapp, I am stuck to
this version :(
Anyway this is a good news, I'll keep it in mind ;)

Thanks
Ale

On Tue, Jan 6, 2009 at 1:15 AM, Jude Robinson
<do...@gmail.com>
> wrote:

> > Oh, and if you were using Velocity 1.6.1, then you could use #parse to
> > load your macros.
>
> <finally stops lurking/> Hello.
>
> Using #parse to load macros - that sounds interesting - can you give
> an example, and explain when/why that may be useful?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: How to load a macro from file (again!!!)

Posted by Jude Robinson <do...@gmail.com>.
> #parse( 'foo.vm' )
> #else
> #parse( 'bar.vm' )
> #end

Ah ... I see :)

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


Re: How to load a macro from file (again!!!)

Posted by Nathan Bubna <nb...@gmail.com>.
On Mon, Jan 5, 2009 at 4:15 PM, Jude Robinson
<do...@gmail.com> wrote:
>> Oh, and if you were using Velocity 1.6.1, then you could use #parse to
>> load your macros.
>
> <finally stops lurking/> Hello.
>
> Using #parse to load macros - that sounds interesting - can you give
> an example, and explain when/why that may be useful?


i don't think it's often useful; most of the time there's another,
better way.  but there are those who have needed it.  not having been
one myself, i don't have a great example.  but here's a made up one:

---foo.vm----
#macro(  link $page )http://foo.com/$page#end
#macro(  blah $x )Do y with $x here#end
...

---bar.vm----
#macro( link $page )http://bar.com/$page#end
#macro( blah $x )Do z with $x here#end
...

---template.vm----
#if( $user.foo )
#parse( 'foo.vm' )
#else
#parse( 'bar.vm' )
#end
Hello $user.name,
<a href="#link( 'home.html' )">#blah( 'your account' )</a>.
sincerely,
george of the jungle

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


Re: How to load a macro from file (again!!!)

Posted by Jude Robinson <do...@gmail.com>.
> Oh, and if you were using Velocity 1.6.1, then you could use #parse to
> load your macros.

<finally stops lurking/> Hello.

Using #parse to load macros - that sounds interesting - can you give
an example, and explain when/why that may be useful?

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


Re: How to load a macro from file (again!!!)

Posted by Nathan Bubna <nb...@gmail.com>.
Oh, and if you were using Velocity 1.6.1, then you could use #parse to
load your macros.  But that will not work with earlier versions.

On Mon, Jan 5, 2009 at 2:19 PM, Nathan Bubna <nb...@gmail.com> wrote:
> Your properties look fine and the logs confirm that.  I can only guess
> that whatever VelocityEngine or Velocity singleton that is processing
> your template is not the same one that you are initializing.  What
> code/servlet/whatever are you using to process templates?  Your
> example code shows that you are using the Velocity singleton.  Are you
> using that to load and merge your templates?
>
> On Mon, Jan 5, 2009 at 2:09 PM, Alessandro Novarini
> <a....@sourcesense.com> wrote:
>> Just a couple of infos to add...
>> Velocity version is 1.4
>> My velocity.properties (apt-velocity.properties as stated in my previous
>> mail) looks like this one:
>>
>> resource.loader=class
>>
>> class.resource.loader.description=Velocity Classpath Resource Loader
>>
>> class.resource.loader.class=
>> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
>>
>>
>> velocimacro.permissions.allow.inline = true
>>
>> velocimacro.library.autoreload = true
>>
>> velocimacro.permissions.allow.inline.to.replace.global = true
>>
>> velocimacro.permissions.allow.inline.local.scope = true
>>
>> velocimacro.library=templates/action/apt/macros.vm
>>
>>
>> runtime.log.error.stacktrace = true
>>
>> runtime.log.warn.stacktrace = true
>>
>> runtime.log.info.stacktrace = true
>>
>> runtime.log.debug.stacktrace = true
>>
>> runtime.log.invalid.reference = true
>>
>>
>>
>> Again, Thank You
>> Ale
>>
>> On Mon, Jan 5, 2009 at 3:45 PM, Alessandro Novarini <
>> a.novarini@sourcesense.com> wrote:
>>
>>> Hi everybody,
>>>
>>> I am new to this list, and I need your help.
>>> I've already looked for some tips but I'm still a bit puzzled about this
>>> issue: how to load a velocity macro file.
>>> I know this topic has been discussed for a long time and I think I've
>>> search back and forth enough, there's just a small step to do that's still
>>> missing.
>>>
>>> This is the environment: Developing a plugin for Jira in Tomcat.
>>> This is out piece of code Java Side:
>>> -------
>>>         Properties customVelocityFile = new Properties();
>>>         InputStream resourceAsStream =
>>> this.getClass().getClassLoader().getResourceAsStream("apt-velocity.properties");
>>>         customVelocityFile.load(resourceAsStream);
>>>         Velocity.init(customVelocityFile);
>>> -------
>>>
>>> So that I can load my vmfile from classpath. This is actually working, as I
>>> can see from velocity.log file:
>>> -------
>>> 2009-01-05 15:25:37,955 - Velocimacro : initialization starting.
>>> 2009-01-05 15:25:37,955 - Velocimacro : adding VMs from VM library template
>>> : templates/action/apt/macros.vm
>>> 2009-01-05 15:25:37,956 - Velocimacro : added new VM : #descriptionDivItem(
>>> issue ) : source = templates/action/apt/macros.vm
>>> 2009-01-05 15:25:37,956 - ResourceManager : found
>>> templates/action/apt/macros.vm with loader
>>> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
>>> 2009-01-05 15:25:37,956 - Velocimacro :  VM library template macro
>>> registration complete.
>>> 2009-01-05 15:25:37,956 - Velocimacro : allowInline = true : VMs can be
>>> defined inline in templates
>>> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineToOverride = true : VMs
>>> defined inline may replace previous VM definitions
>>> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineLocal = true : VMs
>>> defined inline will be local to their defining template only.
>>> 2009-01-05 15:25:37,956 - Velocimacro : messages on  : VM system will
>>> output logging messages
>>> 2009-01-05 15:25:37,956 - Velocimacro : autoload on  : VM system will
>>> automatically reload global library macros
>>> 2009-01-05 15:25:37,956 - Velocimacro : initialization complete.
>>> 2009-01-05 15:25:37,956 - Velocity successfully started.
>>> -------
>>>
>>> In the lines above you can read that the file loaded is
>>> templates/action/apt/macros.vm and it contains the macro
>>> #descriptionDivItem( issue )
>>>
>>> After that I tried to call this macro from a velocity template, but the
>>> macro wasn't parsed. Notice that I didn't use the #parse directive, maybe
>>> should I use it?
>>> I think I'm near to the final solution, but at the moment I'm clueless.
>>>
>>> I hope I have been clear enough, and that you can give me some advice.
>>>
>>> Thank you in advance.
>>>
>>> Happy new year
>>> Ale
>>>
>>
>

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


Re: How to load a macro from file (again!!!)

Posted by Nathan Bubna <nb...@gmail.com>.
Your properties look fine and the logs confirm that.  I can only guess
that whatever VelocityEngine or Velocity singleton that is processing
your template is not the same one that you are initializing.  What
code/servlet/whatever are you using to process templates?  Your
example code shows that you are using the Velocity singleton.  Are you
using that to load and merge your templates?

On Mon, Jan 5, 2009 at 2:09 PM, Alessandro Novarini
<a....@sourcesense.com> wrote:
> Just a couple of infos to add...
> Velocity version is 1.4
> My velocity.properties (apt-velocity.properties as stated in my previous
> mail) looks like this one:
>
> resource.loader=class
>
> class.resource.loader.description=Velocity Classpath Resource Loader
>
> class.resource.loader.class=
> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
>
>
> velocimacro.permissions.allow.inline = true
>
> velocimacro.library.autoreload = true
>
> velocimacro.permissions.allow.inline.to.replace.global = true
>
> velocimacro.permissions.allow.inline.local.scope = true
>
> velocimacro.library=templates/action/apt/macros.vm
>
>
> runtime.log.error.stacktrace = true
>
> runtime.log.warn.stacktrace = true
>
> runtime.log.info.stacktrace = true
>
> runtime.log.debug.stacktrace = true
>
> runtime.log.invalid.reference = true
>
>
>
> Again, Thank You
> Ale
>
> On Mon, Jan 5, 2009 at 3:45 PM, Alessandro Novarini <
> a.novarini@sourcesense.com> wrote:
>
>> Hi everybody,
>>
>> I am new to this list, and I need your help.
>> I've already looked for some tips but I'm still a bit puzzled about this
>> issue: how to load a velocity macro file.
>> I know this topic has been discussed for a long time and I think I've
>> search back and forth enough, there's just a small step to do that's still
>> missing.
>>
>> This is the environment: Developing a plugin for Jira in Tomcat.
>> This is out piece of code Java Side:
>> -------
>>         Properties customVelocityFile = new Properties();
>>         InputStream resourceAsStream =
>> this.getClass().getClassLoader().getResourceAsStream("apt-velocity.properties");
>>         customVelocityFile.load(resourceAsStream);
>>         Velocity.init(customVelocityFile);
>> -------
>>
>> So that I can load my vmfile from classpath. This is actually working, as I
>> can see from velocity.log file:
>> -------
>> 2009-01-05 15:25:37,955 - Velocimacro : initialization starting.
>> 2009-01-05 15:25:37,955 - Velocimacro : adding VMs from VM library template
>> : templates/action/apt/macros.vm
>> 2009-01-05 15:25:37,956 - Velocimacro : added new VM : #descriptionDivItem(
>> issue ) : source = templates/action/apt/macros.vm
>> 2009-01-05 15:25:37,956 - ResourceManager : found
>> templates/action/apt/macros.vm with loader
>> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
>> 2009-01-05 15:25:37,956 - Velocimacro :  VM library template macro
>> registration complete.
>> 2009-01-05 15:25:37,956 - Velocimacro : allowInline = true : VMs can be
>> defined inline in templates
>> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineToOverride = true : VMs
>> defined inline may replace previous VM definitions
>> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineLocal = true : VMs
>> defined inline will be local to their defining template only.
>> 2009-01-05 15:25:37,956 - Velocimacro : messages on  : VM system will
>> output logging messages
>> 2009-01-05 15:25:37,956 - Velocimacro : autoload on  : VM system will
>> automatically reload global library macros
>> 2009-01-05 15:25:37,956 - Velocimacro : initialization complete.
>> 2009-01-05 15:25:37,956 - Velocity successfully started.
>> -------
>>
>> In the lines above you can read that the file loaded is
>> templates/action/apt/macros.vm and it contains the macro
>> #descriptionDivItem( issue )
>>
>> After that I tried to call this macro from a velocity template, but the
>> macro wasn't parsed. Notice that I didn't use the #parse directive, maybe
>> should I use it?
>> I think I'm near to the final solution, but at the moment I'm clueless.
>>
>> I hope I have been clear enough, and that you can give me some advice.
>>
>> Thank you in advance.
>>
>> Happy new year
>> Ale
>>
>

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


Re: How to load a macro from file (again!!!)

Posted by Alessandro Novarini <a....@sourcesense.com>.
Just a couple of infos to add...
Velocity version is 1.4
My velocity.properties (apt-velocity.properties as stated in my previous
mail) looks like this one:

resource.loader=class

class.resource.loader.description=Velocity Classpath Resource Loader

class.resource.loader.class=
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader


velocimacro.permissions.allow.inline = true

velocimacro.library.autoreload = true

velocimacro.permissions.allow.inline.to.replace.global = true

velocimacro.permissions.allow.inline.local.scope = true

velocimacro.library=templates/action/apt/macros.vm


runtime.log.error.stacktrace = true

runtime.log.warn.stacktrace = true

runtime.log.info.stacktrace = true

runtime.log.debug.stacktrace = true

runtime.log.invalid.reference = true



Again, Thank You
Ale

On Mon, Jan 5, 2009 at 3:45 PM, Alessandro Novarini <
a.novarini@sourcesense.com> wrote:

> Hi everybody,
>
> I am new to this list, and I need your help.
> I've already looked for some tips but I'm still a bit puzzled about this
> issue: how to load a velocity macro file.
> I know this topic has been discussed for a long time and I think I've
> search back and forth enough, there's just a small step to do that's still
> missing.
>
> This is the environment: Developing a plugin for Jira in Tomcat.
> This is out piece of code Java Side:
> -------
>         Properties customVelocityFile = new Properties();
>         InputStream resourceAsStream =
> this.getClass().getClassLoader().getResourceAsStream("apt-velocity.properties");
>         customVelocityFile.load(resourceAsStream);
>         Velocity.init(customVelocityFile);
> -------
>
> So that I can load my vmfile from classpath. This is actually working, as I
> can see from velocity.log file:
> -------
> 2009-01-05 15:25:37,955 - Velocimacro : initialization starting.
> 2009-01-05 15:25:37,955 - Velocimacro : adding VMs from VM library template
> : templates/action/apt/macros.vm
> 2009-01-05 15:25:37,956 - Velocimacro : added new VM : #descriptionDivItem(
> issue ) : source = templates/action/apt/macros.vm
> 2009-01-05 15:25:37,956 - ResourceManager : found
> templates/action/apt/macros.vm with loader
> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> 2009-01-05 15:25:37,956 - Velocimacro :  VM library template macro
> registration complete.
> 2009-01-05 15:25:37,956 - Velocimacro : allowInline = true : VMs can be
> defined inline in templates
> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineToOverride = true : VMs
> defined inline may replace previous VM definitions
> 2009-01-05 15:25:37,956 - Velocimacro : allowInlineLocal = true : VMs
> defined inline will be local to their defining template only.
> 2009-01-05 15:25:37,956 - Velocimacro : messages on  : VM system will
> output logging messages
> 2009-01-05 15:25:37,956 - Velocimacro : autoload on  : VM system will
> automatically reload global library macros
> 2009-01-05 15:25:37,956 - Velocimacro : initialization complete.
> 2009-01-05 15:25:37,956 - Velocity successfully started.
> -------
>
> In the lines above you can read that the file loaded is
> templates/action/apt/macros.vm and it contains the macro
> #descriptionDivItem( issue )
>
> After that I tried to call this macro from a velocity template, but the
> macro wasn't parsed. Notice that I didn't use the #parse directive, maybe
> should I use it?
> I think I'm near to the final solution, but at the moment I'm clueless.
>
> I hope I have been clear enough, and that you can give me some advice.
>
> Thank you in advance.
>
> Happy new year
> Ale
>