You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/07/16 05:45:24 UTC

To Singleton, or not to Singlton, that is the question...

Once Brian finishes the CVS migration (Thanks, Brian!) to the new
server, I will put into whiteboard/geir a new jar, source tgz and
example proggie that is a successful attempt to convert Velocity to
allow multiple concurrent instances of the template engine in a given
program.

I won't commit changes to CVS until people agree this is a good way to
go.  I don't want to have to back this change out :)  It's very broad
and touches most if not all parts of Velocity.

Summary
=======

You now have the option of how you want to use the Velocity template
engine in your applications :

1) The current model of using the Velocity class to access the singlton
pattern is still valid - this jar should drop in and work anywhere the
exsting production or nightly jars work.

2) There is a new class org.apache.velocity.app.VelocityEngine that can
be used in the way you suspect

VelocityEngine ve = new VelocityEngine();

and VelocityEngine currently has the same interface as Velocity, so
everything you can do now with the singleton will work with the
instance.

Details
=======

The basic idea is that all parts of velocity depended upon Runtime for
core services in that they would call things like  Runtime.error( msg )
to log, for example.  So, the class Runtime was renamed RuntimeInstance,
a new interface RuntimeServices was created (that has most of the old
Runtime methods), and a referece to RuntimeInstance (which implements
RuntimeServices) is passed into the various subcomponents of Velocity
for use to replace using the singleton for services.  To do this, any
other singleton classes are now instance classes (ResourceManager, for
example) as well, and a few things had to be slightly modified to break
singleton assumptions.

So, the meta API of Velocity is :

VelocityEngine : new class that is a new-able class to provide separate
instances, delegates all calls to a RuntimeInstance.  With it you can :

VelocityEngine ve1 = new VelocityEngine();
VelocityEngine ve2 = new VelocityEngine();

and then configure and init() each separately, as you would hope for...

Velocity : the old Singleton application helper class. Nothing has
changed. Delegates calls to the RuntimeSingleton class.  You can and
should continue to use this for the Singleton model.

RuntimeSingleton : renamed Runtime class, this is the static class for
Singleton usage.  

Runtime : new deprecated wrapper class, delegates to RuntimeSingleton. 
I want to get rid of this if we go forward as I think that
RuntimeSingleton is a more descriptive class name.  Anyway, you
shouldn't be accessing the class directly in your applications - that's
what Velocity is for.

The nice thing is that you can continue to use the Singleton model, or
even use both models concurrently.

I converted Anakia to use an instance, but the structure of Texen
requires more work than I cared to do at the time, so it still requires
the singleton model.  This can be converted later, or left as is.  It's
up to the Texen tribe.  I will note that the failures we have been
seeing from Gump lately are due to a new classloader scheme in Ant that
Sam is trying which I believe could be solved by converting Texen to the
new instance model.

The only real change is that anything implementing LogSystem must now
add an init( RuntimeServices) method, as the logger factory made this
necessary to pass the RuntimeServices.  I don't think this will be
something that affects many people at all.  It would only affect you if
you created your own personal logger class that is instantiated.  If you
have a logger class that you pass to Velocity as a living instance (yes,
you can do that - see the logger test and examples), all is ok.  We can
discuss this - if it's too large a burden, we can try to redo, but I
think that it would be counter productive in the long run.

So, take a look at the code, and more importantly, test it out in
existing apps to make sure all is still healthy, and in new apps that
you were planning. There has been more and more interest in seeing this
solution, so lets give this a try.

Note that there is no performance penalty for this (it actually sped up
as I found some spurious initialization of the syntax tree when going
through this :)

Also, the example program is called InstanceExample, and is very very
simple. It was inspired by the needs of Turbine (or what I understand
their needs to be...) in that you setup two engines, and give each a
different template path, and then ask for the same template from each -
so you can have a default top level template index.vm for each of your
webapps, and don't really have to worry other than at setup time where
the templates are - you can make the same request into any engine...

geir



-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: Any idea why this doesn't work

Posted by Uday Kumar <ud...@eself.com>.
:) :) :)   u definitely need a break... 

-Uday


----- Original Message ----- 
From: "Dave Cramer" <Da...@micro-automation.net>
To: <ve...@jakarta.apache.org>
Sent: Thursday, July 19, 2001 7:09 PM
Subject: RE: Any idea why this doesn't work


> Thanks, now I feel stupid, time for a break
> 
> --dc--
> 
> -----Original Message-----
> From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net] On
> Behalf Of Geir Magnusson Jr.
> Sent: July 19, 2001 10:06 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: Any idea why this doesn't work
> 
> 
> #elif isn't a directive
> 
> try
> 
> #elseif
> 
> :)
> 
> geir
> 
> 
> Dave Cramer wrote:
> > 
> > The following works
> > 
> >         #if ($Store == 'Grocery')
> > 
> >           <b>$Catalog.Render()</b>
> > 
> >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > color='#000000'><b>
> >             <b>
> >                 <a 
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >                         Movie Rental
> >                 </a>
> >             </b>
> >               </font>
> >         #end
> >         #if ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> >                       <b><a 
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> >           #end
> > 
> > But this doesn't
> > 
> >         #if ($Store == 'Grocery')
> > 
> >           <b>$Catalog.Render()</b>
> > 
> >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > color='#000000'><b>
> >             <b>
> >                 <a 
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >                         Movie Rental
> >                 </a>
> >             </b>
> >               </font>
> > 
> >         #elif ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> >                       <b><a 
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> >           #end
> > 
> > The difference is the #end #if was changed to #elif. When the template
> 
> > is displayed I see #elif (xxx == 'Grocery') on the page
> > 
> > TIA,
> > 
> > Dave
> 
> -- 
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!
> 
> 
> 


RE: Any idea why this doesn't work

Posted by Dave Cramer <Da...@micro-automation.net>.
Thanks, now I feel stupid, time for a break

--dc--

-----Original Message-----
From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net] On
Behalf Of Geir Magnusson Jr.
Sent: July 19, 2001 10:06 PM
To: velocity-user@jakarta.apache.org
Subject: Re: Any idea why this doesn't work


#elif isn't a directive

try

#elseif

:)

geir


Dave Cramer wrote:
> 
> The following works
> 
>         #if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
> 
>           <font face='Arial, Helvetica, sans-serif' size='2' 
> color='#000000'><b>
>             <b>
>                 <a 
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>                         Movie Rental
>                 </a>
>             </b>
>               </font>
>         #end
>         #if ($Store == 'Rental')
>           #foreach ($store in $OpenedStores)
>                       <b><a 
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> oc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
>           #end
> 
> But this doesn't
> 
>         #if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
> 
>           <font face='Arial, Helvetica, sans-serif' size='2' 
> color='#000000'><b>
>             <b>
>                 <a 
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>                         Movie Rental
>                 </a>
>             </b>
>               </font>
> 
>         #elif ($Store == 'Rental')
>           #foreach ($store in $OpenedStores)
>                       <b><a 
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> oc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
>           #end
> 
> The difference is the #end #if was changed to #elif. When the template

> is displayed I see #elif (xxx == 'Grocery') on the page
> 
> TIA,
> 
> Dave

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!



Re: Any idea why this doesn't work

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
#elif isn't a directive

try

#elseif

:)

geir


Dave Cramer wrote:
> 
> The following works
> 
>         #if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
> 
>           <font face='Arial, Helvetica, sans-serif' size='2'
> color='#000000'><b>
>             <b>
>                 <a
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>                         Movie Rental
>                 </a>
>             </b>
>               </font>
>         #end
>         #if ($Store == 'Rental')
>           #foreach ($store in $OpenedStores)
>                       <b><a
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
>           #end
> 
> But this doesn't
> 
>         #if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
> 
>           <font face='Arial, Helvetica, sans-serif' size='2'
> color='#000000'><b>
>             <b>
>                 <a
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>                         Movie Rental
>                 </a>
>             </b>
>               </font>
> 
>         #elif ($Store == 'Rental')
>           #foreach ($store in $OpenedStores)
>                       <b><a
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
>           #end
> 
> The difference is the #end #if was changed to #elif. When the template
> is displayed I see #elif (xxx == 'Grocery') on the page
> 
> TIA,
> 
> Dave

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
> 'Schmoo' is my pet word (that I am working hard to get into the Velocity
> vernacular :) for anything in a template that isn't a valid directive or
> a reference.  Velocity must ignore the schmoo and render as is.

Here is a free P.R. advice, add it to the users manuals and make sure
it apears at least 20 times ;-)

>
> > Anyway, it would be nice to report an error in this case. I Hope this
> > is what you had in mind ;-)
>
> It's not an error :)  This is what made the Velocity parser so
> interesting - unlike any other language I can think of, it must find the
> grammatical structure embedded in a sea of stuff that it has to ignore,
> even if that stuff is 'similar'.  HTML, I guess, is sort of this way,
> except it won't render things like <foo>, where velocity will render
> #elsif as '#elsif'

Just for the record, I refered to the C preprocessor which has a similar
task
as Velocity and not the C language itself. Anyway, the argument that
declaring this as an error will flag also things like '#aabbcc' color
specification
make perfect sense to me. This may explain why the C language does not have
a '#' operator.

Thanks for a great product.

Tal

>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!
>


Re: Any idea why this doesn't work

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> > >
> > > Just curious, did you get an exception or an error message or did the
> > > execution (merging) of the template went silently about the error ?
> >
> > That would have went silently...  it was schmoo...
> 
> 
> At the risk of sounding dense, I am not sure what 'schmoo...' means.
> 

'Schmoo' is my pet word (that I am working hard to get into the Velocity
vernacular :) for anything in a template that isn't a valid directive or
a reference.  Velocity must ignore the schmoo and render as is.

> Anyway, it would be nice to report an error in this case. I Hope this
> is what you had in mind ;-)

It's not an error :)  This is what made the Velocity parser so
interesting - unlike any other language I can think of, it must find the
grammatical structure embedded in a sea of stuff that it has to ignore,
even if that stuff is 'similar'.  HTML, I guess, is sort of this way,
except it won't render things like <foo>, where velocity will render
#elsif as '#elsif'

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
> > 
> > Just curious, did you get an exception or an error message or did the
> > execution (merging) of the template went silently about the error ?
> 
> That would have went silently...  it was schmoo...

                               
At the risk of sounding dense, I am not sure what 'schmoo...' means.

Anyway, it would be nice to report an error in this case. I Hope this
is what you had in mind ;-)

Tal




Re: Any idea why this doesn't work

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> Just curious, did you get an exception or an error message or did the
> execution (merging) of the template went silently about the error ?

That would have went silently...  it was schmoo...

> 
> Tal
> 
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: Thursday, July 19, 2001 6:56 PM
> > To: velocity-user@jakarta.apache.org
> > Subject: Any idea why this doesn't work
> >
> >
> > The following works
> >
> >
> >       #if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2'
> > color='#000000'><b>
> >             <b>
> >               <a
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >                       Movie Rental
> >               </a>
> >             </b>
> >             </font>
> >         #end
> >         #if ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> >                     <b><a
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> >         #end
> >
> > But this doesn't
> >
> >       #if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2'
> > color='#000000'><b>
> >             <b>
> >               <a
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >                       Movie Rental
> >               </a>
> >             </b>
> >             </font>
> >
> >         #elif ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> >                     <b><a
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> >         #end
> >
> > The difference is the #end #if was changed to #elif. When the template
> > is displayed I see #elif (xxx == 'Grocery') on the page
> >
> > TIA,
> >
> > Dave
> >
> >

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: Any idea why this doesn't work

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> I am not sure about that. '#elif' looks like an invalid directive, so
> Velocity
> could catch it (since there is a valid escape sequence to generate
> '#elif' is needed).
> 
> I think this is the behavior of standard C/CPP preprocessors, they give an
> error if you try to use a invalid directive.

Of course, but C is a much stricter language than Velocity's VTL.  With
C, everything in an input stream must be syntactically correct.  There
is no 'freeform stuff' in a C program.  In VTL, it can be mostly
freeform stuff (or even none...).

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: #parse doesn't work with evaluate()

Posted by Dan Finkelstein <da...@emind.com>.
This new jar worked great !! We are very, very happy campers !!

Thanks Geir,

Dan

PS -- The reason that Piero can't read the 
whiteboard/geir/velocity_src_20010722.tgz file is that it wasn't added with 
the "-kb" flag -- for binary files.



At 10:40 PM 7/22/01 -0400, you wrote:
>Dan Finkelstein wrote:
> >
> > Here's an odd one.   It happens in the 1.2 dev jar, not in Velocity
> > 1.0.  #parse fails when evaluate() is used but works ok with
> > getTemplate()/merge().
>
>[SNIP]
>
>This is now fixed in both CVS HEAD as well as the proposed version in
>/whiteboard/geir.
>
>I am uploading a new source tree for the 'single instance' code as well
>as a jar, so anyone interested in the new separate instance stuff should
>use the whiteboard version - it is up to date with CVS HEAD, and
>everyone else should give the new jar from whiteboard a try in their
>existing apps to make sure that the latest changes don't do any harm.
>It shouldn't :) The more testers the merrier.
>
>geir
>
>--
>Geir Magnusson Jr.                           geirm@optonline.net
>System and Software Consulting
>Developing for the web?  See http://jakarta.apache.org/velocity/
>Be well, do good work, and keep in touch.

Dan Finkelstein
Senior Architect, Instructional Tools & Technology
eMind LLC
Northern California Annex
1250 Addison St, Suite #210
Berkeley, CA 94702-1700
Tel: (510) 486-2740
Fax: (510)486-2843

Visit us at <http://www.emind.com/>

This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.


Re: #parse doesn't work with evaluate()

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
The reason why this doesn't work is because I have been a distracted
dunderhead lately and I didn't fix it when I fixed #inculde() - I will
have the fix in tonight...  I know what it is...

geir


Dan Finkelstein wrote:
> 
> Here's an odd one.   It happens in the 1.2 dev jar, not in Velocity
> 1.0.  #parse fails when evaluate() is used but works ok with
> getTemplate()/merge().
> 
> We have templates that begin something like this line:
> 
>         #parse ("global.vm")
> 
> It has a bunch of #set-s.  Typical lines might be something like
> 
>         #set ($jFontFace = 'Arial, Helvetica, Tahoma, Verdana, sans-serif')
>         #set ($style_author = "font-family: $jFontFace; font-size: 12pt; color:
> #CCCCCC")
> 
> What we really want is for this file to be read in before every template is
> processed, sort of like a global define.  Now, when we run our processor,
> velocity.log contains this error:
> 
>         Fri Jul 20 15:16:36 PDT 2001  [error] #parse : cannot find global.vm template!
> 
> Weird.  Now, if I change the line to
> 
>         #include ("global.vm")
> 
> then it finds the file just fine.  Strange, huh?
> 
> I included some small files so you can replicate it easily....
> 
> Thanks again,
> Dan
> 
> 
> 
>   ------------------------------------------------------------------------
> 
>    test.vmName: test.vm
>           Type: Plain Text (text/plain)
> 
>    Example.javaName: Example.java
>                Type: Plain Text (text/plain)
> 
>    example.vmName: example.vm
>              Type: Plain Text (text/plain)
> 
>   ------------------------------------------------------------------------
> Dan Finkelstein
> Senior Architect, Instructional Tools & Technology
> eMind LLC
> Northern California Annex
> 1250 Addison St, Suite #210
> Berkeley, CA 94702-1700
> Tel: (510) 486-2740
> Fax: (510)486-2843
> 
> Visit us at <http://www.emind.com/>
> 
> This email message is for the sole use of the intended recipient(s) and may
> contain confidential and privileged information. Any unauthorized review,
> use, disclosure or distribution is prohibited. If you are not the intended
> recipient, please contact the sender by reply email and destroy all copies
> of the original message.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: #parse doesn't work with evaluate()

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Dan Finkelstein wrote:
> 
> Here's an odd one.   It happens in the 1.2 dev jar, not in Velocity
> 1.0.  #parse fails when evaluate() is used but works ok with
> getTemplate()/merge().

[SNIP]

This is now fixed in both CVS HEAD as well as the proposed version in
/whiteboard/geir.

I am uploading a new source tree for the 'single instance' code as well
as a jar, so anyone interested in the new separate instance stuff should
use the whiteboard version - it is up to date with CVS HEAD, and
everyone else should give the new jar from whiteboard a try in their
existing apps to make sure that the latest changes don't do any harm. 
It shouldn't :) The more testers the merrier.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: #parse doesn't work with evaluate()

Posted by Jon Stevens <jo...@latchkey.com>.
on 7/20/01 4:04 PM, "Dan Finkelstein" <da...@emind.com> wrote:

> Here's an odd one.   It happens in the 1.2 dev jar, not in Velocity
> 1.0.  #parse fails when evaluate() is used but works ok with
> getTemplate()/merge().
> 
> We have templates that begin something like this line:
> 
> #parse ("global.vm")
> 
> It has a bunch of #set-s.  Typical lines might be something like
> 
> #set ($jFontFace = 'Arial, Helvetica, Tahoma, Verdana, sans-serif')
> #set ($style_author = "font-family: $jFontFace; font-size: 12pt; color:
> #CCCCCC")
> 
> What we really want is for this file to be read in before every template is
> processed, sort of like a global define.  Now, when we run our processor,
> velocity.log contains this error:
> 
> Fri Jul 20 15:16:36 PDT 2001  [error] #parse : cannot find global.vm template!
> 
> Weird.  Now, if I change the line to
> 
> #include ("global.vm")
> 
> then it finds the file just fine.  Strange, huh?
> 
> I included some small files so you can replicate it easily....
> 
> Thanks again,
> Dan

I would not say that is strange, more a lack of clarity...

I bet what is happening is that #parse is failing to properly parse the file
and therefore, it isn't available to the resource loader. #include doesn't
parse the file.

Now, the question is...why aren't you using #parse to load the file and not
the velocimacro.library= property?

-jon


#parse doesn't work with evaluate()

Posted by Dan Finkelstein <da...@emind.com>.
Here's an odd one.   It happens in the 1.2 dev jar, not in Velocity 
1.0.  #parse fails when evaluate() is used but works ok with 
getTemplate()/merge().

We have templates that begin something like this line:

	#parse ("global.vm")

It has a bunch of #set-s.  Typical lines might be something like

	#set ($jFontFace = 'Arial, Helvetica, Tahoma, Verdana, sans-serif')
	#set ($style_author = "font-family: $jFontFace; font-size: 12pt; color: 
#CCCCCC")

What we really want is for this file to be read in before every template is 
processed, sort of like a global define.  Now, when we run our processor, 
velocity.log contains this error:

	Fri Jul 20 15:16:36 PDT 2001  [error] #parse : cannot find global.vm template!

Weird.  Now, if I change the line to

	#include ("global.vm")

then it finds the file just fine.  Strange, huh?

I included some small files so you can replicate it easily....

Thanks again,
Dan

	

Re: VelocityEngine

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi guys,
> 
> I'm having a bit of trouble with a file in the CVS,
> namely whiteboard/geir/velocity_src_20010715.tgz , my
> system says it's corrupted.

Hm.

> 
> since I have been waiting to try this stuff VERY VERY
> EAGERLY, will somebody give me a list of method
> signatures in VelocityEngine ?
> 

I will upload a new src tonight, as I fixed (I hope) the #parse()/Eval()
problem reported by Dan, and since Dan is using the new single instance
(I think), I want that to be there for him.

I will also put the fix into CVS HEAD.

Anyone else, give the new VelocityEngine version a try - it's the same
as CVS HEAD except for the [widespread] changes to make single instance
possible.  These changes aren't really functional ( I did fix a small
bug or two...)  I don't want to continue too long with this not checked
in, as I have to do double work each time there is a fix (see above :),
so we should decide after a few people try it.

geir

> 
> and remember guys, we aren't Velocity users by
> chance...we rule!
> 
> piero de salvia
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

VelocityEngine

Posted by piero de salvia <pi...@yahoo.com>.
Hi guys,

I'm having a bit of trouble with a file in the CVS,
namely whiteboard/geir/velocity_src_20010715.tgz , my
system says it's corrupted. 

since I have been waiting to try this stuff VERY VERY
EAGERLY, will somebody give me a list of method
signatures in VelocityEngine ?

thanks

and remember guys, we aren't Velocity users by
chance...we rule!

piero de salvia

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
If so, I take back my suggestion to report an error for invalid 
'#' directives. After all, it is just a schmoo.

Tal

> -----Original Message-----
> From: Jeremy Leader [mailto:jleader@alumni.caltech.edu]
> Sent: Friday, July 20, 2001 9:20 AM
> To: velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
> 
> 
> At 09:11 AM 7/20/01 , Tal Dayan wrote:
> >I see, yes, this make sense.
> >
> >BTW, does the '#' directives such as #if need to be in the begining
> >of the line (after possibly a white space) or can they be anywhere
> >in the line ?
> >
> >Tal
> 
> I believe VTL directives are recognized anywhere in the line.
> At least, I've done things like:
> 
> <option name="foo" #if($a)selected#end>
> 
> and they worked.
> 
> Jeremy
> 
> 

RE: Any idea why this doesn't work

Posted by Jeremy Leader <jl...@alumni.caltech.edu>.
At 09:11 AM 7/20/01 , Tal Dayan wrote:
>I see, yes, this make sense.
>
>BTW, does the '#' directives such as #if need to be in the begining
>of the line (after possibly a white space) or can they be anywhere
>in the line ?
>
>Tal

I believe VTL directives are recognized anywhere in the line.
At least, I've done things like:

<option name="foo" #if($a)selected#end>

and they worked.

Jeremy


RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
I see, yes, this make sense.

BTW, does the '#' directives such as #if need to be in the begining
of the line (after possibly a white space) or can they be anywhere
in the line ?

Tal

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Friday, July 20, 2001 2:34 AM
> To: velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
> 
> 
> Tal,
> 
> That would mean that everywhere there was an # we would get an error.
> This may be useful, but would generate a lot of error messages (colour
> definitions for example) . 
> 
> Dave
> 
> -----Original Message-----
> From: Tal Dayan [mailto:tal@zapta.com] 
> Sent: July 20, 2001 5:31 AM
> To: Dave@micro-automation.net; velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
> 
> 
> I am not sure about that. '#elif' looks like an invalid directive, so
> Velocity could catch it (since there is a valid escape sequence to
> generate '#elif' is needed).
> 
> I think this is the behavior of standard C/CPP preprocessors, they give
> an error if you try to use a invalid directive.
> 
> Tal
> 
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: Friday, July 20, 2001 1:37 AM
> > To: 'Tal Dayan'; velocity-user@jakarta.apache.org
> > Subject: RE: Any idea why this doesn't work
> >
> >
> > No exception. Velocity didn't understand it so it rendered it. This is
> 
> > ok in retrospect, velocitiy can't be expected to catch every mistake, 
> > and still do the "right" thing every where else
> >
> > Dave
> >
> > -----Original Message-----
> > From: Tal Dayan [mailto:tal@zapta.com]
> > Sent: July 20, 2001 12:38 AM
> > To: velocity-user@jakarta.apache.org; Dave@micro-automation.net
> > Subject: RE: Any idea why this doesn't work
> >
> >
> > Just curious, did you get an exception or an error message or did the 
> > execution (merging) of the template went silently about the error ?
> >
> > Tal
> >
> > > -----Original Message-----
> > > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > > Sent: Thursday, July 19, 2001 6:56 PM
> > > To: velocity-user@jakarta.apache.org
> > > Subject: Any idea why this doesn't work
> > >
> > >
> > > The following works
> > >
> > >
> > > 	#if ($Store == 'Grocery')
> > >
> > >           <b>$Catalog.Render()</b>
> > >
> > >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > > color='#000000'><b>
> > >             <b>
> > >             	<a 
> > > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> > >             		Movie Rental
> > >             	</a>
> > >             </b>
> > >   	      </font>
> > >         #end
> > >         #if ($Store == 'Rental')
> > >           #foreach ($store in $OpenedStores)
> > > 	  	      <b><a 
> > > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > > Gr
> > > oc
> > > ery">
> > >             <font face="Arial, Helvetica, sans-serif" size="2"
> > > >$store.Name</font></a><br>
> > >           #end
> > >           <b>$Catalog.Render()</b>
> > > 	  #end
> > >
> > > But this doesn't
> > >
> > > 	#if ($Store == 'Grocery')
> > >
> > >           <b>$Catalog.Render()</b>
> > >
> > >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > > color='#000000'><b>
> > >             <b>
> > >             	<a 
> > > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> > >             		Movie Rental
> > >             	</a>
> > >             </b>
> > >   	      </font>
> > >
> > >         #elif ($Store == 'Rental')
> > >           #foreach ($store in $OpenedStores)
> > > 	  	      <b><a 
> > > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > > Gr
> > > oc
> > > ery">
> > >             <font face="Arial, Helvetica, sans-serif" size="2"
> > > >$store.Name</font></a><br>
> > >           #end
> > >           <b>$Catalog.Render()</b>
> > > 	  #end
> > >
> > > The difference is the #end #if was changed to #elif. When the 
> > > template
> >
> > > is displayed I see #elif (xxx == 'Grocery') on the page
> > >
> > > TIA,
> > >
> > > Dave
> > >
> > >
> >
> >
> >
> 
> 
> 

Re: Observation

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Dave Cramer wrote:
> 
> I had a quick look at the code, and it looks like
> 
> #if ($Object.Long == $Object.Integer) would return false even if they
> were equal in value

Yes - we don't do comparisons of anything but Integer and String.  It's
something we are working on, carefully.

> 
> Most compilers deal with this by promoting the smaller object to the
> larger, but this adds a lot of overhead.

Yes, and this isn't a programming language. :)
 
> A really easy way to deal with this is see if both sides are instances
> of Number and then compare their toString values.
> 
> I haven't tried the above so if I'm totally out of it, please ignore

No, this is valid.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Observation

Posted by Dave Cramer <Da...@micro-automation.net>.
I had a quick look at the code, and it looks like 

#if ($Object.Long == $Object.Integer) would return false even if they
were equal in value

Most compilers deal with this by promoting the smaller object to the
larger, but this adds a lot of overhead.

A really easy way to deal with this is see if both sides are instances
of Number and then compare their toString values. 

I haven't tried the above so if I'm totally out of it, please ignore

Dave


RE: Any idea why this doesn't work

Posted by Paulo Gaspar <pa...@krankikom.de>.
My 2 cents:
Considering the pros and cons I also prefer the current behavior.

Have fun,
Paulo Gaspar

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Friday, July 20, 2001 11:34 AM
> 
> 
> Tal,
> 
> That would mean that everywhere there was an # we would get an error.
> This may be useful, but would generate a lot of error messages (colour
> definitions for example) . 
> 
> Dave
> 
> -----Original Message-----
> From: Tal Dayan [mailto:tal@zapta.com] 
> Sent: July 20, 2001 5:31 AM
> To: Dave@micro-automation.net; velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
> 
> 
> I am not sure about that. '#elif' looks like an invalid directive, so
> Velocity could catch it (since there is a valid escape sequence to
> generate '#elif' is needed).
> 
> I think this is the behavior of standard C/CPP preprocessors, they give
> an error if you try to use a invalid directive.
> 
> Tal
> 
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: Friday, July 20, 2001 1:37 AM
> > To: 'Tal Dayan'; velocity-user@jakarta.apache.org
> > Subject: RE: Any idea why this doesn't work
> >
> >
> > No exception. Velocity didn't understand it so it rendered it. This is
> 
> > ok in retrospect, velocitiy can't be expected to catch every mistake, 
> > and still do the "right" thing every where else
> >
> > Dave
> >
> > -----Original Message-----
> > From: Tal Dayan [mailto:tal@zapta.com]
> > Sent: July 20, 2001 12:38 AM
> > To: velocity-user@jakarta.apache.org; Dave@micro-automation.net
> > Subject: RE: Any idea why this doesn't work
> >
> >
> > Just curious, did you get an exception or an error message or did the 
> > execution (merging) of the template went silently about the error ?
> >
> > Tal
> >
> > > -----Original Message-----
> > > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > > Sent: Thursday, July 19, 2001 6:56 PM
> > > To: velocity-user@jakarta.apache.org
> > > Subject: Any idea why this doesn't work
> > >
> > >
> > > The following works
> > >
> > >
> > > 	#if ($Store == 'Grocery')
> > >
> > >           <b>$Catalog.Render()</b>
> > >
> > >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > > color='#000000'><b>
> > >             <b>
> > >             	<a 
> > > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> > >             		Movie Rental
> > >             	</a>
> > >             </b>
> > >   	      </font>
> > >         #end
> > >         #if ($Store == 'Rental')
> > >           #foreach ($store in $OpenedStores)
> > > 	  	      <b><a 
> > > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > > Gr
> > > oc
> > > ery">
> > >             <font face="Arial, Helvetica, sans-serif" size="2"
> > > >$store.Name</font></a><br>
> > >           #end
> > >           <b>$Catalog.Render()</b>
> > > 	  #end
> > >
> > > But this doesn't
> > >
> > > 	#if ($Store == 'Grocery')
> > >
> > >           <b>$Catalog.Render()</b>
> > >
> > >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > > color='#000000'><b>
> > >             <b>
> > >             	<a 
> > > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> > >             		Movie Rental
> > >             	</a>
> > >             </b>
> > >   	      </font>
> > >
> > >         #elif ($Store == 'Rental')
> > >           #foreach ($store in $OpenedStores)
> > > 	  	      <b><a 
> > > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > > Gr
> > > oc
> > > ery">
> > >             <font face="Arial, Helvetica, sans-serif" size="2"
> > > >$store.Name</font></a><br>
> > >           #end
> > >           <b>$Catalog.Render()</b>
> > > 	  #end
> > >
> > > The difference is the #end #if was changed to #elif. When the 
> > > template
> >
> > > is displayed I see #elif (xxx == 'Grocery') on the page
> > >
> > > TIA,
> > >
> > > Dave
> > >
> > >
> >
> >
> >
> 
> 

RE: Any idea why this doesn't work

Posted by Dave Cramer <Da...@micro-automation.net>.
Tal,

That would mean that everywhere there was an # we would get an error.
This may be useful, but would generate a lot of error messages (colour
definitions for example) . 

Dave

-----Original Message-----
From: Tal Dayan [mailto:tal@zapta.com] 
Sent: July 20, 2001 5:31 AM
To: Dave@micro-automation.net; velocity-user@jakarta.apache.org
Subject: RE: Any idea why this doesn't work


I am not sure about that. '#elif' looks like an invalid directive, so
Velocity could catch it (since there is a valid escape sequence to
generate '#elif' is needed).

I think this is the behavior of standard C/CPP preprocessors, they give
an error if you try to use a invalid directive.

Tal

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Friday, July 20, 2001 1:37 AM
> To: 'Tal Dayan'; velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
>
>
> No exception. Velocity didn't understand it so it rendered it. This is

> ok in retrospect, velocitiy can't be expected to catch every mistake, 
> and still do the "right" thing every where else
>
> Dave
>
> -----Original Message-----
> From: Tal Dayan [mailto:tal@zapta.com]
> Sent: July 20, 2001 12:38 AM
> To: velocity-user@jakarta.apache.org; Dave@micro-automation.net
> Subject: RE: Any idea why this doesn't work
>
>
> Just curious, did you get an exception or an error message or did the 
> execution (merging) of the template went silently about the error ?
>
> Tal
>
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: Thursday, July 19, 2001 6:56 PM
> > To: velocity-user@jakarta.apache.org
> > Subject: Any idea why this doesn't work
> >
> >
> > The following works
> >
> >
> > 	#if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > color='#000000'><b>
> >             <b>
> >             	<a 
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >             		Movie Rental
> >             	</a>
> >             </b>
> >   	      </font>
> >         #end
> >         #if ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> > 	  	      <b><a 
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> > 	  #end
> >
> > But this doesn't
> >
> > 	#if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2' 
> > color='#000000'><b>
> >             <b>
> >             	<a 
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >             		Movie Rental
> >             	</a>
> >             </b>
> >   	      </font>
> >
> >         #elif ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> > 	  	      <b><a 
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=
> > Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> > 	  #end
> >
> > The difference is the #end #if was changed to #elif. When the 
> > template
>
> > is displayed I see #elif (xxx == 'Grocery') on the page
> >
> > TIA,
> >
> > Dave
> >
> >
>
>
>



RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
I am not sure about that. '#elif' looks like an invalid directive, so
Velocity
could catch it (since there is a valid escape sequence to generate
'#elif' is needed).

I think this is the behavior of standard C/CPP preprocessors, they give an
error if you try to use a invalid directive.

Tal

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Friday, July 20, 2001 1:37 AM
> To: 'Tal Dayan'; velocity-user@jakarta.apache.org
> Subject: RE: Any idea why this doesn't work
>
>
> No exception. Velocity didn't understand it so it rendered it. This is
> ok in retrospect, velocitiy can't be expected to catch every mistake,
> and still do the "right" thing every where else
>
> Dave
>
> -----Original Message-----
> From: Tal Dayan [mailto:tal@zapta.com]
> Sent: July 20, 2001 12:38 AM
> To: velocity-user@jakarta.apache.org; Dave@micro-automation.net
> Subject: RE: Any idea why this doesn't work
>
>
> Just curious, did you get an exception or an error message or did the
> execution (merging) of the template went silently about the error ?
>
> Tal
>
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: Thursday, July 19, 2001 6:56 PM
> > To: velocity-user@jakarta.apache.org
> > Subject: Any idea why this doesn't work
> >
> >
> > The following works
> >
> >
> > 	#if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2'
> > color='#000000'><b>
> >             <b>
> >             	<a
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >             		Movie Rental
> >             	</a>
> >             </b>
> >   	      </font>
> >         #end
> >         #if ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> > 	  	      <b><a
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> > 	  #end
> >
> > But this doesn't
> >
> > 	#if ($Store == 'Grocery')
> >
> >           <b>$Catalog.Render()</b>
> >
> >           <font face='Arial, Helvetica, sans-serif' size='2'
> > color='#000000'><b>
> >             <b>
> >             	<a
> > href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
> >             		Movie Rental
> >             	</a>
> >             </b>
> >   	      </font>
> >
> >         #elif ($Store == 'Rental')
> >           #foreach ($store in $OpenedStores)
> > 	  	      <b><a
> > href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> > oc
> > ery">
> >             <font face="Arial, Helvetica, sans-serif" size="2"
> > >$store.Name</font></a><br>
> >           #end
> >           <b>$Catalog.Render()</b>
> > 	  #end
> >
> > The difference is the #end #if was changed to #elif. When the template
>
> > is displayed I see #elif (xxx == 'Grocery') on the page
> >
> > TIA,
> >
> > Dave
> >
> >
>
>
>


RE: Any idea why this doesn't work

Posted by Dave Cramer <Da...@micro-automation.net>.
No exception. Velocity didn't understand it so it rendered it. This is
ok in retrospect, velocitiy can't be expected to catch every mistake,
and still do the "right" thing every where else

Dave

-----Original Message-----
From: Tal Dayan [mailto:tal@zapta.com] 
Sent: July 20, 2001 12:38 AM
To: velocity-user@jakarta.apache.org; Dave@micro-automation.net
Subject: RE: Any idea why this doesn't work


Just curious, did you get an exception or an error message or did the 
execution (merging) of the template went silently about the error ?

Tal

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Thursday, July 19, 2001 6:56 PM
> To: velocity-user@jakarta.apache.org
> Subject: Any idea why this doesn't work
> 
> 
> The following works
> 
> 
> 	#if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
>           
>           <font face='Arial, Helvetica, sans-serif' size='2' 
> color='#000000'><b>
>             <b>
>             	<a 
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>             		Movie Rental
>             	</a>
>             </b>
>   	      </font>
>         #end
>         #if ($Store == 'Rental') 
>           #foreach ($store in $OpenedStores)
> 	  	      <b><a 
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> oc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
> 	  #end
> 
> But this doesn't
> 
> 	#if ($Store == 'Grocery')
> 
>           <b>$Catalog.Render()</b>
>           
>           <font face='Arial, Helvetica, sans-serif' size='2' 
> color='#000000'><b>
>             <b>
>             	<a 
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>             		Movie Rental
>             	</a>
>             </b>
>   	      </font>
>         
>         #elif ($Store == 'Rental') 
>           #foreach ($store in $OpenedStores)
> 	  	      <b><a 
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Gr
> oc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
> 	  #end
> 
> The difference is the #end #if was changed to #elif. When the template

> is displayed I see #elif (xxx == 'Grocery') on the page
> 
> TIA,
> 
> Dave
> 
> 



RE: Any idea why this doesn't work

Posted by Tal Dayan <ta...@zapta.com>.
Just curious, did you get an exception or an error message or did the 
execution (merging) of the template went silently about the error ?

Tal

> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: Thursday, July 19, 2001 6:56 PM
> To: velocity-user@jakarta.apache.org
> Subject: Any idea why this doesn't work
> 
> 
> The following works
> 
> 
> 	#if ($Store == 'Grocery') 
> 
>           <b>$Catalog.Render()</b>
>           
>           <font face='Arial, Helvetica, sans-serif' size='2'
> color='#000000'><b>
>             <b>
>             	<a
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>             		Movie Rental
>             	</a>
>             </b>
>   	      </font>
>         #end
>         #if ($Store == 'Rental') 
>           #foreach ($store in $OpenedStores)
> 	  	      <b><a
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
> 	  #end
> 
> But this doesn't
> 
> 	#if ($Store == 'Grocery') 
> 
>           <b>$Catalog.Render()</b>
>           
>           <font face='Arial, Helvetica, sans-serif' size='2'
> color='#000000'><b>
>             <b>
>             	<a
> href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
>             		Movie Rental
>             	</a>
>             </b>
>   	      </font>
>         
>         #elif ($Store == 'Rental') 
>           #foreach ($store in $OpenedStores)
> 	  	      <b><a
> href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
> ery">
>             <font face="Arial, Helvetica, sans-serif" size="2"
> >$store.Name</font></a><br>
>           #end
>           <b>$Catalog.Render()</b>
> 	  #end
> 
> The difference is the #end #if was changed to #elif. When the template
> is displayed I see #elif (xxx == 'Grocery') on the page
> 
> TIA,
> 
> Dave
> 
> 

Any idea why this doesn't work

Posted by Dave Cramer <Da...@micro-automation.net>.
The following works


	#if ($Store == 'Grocery') 

          <b>$Catalog.Render()</b>
          
          <font face='Arial, Helvetica, sans-serif' size='2'
color='#000000'><b>
            <b>
            	<a
href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
            		Movie Rental
            	</a>
            </b>
  	      </font>
        #end
        #if ($Store == 'Rental') 
          #foreach ($store in $OpenedStores)
	  	      <b><a
href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
ery">
            <font face="Arial, Helvetica, sans-serif" size="2"
>$store.Name</font></a><br>
          #end
          <b>$Catalog.Render()</b>
	  #end

But this doesn't

	#if ($Store == 'Grocery') 

          <b>$Catalog.Render()</b>
          
          <font face='Arial, Helvetica, sans-serif' size='2'
color='#000000'><b>
            <b>
            	<a
href="$target?Command=catalog&amp;CategoryID=1100&amp;Store=Rental">
            		Movie Rental
            	</a>
            </b>
  	      </font>
        
        #elif ($Store == 'Rental') 
          #foreach ($store in $OpenedStores)
	  	      <b><a
href="$target?Command=catalog&amp;CategoryID=$store.CatId&amp;Store=Groc
ery">
            <font face="Arial, Helvetica, sans-serif" size="2"
>$store.Name</font></a><br>
          #end
          <b>$Catalog.Render()</b>
	  #end

The difference is the #end #if was changed to #elif. When the template
is displayed I see #elif (xxx == 'Grocery') on the page

TIA,

Dave


Re: Instantiable Velocity Engine

Posted by piero de salvia <pi...@yahoo.com>.
thinking about it,

maybe I need to move handleRequest() inside of
VelocityServlet.mergeTemplate()and do 
VelocityEngine.mergeTemplate in there, don't I ?

--- piero de salvia <pi...@yahoo.com> wrote:
> Hello everybody,
> 
> I am trying the instantiable VE in the Velocity
> servlet ( a modified versione of mine ) and,
> although
> I can do this : (vEngine = new VelocityEngine())
> 
> public Template getTemplate( String name )
>         throws ResourceNotFoundException,           
>  
> ParseErrorException, Exception
> {
> return vEngine.getTemplate(name);
> }
> 
> I cannot do this:
> 
> protected void mergeTemplate( Template template....
> {
> ...
> vEngine.mergeTemplate(template, context, vw);
> ....
> }
> 
> In the example app first arg is a String, but the
> servlet need to do getTemplate and Merge in two
> steps...
> 
> I tried to look into the source but it won't open,
> it
> seems corrupted (I am on Window$ - cannot do
> differently right now)
> 
> piero de salvia
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Instantiable Velocity Engine

Posted by piero de salvia <pi...@yahoo.com>.
Hello everybody,

I am trying the instantiable VE in the Velocity
servlet ( a modified versione of mine ) and, although
I can do this : (vEngine = new VelocityEngine())

public Template getTemplate( String name )
        throws ResourceNotFoundException,             
ParseErrorException, Exception
{
return vEngine.getTemplate(name);
}

I cannot do this:

protected void mergeTemplate( Template template.... {
...
vEngine.mergeTemplate(template, context, vw);
....
}

In the example app first arg is a String, but the
servlet need to do getTemplate and Merge in two
steps...

I tried to look into the source but it won't open, it
seems corrupted (I am on Window$ - cannot do
differently right now)

piero de salvia

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: To Singleton, or not to Singlton, that is the question...

Posted by Dan Finkelstein <da...@emind.com>.
Hi --

We have now successfully modified our application to take advantage of the 
multiple engine support that Geir has now incorporated into velocity.

I'm really pleased with the implementation and functionality. It solves 
what were some very tricky problems for us -- and our code is cleaner to boot.

Our architecture is a bit unusual, basically with two variations of 
velocity usage:

* We have normal servlets, which use templates for specifying the html 
pages. For this I'm using the static Velocity singleton.

* Then we have a publishing capability, where a lot of munging, or 
preprocessing, is taking place. Each of these publish processes may have 
differing characteristics so we instantiate a new velocity engine at the 
beginning of each process. And guess what? This is the WWW so we need to 
handle multiple publishes simultaneously.

The multiple engine support allows us to implement our design in a natural 
fashion -- we already use velocity on our live site and this new feature 
strongly reinforces our decision to go with this enabling technology.

And a special word of thanks to Geir -- who came through in record time 
with fixes for ancillary bugs, so that I could test this feature.  Thanks 
so much for your help and support!

As you might imagine, my vote is to fold this new feature into the source !!!

Dan





At 12:03 PM 7/17/01 -0700, you wrote:
>Hi Geir,
>
>This morning I tried to integrate the new multiple engine feature into our 
>system.  Unfortunately, I came to a stop because a bug that I reported to 
>you earlier doesn't seem to have been fixed.
>
>The bug was this:
>
>         The resource loader is unable to find #include files which 
> Velocity 1.1 when running
>         with Velocity.evaluate(). It works ok if I were to use 
> template.merge().
>         And it also works ok with Velocity 1.0.
>
>(see emails with subject "template load problem with evaluate()in Vel 1.1").
>
>Anyway, as you might imagine, I'm dying to try this out, but our system 
>relies heavily on the Velocity.evaluate() method.  Help!
>
>Thanks a lot,
>Dan
>
>At 11:45 PM 7/15/01 -0400, you wrote:
>>Once Brian finishes the CVS migration (Thanks, Brian!) to the new
>>server, I will put into whiteboard/geir a new jar, source tgz and
>>example proggie that is a successful attempt to convert Velocity to
>>allow multiple concurrent instances of the template engine in a given
>>program.
>>
>>I won't commit changes to CVS until people agree this is a good way to
>>go.  I don't want to have to back this change out :)  It's very broad
>>and touches most if not all parts of Velocity.
>>
>>Summary
>>=======
>>
>>You now have the option of how you want to use the Velocity template
>>engine in your applications :
>>
>>1) The current model of using the Velocity class to access the singlton
>>pattern is still valid - this jar should drop in and work anywhere the
>>exsting production or nightly jars work.
>>
>>2) There is a new class org.apache.velocity.app.VelocityEngine that can
>>be used in the way you suspect
>>
>>VelocityEngine ve = new VelocityEngine();
>>
>>and VelocityEngine currently has the same interface as Velocity, so
>>everything you can do now with the singleton will work with the
>>instance.
>>
>>Details
>>=======
>>
>>The basic idea is that all parts of velocity depended upon Runtime for
>>core services in that they would call things like  Runtime.error( msg )
>>to log, for example.  So, the class Runtime was renamed RuntimeInstance,
>>a new interface RuntimeServices was created (that has most of the old
>>Runtime methods), and a referece to RuntimeInstance (which implements
>>RuntimeServices) is passed into the various subcomponents of Velocity
>>for use to replace using the singleton for services.  To do this, any
>>other singleton classes are now instance classes (ResourceManager, for
>>example) as well, and a few things had to be slightly modified to break
>>singleton assumptions.
>>
>>So, the meta API of Velocity is :
>>
>>VelocityEngine : new class that is a new-able class to provide separate
>>instances, delegates all calls to a RuntimeInstance.  With it you can :
>>
>>VelocityEngine ve1 = new VelocityEngine();
>>VelocityEngine ve2 = new VelocityEngine();
>>
>>and then configure and init() each separately, as you would hope for...
>>
>>Velocity : the old Singleton application helper class. Nothing has
>>changed. Delegates calls to the RuntimeSingleton class.  You can and
>>should continue to use this for the Singleton model.
>>
>>RuntimeSingleton : renamed Runtime class, this is the static class for
>>Singleton usage.
>>
>>Runtime : new deprecated wrapper class, delegates to RuntimeSingleton.
>>I want to get rid of this if we go forward as I think that
>>RuntimeSingleton is a more descriptive class name.  Anyway, you
>>shouldn't be accessing the class directly in your applications - that's
>>what Velocity is for.
>>
>>The nice thing is that you can continue to use the Singleton model, or
>>even use both models concurrently.
>>
>>I converted Anakia to use an instance, but the structure of Texen
>>requires more work than I cared to do at the time, so it still requires
>>the singleton model.  This can be converted later, or left as is.  It's
>>up to the Texen tribe.  I will note that the failures we have been
>>seeing from Gump lately are due to a new classloader scheme in Ant that
>>Sam is trying which I believe could be solved by converting Texen to the
>>new instance model.
>>
>>The only real change is that anything implementing LogSystem must now
>>add an init( RuntimeServices) method, as the logger factory made this
>>necessary to pass the RuntimeServices.  I don't think this will be
>>something that affects many people at all.  It would only affect you if
>>you created your own personal logger class that is instantiated.  If you
>>have a logger class that you pass to Velocity as a living instance (yes,
>>you can do that - see the logger test and examples), all is ok.  We can
>>discuss this - if it's too large a burden, we can try to redo, but I
>>think that it would be counter productive in the long run.
>>
>>So, take a look at the code, and more importantly, test it out in
>>existing apps to make sure all is still healthy, and in new apps that
>>you were planning. There has been more and more interest in seeing this
>>solution, so lets give this a try.
>>
>>Note that there is no performance penalty for this (it actually sped up
>>as I found some spurious initialization of the syntax tree when going
>>through this :)
>>
>>Also, the example program is called InstanceExample, and is very very
>>simple. It was inspired by the needs of Turbine (or what I understand
>>their needs to be...) in that you setup two engines, and give each a
>>different template path, and then ask for the same template from each -
>>so you can have a default top level template index.vm for each of your
>>webapps, and don't really have to worry other than at setup time where
>>the templates are - you can make the same request into any engine...
>>
>>geir
>>
>>
>>
>>--
>>Geir Magnusson Jr.                           geirm@optonline.net
>>System and Software Consulting
>>Developing for the web?  See http://jakarta.apache.org/velocity/
>>You have a genius for suggesting things I've come a cropper with!
>
>Dan Finkelstein
>Senior Architect, Instructional Tools & Technology
>eMind LLC
>Northern California Annex
>1250 Addison St, Suite #210
>Berkeley, CA 94702-1700
>Tel: (510) 486-2740
>Fax: (510)486-2843
>
>Visit us at <http://www.emind.com/>
>
>This email message is for the sole use of the intended recipient(s) and may
>contain confidential and privileged information. Any unauthorized review,
>use, disclosure or distribution is prohibited. If you are not the intended
>recipient, please contact the sender by reply email and destroy all copies
>of the original message.
>

Dan Finkelstein
Senior Architect, Instructional Tools & Technology
eMind LLC
Northern California Annex
1250 Addison St, Suite #210
Berkeley, CA 94702-1700
Tel: (510) 486-2740
Fax: (510)486-2843

Visit us at <http://www.emind.com/>

This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.


RE: To Singleton, or not to Singlton, that is the question...

Posted by Paulo Gaspar <pa...@krankikom.de>.
That was the last one in my "big wishes" list. I was studying the code
in order to mess with that.

After getting to the point where I understood how hard it was going to 
be for me, I sure am _very_ glad that you did before I tried further.

Thanks a lot Geir,
Paulo

> -----Original Message-----
> From: gmj@mta2.srv.hcvlny.cv.net [mailto:gmj@mta2.srv.hcvlny.cv.net]On
> Behalf Of Geir Magnusson Jr.
> 
> 
> Once Brian finishes the CVS migration (Thanks, Brian!) to the new
> server, I will put into whiteboard/geir a new jar, source tgz and
> example proggie that is a successful attempt to convert Velocity to
> allow multiple concurrent instances of the template engine in a given
> program.
> 
> I won't commit changes to CVS until people agree this is a good way to
> go.  I don't want to have to back this change out :)  It's very broad
> and touches most if not all parts of Velocity.
> 
> Summary
> =======
> 
> You now have the option of how you want to use the Velocity template
> engine in your applications :
> 
> 1) The current model of using the Velocity class to access the singlton
> pattern is still valid - this jar should drop in and work anywhere the
> exsting production or nightly jars work.
> 
> 2) There is a new class org.apache.velocity.app.VelocityEngine that can
> be used in the way you suspect
> 
> VelocityEngine ve = new VelocityEngine();
> 
> and VelocityEngine currently has the same interface as Velocity, so
> everything you can do now with the singleton will work with the
> instance.
> 
> Details
> =======
> 
> The basic idea is that all parts of velocity depended upon Runtime for
> core services in that they would call things like  Runtime.error( msg )
> to log, for example.  So, the class Runtime was renamed RuntimeInstance,
> a new interface RuntimeServices was created (that has most of the old
> Runtime methods), and a referece to RuntimeInstance (which implements
> RuntimeServices) is passed into the various subcomponents of Velocity
> for use to replace using the singleton for services.  To do this, any
> other singleton classes are now instance classes (ResourceManager, for
> example) as well, and a few things had to be slightly modified to break
> singleton assumptions.
> 
> So, the meta API of Velocity is :
> 
> VelocityEngine : new class that is a new-able class to provide separate
> instances, delegates all calls to a RuntimeInstance.  With it you can :
> 
> VelocityEngine ve1 = new VelocityEngine();
> VelocityEngine ve2 = new VelocityEngine();
> 
> and then configure and init() each separately, as you would hope for...
> 
> Velocity : the old Singleton application helper class. Nothing has
> changed. Delegates calls to the RuntimeSingleton class.  You can and
> should continue to use this for the Singleton model.
> 
> RuntimeSingleton : renamed Runtime class, this is the static class for
> Singleton usage.  
> 
> Runtime : new deprecated wrapper class, delegates to RuntimeSingleton. 
> I want to get rid of this if we go forward as I think that
> RuntimeSingleton is a more descriptive class name.  Anyway, you
> shouldn't be accessing the class directly in your applications - that's
> what Velocity is for.
> 
> The nice thing is that you can continue to use the Singleton model, or
> even use both models concurrently.
> 
> I converted Anakia to use an instance, but the structure of Texen
> requires more work than I cared to do at the time, so it still requires
> the singleton model.  This can be converted later, or left as is.  It's
> up to the Texen tribe.  I will note that the failures we have been
> seeing from Gump lately are due to a new classloader scheme in Ant that
> Sam is trying which I believe could be solved by converting Texen to the
> new instance model.
> 
> The only real change is that anything implementing LogSystem must now
> add an init( RuntimeServices) method, as the logger factory made this
> necessary to pass the RuntimeServices.  I don't think this will be
> something that affects many people at all.  It would only affect you if
> you created your own personal logger class that is instantiated.  If you
> have a logger class that you pass to Velocity as a living instance (yes,
> you can do that - see the logger test and examples), all is ok.  We can
> discuss this - if it's too large a burden, we can try to redo, but I
> think that it would be counter productive in the long run.
> 
> So, take a look at the code, and more importantly, test it out in
> existing apps to make sure all is still healthy, and in new apps that
> you were planning. There has been more and more interest in seeing this
> solution, so lets give this a try.
> 
> Note that there is no performance penalty for this (it actually sped up
> as I found some spurious initialization of the syntax tree when going
> through this :)
> 
> Also, the example program is called InstanceExample, and is very very
> simple. It was inspired by the needs of Turbine (or what I understand
> their needs to be...) in that you setup two engines, and give each a
> different template path, and then ask for the same template from each -
> so you can have a default top level template index.vm for each of your
> webapps, and don't really have to worry other than at setup time where
> the templates are - you can make the same request into any engine...
> 
> geir
> 
> 
> 
> -- 
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!
> 

Re: To Singleton, or not to Singlton, that is the question...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi Geir,
> 
> I was, as some of you may remember, a big fan of the
> instantiable-at-will engine, so my vote is a
> resounding "YES". i will start testing away as soon as
> possible.
> 

That would be great - thanks.  We want to make sure this approach works
for everyone.  I think it should - nothing really is changed, and it's
100% (AFAIK) backwards compatible with the existing.


> In my opinion this gives a developer new and exciting
> ways to use Velocity, which after all is a template
> engine and not just a web page generator.

Yep!  +1

geir
 
> Velocity developers ROCK!
> 
> piero de salvia
> 
> --- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> > Once Brian finishes the CVS migration (Thanks,
> > Brian!) to the new
> > server, I will put into whiteboard/geir a new jar,
> > source tgz and
> > example proggie that is a successful attempt to
> > convert Velocity to
> > allow multiple concurrent instances of the template
> > engine in a given
> > program.
> >
> > I won't commit changes to CVS until people agree
> > this is a good way to
> > go.  I don't want to have to back this change out :)
> >  It's very broad
> > and touches most if not all parts of Velocity.
> >
> > Summary
> > =======
> >
> > You now have the option of how you want to use the
> > Velocity template
> > engine in your applications :
> >
> > 1) The current model of using the Velocity class to
> > access the singlton
> > pattern is still valid - this jar should drop in and
> > work anywhere the
> > exsting production or nightly jars work.
> >
> > 2) There is a new class
> > org.apache.velocity.app.VelocityEngine that can
> > be used in the way you suspect
> >
> > VelocityEngine ve = new VelocityEngine();
> >
> > and VelocityEngine currently has the same interface
> > as Velocity, so
> > everything you can do now with the singleton will
> > work with the
> > instance.
> >
> > Details
> > =======
> >
> > The basic idea is that all parts of velocity
> > depended upon Runtime for
> > core services in that they would call things like
> > Runtime.error( msg )
> > to log, for example.  So, the class Runtime was
> > renamed RuntimeInstance,
> > a new interface RuntimeServices was created (that
> > has most of the old
> > Runtime methods), and a referece to RuntimeInstance
> > (which implements
> > RuntimeServices) is passed into the various
> > subcomponents of Velocity
> > for use to replace using the singleton for services.
> >  To do this, any
> > other singleton classes are now instance classes
> > (ResourceManager, for
> > example) as well, and a few things had to be
> > slightly modified to break
> > singleton assumptions.
> >
> > So, the meta API of Velocity is :
> >
> > VelocityEngine : new class that is a new-able class
> > to provide separate
> > instances, delegates all calls to a RuntimeInstance.
> >  With it you can :
> >
> > VelocityEngine ve1 = new VelocityEngine();
> > VelocityEngine ve2 = new VelocityEngine();
> >
> > and then configure and init() each separately, as
> > you would hope for...
> >
> > Velocity : the old Singleton application helper
> > class. Nothing has
> > changed. Delegates calls to the RuntimeSingleton
> > class.  You can and
> > should continue to use this for the Singleton model.
> >
> > RuntimeSingleton : renamed Runtime class, this is
> > the static class for
> > Singleton usage.
> >
> > Runtime : new deprecated wrapper class, delegates to
> > RuntimeSingleton.
> > I want to get rid of this if we go forward as I
> > think that
> > RuntimeSingleton is a more descriptive class name.
> > Anyway, you
> > shouldn't be accessing the class directly in your
> > applications - that's
> > what Velocity is for.
> >
> > The nice thing is that you can continue to use the
> > Singleton model, or
> > even use both models concurrently.
> >
> > I converted Anakia to use an instance, but the
> > structure of Texen
> > requires more work than I cared to do at the time,
> > so it still requires
> > the singleton model.  This can be converted later,
> > or left as is.  It's
> > up to the Texen tribe.  I will note that the
> > failures we have been
> > seeing from Gump lately are due to a new classloader
> > scheme in Ant that
> > Sam is trying which I believe could be solved by
> > converting Texen to the
> > new instance model.
> >
> > The only real change is that anything implementing
> > LogSystem must now
> > add an init( RuntimeServices) method, as the logger
> > factory made this
> > necessary to pass the RuntimeServices.  I don't
> > think this will be
> > something that affects many people at all.  It would
> > only affect you if
> > you created your own personal logger class that is
> > instantiated.  If you
> > have a logger class that you pass to Velocity as a
> > living instance (yes,
> > you can do that - see the logger test and examples),
> > all is ok.  We can
> > discuss this - if it's too large a burden, we can
> > try to redo, but I
> > think that it would be counter productive in the
> > long run.
> >
> > So, take a look at the code, and more importantly,
> > test it out in
> > existing apps to make sure all is still healthy, and
> > in new apps that
> > you were planning. There has been more and more
> > interest in seeing this
> > solution, so lets give this a try.
> >
> > Note that there is no performance penalty for this
> > (it actually sped up
> > as I found some spurious initialization of the
> > syntax tree when going
> > through this :)
> >
> > Also, the example program is called InstanceExample,
> > and is very very
> > simple. It was inspired by the needs of Turbine (or
> > what I understand
> > their needs to be...) in that you setup two engines,
> > and give each a
> > different template path, and then ask for the same
> > template from each -
> > so you can have a default top level template
> > index.vm for each of your
> > webapps, and don't really have to worry other than
> > at setup time where
> > the templates are - you can make the same request
> > into any engine...
> >
> > geir
> >
> >
> >
> > --
> > Geir Magnusson Jr.
> > geirm@optonline.net
> > System and Software Consulting
> > Developing for the web?  See
> > http://jakarta.apache.org/velocity/
> > You have a genius for suggesting things I've come a
> > cropper with!
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: To Singleton, or not to Singlton, that is the question...

Posted by piero de salvia <pi...@yahoo.com>.
Hi Geir,

I was, as some of you may remember, a big fan of the
instantiable-at-will engine, so my vote is a
resounding "YES". i will start testing away as soon as
possible. 

In my opinion this gives a developer new and exciting
ways to use Velocity, which after all is a template
engine and not just a web page generator.

Velocity developers ROCK!

piero de salvia


--- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> Once Brian finishes the CVS migration (Thanks,
> Brian!) to the new
> server, I will put into whiteboard/geir a new jar,
> source tgz and
> example proggie that is a successful attempt to
> convert Velocity to
> allow multiple concurrent instances of the template
> engine in a given
> program.
> 
> I won't commit changes to CVS until people agree
> this is a good way to
> go.  I don't want to have to back this change out :)
>  It's very broad
> and touches most if not all parts of Velocity.
> 
> Summary
> =======
> 
> You now have the option of how you want to use the
> Velocity template
> engine in your applications :
> 
> 1) The current model of using the Velocity class to
> access the singlton
> pattern is still valid - this jar should drop in and
> work anywhere the
> exsting production or nightly jars work.
> 
> 2) There is a new class
> org.apache.velocity.app.VelocityEngine that can
> be used in the way you suspect
> 
> VelocityEngine ve = new VelocityEngine();
> 
> and VelocityEngine currently has the same interface
> as Velocity, so
> everything you can do now with the singleton will
> work with the
> instance.
> 
> Details
> =======
> 
> The basic idea is that all parts of velocity
> depended upon Runtime for
> core services in that they would call things like 
> Runtime.error( msg )
> to log, for example.  So, the class Runtime was
> renamed RuntimeInstance,
> a new interface RuntimeServices was created (that
> has most of the old
> Runtime methods), and a referece to RuntimeInstance
> (which implements
> RuntimeServices) is passed into the various
> subcomponents of Velocity
> for use to replace using the singleton for services.
>  To do this, any
> other singleton classes are now instance classes
> (ResourceManager, for
> example) as well, and a few things had to be
> slightly modified to break
> singleton assumptions.
> 
> So, the meta API of Velocity is :
> 
> VelocityEngine : new class that is a new-able class
> to provide separate
> instances, delegates all calls to a RuntimeInstance.
>  With it you can :
> 
> VelocityEngine ve1 = new VelocityEngine();
> VelocityEngine ve2 = new VelocityEngine();
> 
> and then configure and init() each separately, as
> you would hope for...
> 
> Velocity : the old Singleton application helper
> class. Nothing has
> changed. Delegates calls to the RuntimeSingleton
> class.  You can and
> should continue to use this for the Singleton model.
> 
> RuntimeSingleton : renamed Runtime class, this is
> the static class for
> Singleton usage.  
> 
> Runtime : new deprecated wrapper class, delegates to
> RuntimeSingleton. 
> I want to get rid of this if we go forward as I
> think that
> RuntimeSingleton is a more descriptive class name. 
> Anyway, you
> shouldn't be accessing the class directly in your
> applications - that's
> what Velocity is for.
> 
> The nice thing is that you can continue to use the
> Singleton model, or
> even use both models concurrently.
> 
> I converted Anakia to use an instance, but the
> structure of Texen
> requires more work than I cared to do at the time,
> so it still requires
> the singleton model.  This can be converted later,
> or left as is.  It's
> up to the Texen tribe.  I will note that the
> failures we have been
> seeing from Gump lately are due to a new classloader
> scheme in Ant that
> Sam is trying which I believe could be solved by
> converting Texen to the
> new instance model.
> 
> The only real change is that anything implementing
> LogSystem must now
> add an init( RuntimeServices) method, as the logger
> factory made this
> necessary to pass the RuntimeServices.  I don't
> think this will be
> something that affects many people at all.  It would
> only affect you if
> you created your own personal logger class that is
> instantiated.  If you
> have a logger class that you pass to Velocity as a
> living instance (yes,
> you can do that - see the logger test and examples),
> all is ok.  We can
> discuss this - if it's too large a burden, we can
> try to redo, but I
> think that it would be counter productive in the
> long run.
> 
> So, take a look at the code, and more importantly,
> test it out in
> existing apps to make sure all is still healthy, and
> in new apps that
> you were planning. There has been more and more
> interest in seeing this
> solution, so lets give this a try.
> 
> Note that there is no performance penalty for this
> (it actually sped up
> as I found some spurious initialization of the
> syntax tree when going
> through this :)
> 
> Also, the example program is called InstanceExample,
> and is very very
> simple. It was inspired by the needs of Turbine (or
> what I understand
> their needs to be...) in that you setup two engines,
> and give each a
> different template path, and then ask for the same
> template from each -
> so you can have a default top level template
> index.vm for each of your
> webapps, and don't really have to worry other than
> at setup time where
> the templates are - you can make the same request
> into any engine...
> 
> geir
> 
> 
> 
> -- 
> Geir Magnusson Jr.                          
> geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See
> http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a
> cropper with!


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

ATTN: Scott Eade. (WAS: caching templates)

Posted by ps...@comcen.com.au.
Scott,
I think you were asking about how to get velocity
to reload macros without restarting, well, I've
been all the ways through this with Gier a few weeks ago
and it seems in addition to setting the TRProps
correctly, if you call #parse("yourlib.vm") before
using it, you will see any changes you have made 
and saved while Turbine is running (I'm assuming Turbine,
though principle is same).

The docs say #parse() will render to the screen, but it
does not, (which suits me fine anyway), so just use
#parse() before using your function and you'll be fine. :)

Patrick.

Re: To Singleton, or not to Singlton, that is the question...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Dan Finkelstein wrote:
> 
> Hi Geir,
> 
> This morning I tried to integrate the new multiple engine feature into our
> system.  Unfortunately, I came to a stop because a bug that I reported to
> you earlier doesn't seem to have been fixed.

Please accept my apologies. (I feel like a dolt...)

I fixed it as soon as you noted it in the 1.1 branch thinking it would
be a 1.1.1 bugfix release.

However, I didn't do it to HEAD, which is where the multiple engine
feature lives.

I will fix now and commit to the whiteboard both src and a jar.

Sorry...

geir

> 
> The bug was this:
> 
>          The resource loader is unable to find #include files which
> Velocity 1.1 when running
>          with Velocity.evaluate(). It works ok if I were to use
> template.merge().
>          And it also works ok with Velocity 1.0.
> 
> (see emails with subject "template load problem with evaluate()in Vel 1.1").
> 
> Anyway, as you might imagine, I'm dying to try this out, but our system
> relies heavily on the Velocity.evaluate() method.  Help!
> 
> Thanks a lot,
> Dan
> 

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: To Singleton, or not to Singlton, that is the question...

Posted by Dan Finkelstein <da...@emind.com>.
Hi Geir,

This morning I tried to integrate the new multiple engine feature into our 
system.  Unfortunately, I came to a stop because a bug that I reported to 
you earlier doesn't seem to have been fixed.

The bug was this:

         The resource loader is unable to find #include files which 
Velocity 1.1 when running
         with Velocity.evaluate(). It works ok if I were to use 
template.merge().
         And it also works ok with Velocity 1.0.

(see emails with subject "template load problem with evaluate()in Vel 1.1").

Anyway, as you might imagine, I'm dying to try this out, but our system 
relies heavily on the Velocity.evaluate() method.  Help!

Thanks a lot,
Dan

At 11:45 PM 7/15/01 -0400, you wrote:
>Once Brian finishes the CVS migration (Thanks, Brian!) to the new
>server, I will put into whiteboard/geir a new jar, source tgz and
>example proggie that is a successful attempt to convert Velocity to
>allow multiple concurrent instances of the template engine in a given
>program.
>
>I won't commit changes to CVS until people agree this is a good way to
>go.  I don't want to have to back this change out :)  It's very broad
>and touches most if not all parts of Velocity.
>
>Summary
>=======
>
>You now have the option of how you want to use the Velocity template
>engine in your applications :
>
>1) The current model of using the Velocity class to access the singlton
>pattern is still valid - this jar should drop in and work anywhere the
>exsting production or nightly jars work.
>
>2) There is a new class org.apache.velocity.app.VelocityEngine that can
>be used in the way you suspect
>
>VelocityEngine ve = new VelocityEngine();
>
>and VelocityEngine currently has the same interface as Velocity, so
>everything you can do now with the singleton will work with the
>instance.
>
>Details
>=======
>
>The basic idea is that all parts of velocity depended upon Runtime for
>core services in that they would call things like  Runtime.error( msg )
>to log, for example.  So, the class Runtime was renamed RuntimeInstance,
>a new interface RuntimeServices was created (that has most of the old
>Runtime methods), and a referece to RuntimeInstance (which implements
>RuntimeServices) is passed into the various subcomponents of Velocity
>for use to replace using the singleton for services.  To do this, any
>other singleton classes are now instance classes (ResourceManager, for
>example) as well, and a few things had to be slightly modified to break
>singleton assumptions.
>
>So, the meta API of Velocity is :
>
>VelocityEngine : new class that is a new-able class to provide separate
>instances, delegates all calls to a RuntimeInstance.  With it you can :
>
>VelocityEngine ve1 = new VelocityEngine();
>VelocityEngine ve2 = new VelocityEngine();
>
>and then configure and init() each separately, as you would hope for...
>
>Velocity : the old Singleton application helper class. Nothing has
>changed. Delegates calls to the RuntimeSingleton class.  You can and
>should continue to use this for the Singleton model.
>
>RuntimeSingleton : renamed Runtime class, this is the static class for
>Singleton usage.
>
>Runtime : new deprecated wrapper class, delegates to RuntimeSingleton.
>I want to get rid of this if we go forward as I think that
>RuntimeSingleton is a more descriptive class name.  Anyway, you
>shouldn't be accessing the class directly in your applications - that's
>what Velocity is for.
>
>The nice thing is that you can continue to use the Singleton model, or
>even use both models concurrently.
>
>I converted Anakia to use an instance, but the structure of Texen
>requires more work than I cared to do at the time, so it still requires
>the singleton model.  This can be converted later, or left as is.  It's
>up to the Texen tribe.  I will note that the failures we have been
>seeing from Gump lately are due to a new classloader scheme in Ant that
>Sam is trying which I believe could be solved by converting Texen to the
>new instance model.
>
>The only real change is that anything implementing LogSystem must now
>add an init( RuntimeServices) method, as the logger factory made this
>necessary to pass the RuntimeServices.  I don't think this will be
>something that affects many people at all.  It would only affect you if
>you created your own personal logger class that is instantiated.  If you
>have a logger class that you pass to Velocity as a living instance (yes,
>you can do that - see the logger test and examples), all is ok.  We can
>discuss this - if it's too large a burden, we can try to redo, but I
>think that it would be counter productive in the long run.
>
>So, take a look at the code, and more importantly, test it out in
>existing apps to make sure all is still healthy, and in new apps that
>you were planning. There has been more and more interest in seeing this
>solution, so lets give this a try.
>
>Note that there is no performance penalty for this (it actually sped up
>as I found some spurious initialization of the syntax tree when going
>through this :)
>
>Also, the example program is called InstanceExample, and is very very
>simple. It was inspired by the needs of Turbine (or what I understand
>their needs to be...) in that you setup two engines, and give each a
>different template path, and then ask for the same template from each -
>so you can have a default top level template index.vm for each of your
>webapps, and don't really have to worry other than at setup time where
>the templates are - you can make the same request into any engine...
>
>geir
>
>
>
>--
>Geir Magnusson Jr.                           geirm@optonline.net
>System and Software Consulting
>Developing for the web?  See http://jakarta.apache.org/velocity/
>You have a genius for suggesting things I've come a cropper with!

Dan Finkelstein
Senior Architect, Instructional Tools & Technology
eMind LLC
Northern California Annex
1250 Addison St, Suite #210
Berkeley, CA 94702-1700
Tel: (510) 486-2740
Fax: (510)486-2843

Visit us at <http://www.emind.com/>

This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.