You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Carsten Rhod Gregersen <ve...@logiva.dk> on 2001/04/29 00:38:30 UTC
Anakia and multifile generation
Hi,
First, thank you for a really nice tool.
I'm using velocity and anakia to automatically generate
some files based on a xml description.
I've run into some different problems.
I'm using the programs in a little different way than the
examples, and that might be the source to all my problems.
I'm using a single xml file in combination with several
stylesheets (velocity templates) to generate about 6-8
different "final" files (e.g. 6-8 autogenerated files pr. xml file)
that all are different but based on the same data.
This can today only be acomplished by creating 6-8 links
and using the extension to decide which style (template) to
use. Has anyone done something like this before, and how
did they do it (e.g. is there a smarter way) ??
I've read the source code of the anakia task, and it would seem
quite easy to code something for my specific purpose, but
if someone has done it before and submitted it I would rather
work on that.
Also I've found out that it seem that the macro's spans over multiple
stylesheets (velocity templates). So if I have a macro in one
template the same name can not be used in another. I'm not
saying this is an error, but quite some time was invested before
i found out that the macro's seemed to have a global definition.
mvh,
Carsten Rhod Gregersen @ Logiva A/S
Email: crg@logiva.dk, Web: http://www.logiva.dk
Tlf. 70 211 360. Direkte 70211361
Re: Why can't I pass a null to my functions?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Paulo Gaspar wrote:
>
> hehehe
> I was working with an old version and now I got the latest daily build.
I don't know if that will make a difference.
> I also do not know what I am getting. Both trough the debugger and trough
> introspection I just now it is a java.lang.Object!
> =:o\
really? Hm.
> If you are surprised, then I suppose it is not meant to behave this way
> and I am going to dig a bit more.
I can't say I would be terribly surprised either way. There is some
wierdness orbiting this subject...
geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
RE: Why can't I pass a null to my functions?
Posted by Paulo Gaspar <pa...@krankikom.de>.
hehehe
I was working with an old version and now I got the latest daily build.
I also do not know what I am getting. Both trough the debugger and trough
introspection I just now it is a java.lang.Object!
=:o\
If you are surprised, then I suppose it is not meant to behave this way
and I am going to dig a bit more.
Thanks for the (as usual) very fast answer,
Paulo
> -----Original Message-----
> From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net]On
> Behalf Of Geir Magnusson Jr.
> Sent: Monday, April 30, 2001 20:51
> To: velocity-dev@jakarta.apache.org
> Subject: Re: Why can't I pass a null to my functions?
>
>
> Paulo Gaspar wrote:
> >
> > It looks like the new Velocity replaces a null reference
> > with "something" before passing it as a parameter to a
> > method reference.
> >
> > So, if I have:
> >
> > #if($tool.hasSomething($data.field))
> >
> > and $data.field resolves to null, the hasSomething() method
> > gets something else (not the null).
> >
> > WHY?
>
> Huh? What do you mean 'new', and what does it get?
>
> geir
>
> --
> Geir Magnusson Jr. geirm@optonline.net
> System and Software Consulting
>
> Developing for the web? See http://jakarta.apache.org/velocity/
>
Re: Why can't I pass a null to my functions?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Paulo Gaspar wrote:
>
> It looks like the new Velocity replaces a null reference
> with "something" before passing it as a parameter to a
> method reference.
>
> So, if I have:
>
> #if($tool.hasSomething($data.field))
>
> and $data.field resolves to null, the hasSomething() method
> gets something else (not the null).
>
> WHY?
Huh? What do you mean 'new', and what does it get?
geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
Why can't I pass a null to my functions?
Posted by Paulo Gaspar <pa...@krankikom.de>.
It looks like the new Velocity replaces a null reference
with "something" before passing it as a parameter to a
method reference.
So, if I have:
#if($tool.hasSomething($data.field))
and $data.field resolves to null, the hasSomething() method
gets something else (not the null).
WHY?
Thanks,
Paulo Gaspar
Re: Anakia and multifile generation
Posted by Jon Stevens <jo...@latchkey.com>.
on 4/30/01 6:10 AM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> Anakia is a nice tool, but it is tailored for a specific purpose. You
> can extend it to make it do more (and contribute it back here if its
> general and you like it...) or make a new tool, drawing on Anakia as an
> example, to solve whatever problem you have.
One thing that I would like to see is the core of Anakia broken out into a
separate class than the AnakiaTask.java. This will allow people to
instantiate the model and work with it (including changing the order)
instead of having to strip the code out of the AnakiaTask.
I don't have the time/energy to do that right now but would appreciate
contributions in that area.
thanks,
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>
Re: Anakia and multifile generation
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Carsten Rhod Gregersen wrote:
>
> Hi,
>
> First, thank you for a really nice tool.
>
> I'm using velocity and anakia to automatically generate
> some files based on a xml description.
>
> I've run into some different problems.
>
> I'm using the programs in a little different way than the
> examples, and that might be the source to all my problems.
Nah. Different is good.
> I'm using a single xml file in combination with several
> stylesheets (velocity templates) to generate about 6-8
> different "final" files (e.g. 6-8 autogenerated files pr. xml file)
> that all are different but based on the same data.
>
> This can today only be acomplished by creating 6-8 links
> and using the extension to decide which style (template) to
> use. Has anyone done something like this before, and how
> did they do it (e.g. is there a smarter way) ??
>
> I've read the source code of the anakia task, and it would seem
> quite easy to code something for my specific purpose, but
> if someone has done it before and submitted it I would rather
> work on that.
I've done exactly that when my needs were different. The basic model
that Anakia uses is pretty straightforward :
1) parse your XML into a JDOM Document
SAXBuilder builder;
Document root = null;
try
{
builder = new SAXBuilder(
"org.apache.xerces.parsers.SAXParser" );
root = builder.build( file );
}
catch( Exception )
{
System.out.println( ... );
}
2) Stuff the Document (or root Element) into the context
context.put("root", root );
3) Render a template.
Anakia is a nice tool, but it is tailored for a specific purpose. You
can extend it to make it do more (and contribute it back here if its
general and you like it...) or make a new tool, drawing on Anakia as an
example, to solve whatever problem you have.
>
> Also I've found out that it seem that the macro's spans over multiple
> stylesheets (velocity templates). So if I have a macro in one
> template the same name can not be used in another. I'm not
> saying this is an error, but quite some time was invested before
> i found out that the macro's seemed to have a global definition.
Yes, that's the idea - that you can create a library of VMs
(Velocimacros) that anyone can share. Of course, there are issues with
that, like when you *don't* want that to be the case. If so, you can
turn on what is called 'local scope' :
velocimacro.permissions.allow.inline.local.scope = true
and that should keep the macro definition local to the template that
declared it. Anakia can take a properties file, so you can put it
there, or in your own code either read a properties file, or do
something like
Velocity.setProperty(
"velocimacro.permissions.allow.inline.local.scope", Boolean.TRUE );
or if you don't like the string :
Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE );
geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/