You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thierry Legrain <tl...@scort.com> on 2001/01/15 14:36:11 UTC

Bugs and features


Hi,

I find this engine very useful and I hope you appreciate my tiny contribution.
Bug :
if you have $value1.test() and you want x.test() for result, you must to exclude or escape ".".

Features :
How to put a static class to call static method, attributes, ...
How to add a new escaper (other than HTML)

Thanks.

Thierry.

Re: Bugs and features

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Christoph Reck wrote:
> 
> DO NOT takeover the [PATCH] I provided here.

I wasn't going to...  (I am trying to have breakfast with my wife who
just got back from a trip, but the call of Velocity keeps luring me into
my office...)

I was going to think about it, but I wasn't very thrilled with the
idea.  I figured you hadn't tested it all that hard...

:)

> It breaks code like $foo.getClass().getName() because the
> introspector would then try the class of foo which does
> not have a static getName method.
> (Note: I use getClass().getName() within templates sometimes
>  to ensure they contain what I expect and for debug-dumps
>  of the context).
> 
> I guess the only solutions are:
> + to place an instance of the class into the context, or
> + to use a context tool that accesses the static methods.

+1 on both


-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: Bugs and features

Posted by Christoph Reck <Ch...@dlr.de>.
DO NOT takeover the [PATCH] I provided here.

It breaks code like $foo.getClass().getName() because the 
introspector would then try the class of foo which does 
not have a static getName method. 
(Note: I use getClass().getName() within templates sometimes 
 to ensure they contain what I expect and for debug-dumps
 of the context).

I guess the only solutions are:
+ to place an instance of the class into the context, or 
+ to use a context tool that accesses the static methods.

:) Christoph

Re: Bugs and features

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Christoph Reck wrote:
> 
> Patch embeded.
> 
> Thierry Legrain wrote:
> >
> > Hi,
> >
> > I find this engine very useful and I hope you appreciate my tiny contribution.
> > Bug :
> > if you have $value1.test() and you want x.test() for result, you must to exclude or escape ".".
> 
> use ${value1}.test() and read the VTL Reference Guide. This form is
> called a formal reference there.

That works, but there is still a bug related to this.

> 
> >
> > Features :
> > How to put a static class to call static method, attributes, ...
> 
> Currently Velocity it is designed to access intances of objects that
> provide a bean-like interface (get and set methods). Additionally it
> has the power of accessing any method via an introspection engine.
> 
> You can access any static method of an object instance.
> E.g. you can take any string:
>   #set( $foo = "" )
> and call the static method from it:
>   The string form of a boolean TRUE = $foo.valueOf(true)
> 
> Currently it has a limitation that the introspection engine will not
> work on the Class of an object itself (when it is not the instance)
> The patch below overcomes the limitation:
> 
> [PATCH]
> changing the line 172 of the ASTMethod.java execute method to
>             Class c = (o instanceof Class) ? (Class)o :  o.getClass();
> then allows accessing static methods of a class, e.g.
>   context.put("String", Class.forName("java.lang.String"));
> in the tamplate:
>   The string form of a boolean TRUE = $String.valueOf(true)
> 
> Geir, could you ingest this patch? Any objections?
> 
> > How to add a new escaper (other than HTML)
> 
> Put a corresponding tool into the context. I have submitted code to
> do HTML and other escaping to this list previously. Jason van Zyl
> has states that thgis and others are beeing collected to provide
> a sensible set of tools within the velocity package.
> 
> >
> > Thanks.
> >
> > Thierry.
> 
> :) Christoph

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: Bugs and features

Posted by Christoph Reck <Ch...@dlr.de>.
Patch embeded.

Thierry Legrain wrote:
> 
> Hi,
> 
> I find this engine very useful and I hope you appreciate my tiny contribution.
> Bug :
> if you have $value1.test() and you want x.test() for result, you must to exclude or escape ".".

use ${value1}.test() and read the VTL Reference Guide. This form is 
called a formal reference there.

> 
> Features :
> How to put a static class to call static method, attributes, ...

Currently Velocity it is designed to access intances of objects that
provide a bean-like interface (get and set methods). Additionally it 
has the power of accessing any method via an introspection engine.

You can access any static method of an object instance.
E.g. you can take any string:
  #set( $foo = "" )
and call the static method from it:
  The string form of a boolean TRUE = $foo.valueOf(true)

Currently it has a limitation that the introspection engine will not
work on the Class of an object itself (when it is not the instance)
The patch below overcomes the limitation:

[PATCH]
changing the line 172 of the ASTMethod.java execute method to
            Class c = (o instanceof Class) ? (Class)o :  o.getClass();
then allows accessing static methods of a class, e.g. 
  context.put("String", Class.forName("java.lang.String"));
in the tamplate:
  The string form of a boolean TRUE = $String.valueOf(true)

Geir, could you ingest this patch? Any objections?

> How to add a new escaper (other than HTML)

Put a corresponding tool into the context. I have submitted code to
do HTML and other escaping to this list previously. Jason van Zyl
has states that thgis and others are beeing collected to provide
a sensible set of tools within the velocity package.


> 
> Thanks.
> 
> Thierry.

:) Christoph

Re: Bugs and features

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Thierry Legrain wrote:
> 
> Hi,
> 
> I find this engine very useful and I hope you appreciate my tiny contribution.
> Bug :
> if you have $value1.test() and you want x.test() for result, you must to exclude or escape ".".

Does whatever is in the context for $value1 have a test() method?

> 
> Features :
> How to put a static class to call static method, attributes, ...

What do you mean?

> How to add a new escaper (other than HTML)

What do you mean?  

> 
> Thanks.
> 
> Thierry.

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity