|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.tools.generic.RenderTool
This tool expose static methods to evaluate the given
strings as VTL (Velocity Template Language)
using the given context.
Example of eval(): Input ----- #set( $list = [1,2,3] ) #set( $object = '$list' ) #set( $method = 'size()' ) $render.eval($ctx, "${object}.$method") Output ------ 3 Example of recurse(): Input ----- #macro( say_hi )hello world!#end #set( $foo = '#say_hi()' ) #set( $bar = '$foo' ) $render.recurse($ctx, $bar) Output ------ hello world!
Ok, so these examples are really lame. But, it seems like someone out there is always asking how to do stuff like this and we always tell them to write a tool. Now we can just tell them to use this tool.
This tool is safe (and optimized) for use in the application scope of a servlet environment.
Field Summary | |
private static java.lang.String |
LOG_TAG
|
Constructor Summary | |
RenderTool()
Constructs a new instance |
Method Summary | |
static java.lang.String |
eval(org.apache.velocity.context.Context ctx,
java.lang.String vtl)
Evaluates a String containing VTL using the current context, and returns the result as a String. |
static java.lang.String |
recurse(org.apache.velocity.context.Context ctx,
java.lang.String vtl)
Recursively evaluates a String containing VTL using the current context, and returns the result as a String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final java.lang.String LOG_TAG
Constructor Detail |
public RenderTool()
Method Detail |
public static java.lang.String eval(org.apache.velocity.context.Context ctx, java.lang.String vtl) throws java.lang.Exception
Evaluates a String containing VTL using the current context,
and returns the result as a String. If this fails, then
null
will be returned. This evaluation is not
recursive.
ctx
- the current Contextvtl
- the code to be evaluated
java.lang.Exception
public static java.lang.String recurse(org.apache.velocity.context.Context ctx, java.lang.String vtl) throws java.lang.Exception
Recursively evaluates a String containing VTL using the current context, and returns the result as a String. It will continue to re-evaluate the output of the last evaluation until an evaluation returns the same code that was fed into it.
FIXME? add a parse-depth to prevent infinite recursion?
ctx
- the current Contextvtl
- the code to be evaluated
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |