velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Smith, Mike H" <Mike.H.Sm...@pfizer.com>
Subject RE: Extracting a list of keys from a string based template
Date Fri, 21 Jul 2006 12:36:19 GMT
Hi,

We're not planning on using conditionals, and certainly not in that
manner.

The wrapper approach is working well for my simple templates.

Thanks.
Mike

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: 21 July 2006 01:50
To: Velocity Users List
Subject: Re: Extracting a list of keys from a string based template

True.  I'd not thought of that.

Still, if you're not using a resource loader and can get away with no
conditionals, it's probably useful. :)

On 7/20/06, Marc Novakowski <marc@pandora.com> wrote:
> Thanks!  The only situation where this might not work is if you
> access a key within an #if block that evaluates to false, i.e.
>
> #if ($foo)
>         $bar
> #end
>
> If there is no "foo" in your context when you do the evaluate, I'm
> guessing that it doesn't go ahead and get "bar" from the context.

Correct.

> Marc
>
>
> On 20-Jul-06, at 2:35 PM, Nathan Bubna wrote:
>
> > Hey, i think that's a good idea!  That would work without need to
have
> > a Template object and AST for the TemplateTool to analyze. (In other
> > words, it could work with VelocityEngine.evaluate() and no need to
> > mess with resource loaders for those who don't need/care about
them).
> > I really can't imagine why this wouldn't work.
> >
> > If you/anyone tries this, i'd love to hear how it works out for
them.
> > Perhaps they could even contribute the context wrapper they come up
> > with? ;-)
> >
> > On 7/20/06, Marc Novakowski <marc@pandora.com> wrote:
> >> Here's an idea - to get the keys from the template, you could use
the
> >> decorator pattern to create a wrapper around the context object.
> >> Have the "get()" and "containsKey()" methods in your wrapper keep
> >> track of the keys that are being looked up by velocity during the
> >> evaluate.
> >>
> >> I haven't tried it, but I think it might work...
> >>
> >> Marc
> >>
> >>
> >> On 20-Jul-06, at 4:01 AM, Smith, Mike H wrote:
> >>
> >> > Hi,
> >> >
> >> >
> >> >
> >> > I'm a Velocity newbie, and am evaluating to see if it can
> >> address our
> >> > relatively simple requirements.
> >> >
> >> >
> >> >
> >> > I need to use String based templates. After a bit if digging
> >> around I
> >> > found the following function:
> >> >
> >> >
> >> >
> >> > Velocity.evaluate( context, writer, "", templateString );
> >> >
> >> >
> >> >
> >> > This works pretty well for our purposes.
> >> >
> >> >
> >> >
> >> > However I also need to get a list of candidate keys from the
> >> template
> >> > String.
> >> >
> >> >
> >> >
> >> > So if my template contains: "$a $b" I need to extract ["a","b"].
> >> >
> >> >
> >> >
> >> > Thanks.
> >> >
> >> > Mike
> >> >
> >> >
> >> >
> >>
> >>
> >>
---------------------------------------------------------------------
> >> 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
> >
>
>
> ---------------------------------------------------------------------
> 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


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


Mime
View raw message