[ 
https://issues.apache.org/jira/browse/VELOCITY-102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12622923#action_12622923
 ] 

Nathan Bubna commented on VELOCITY-102:
---------------------------------------

I can't say i'm fond of the idea for a few reasons.  First, the very reasons 
that i like context.put("math", Math.class) are that it keeps control of the 
name fully in the hands of the context creator, and that when working on the 
template, you don't really need to know that $math is anything special.  :)  
I've long been an advocate of hiding java-isms (like the difference between 
arrays and lists) from templates.  Despite the fact that it is java-powered and 
allows java methods to be called, VTL is not java.   When we do things that 
make it more like java, then it complicates it and makes it more difficult to 
swap things around on the java side.  So, i prefer the ignorance that comes 
with something like $view.CONTEXT, as it allows $view to be almost anything and 
CONTEXT to refer to getCONTEXT() or get("CONTEXT").  This loose binding 
provides a lot of implementation flexibility that a tighter binding would not.  
 The class can evolve a lot without ever needing to update the t
 emplate.

So, i actually think keeping things to $view.CONTEXT simplifies things.  No 
worries about classes with same name and different package, no need to consider 
if something is accessed through a class or an instance, as there is no actual 
difference between the way the two behave.

> Add Support for Static Utility Classes
> --------------------------------------
>
>                 Key: VELOCITY-102
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-102
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.3-rc1
>         Environment: Operating System: All
> Platform: All
>            Reporter: Juozas Baliuka
>            Priority: Minor
>             Fix For: 1.6
>
>
> Support for Static Utility Classes is:
> 1) define namespaces
>   
>   context.defineNamespace("Math").add( java.lang.Math.class  ) ;
>    used as $Math.sin(0)
> 2) Add / Replace / remove methods in namespace :
>   
> context.getNamespace("Math").add(MyRandom.class.getMethod("randomString",new 
> Class[]{int.class}))
>   used as $Math.randomString(12)
> 3) "union" on namespaces
>  context.defineNamespace("Utils")
>           .add(context.getNamespace("Math"))
>           .add(context.defineNamespace("Collections",Collections.class ) );
>  used as:
>   $Utils.sin(0)
>   $Utils.sort($list)
> 4) Global namespace
>   context.getGlobalNamespace().add( Math.class ); 
>   used as $sin(0)
> 5) inline namespaces:
>  #use java.lang.Math as Math
>    $Math.sin(0)
>  #end
>  #with Math
>    $sin(0)
>  #end

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to