|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.RenderTool
public class RenderTool
This tool exposes methods to evaluate the given strings as VTL (Velocity Template Language) using the given context.
NOTE: These examples assume you have placed an instance of the current context within itself as 'ctx'. And, of course, the RenderTool is assumed to be available as 'render'.
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! Toolbox configuration: <tool> <key>render</key> <class>org.apache.velocity.tools.generic.RenderTool</class> </tool>
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 boolean |
catchExceptions
|
static int |
DEFAULT_PARSE_DEPTH
The maximum number of loops allowed when recursing. |
private org.apache.velocity.app.VelocityEngine |
engine
|
static java.lang.String |
KEY_CATCH_EXCEPTIONS
|
static java.lang.String |
KEY_PARSE_DEPTH
|
private static java.lang.String |
LOG_TAG
|
private int |
parseDepth
|
Constructor Summary | |
---|---|
RenderTool()
|
Method Summary | |
---|---|
void |
configure(java.util.Map params)
Looks for parse depth and catch.exceptions parameters. |
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. |
boolean |
getCatchExceptions()
Returns true if this render() and eval() methods will
catch exceptions thrown during rendering. |
int |
getParseDepth()
Get the maximum number of loops allowed when recursing. |
private java.lang.String |
internalEval(org.apache.velocity.context.Context ctx,
java.lang.String vtl)
|
protected java.lang.String |
internalRecurse(org.apache.velocity.context.Context ctx,
java.lang.String vtl,
int count)
|
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. |
void |
setCatchExceptions(boolean catchExceptions)
Sets whether or not the render() and eval() methods should catch exceptions during their execution or not. |
void |
setParseDepth(int depth)
Set the maximum number of loops allowed when recursing. |
void |
setVelocityEngine(org.apache.velocity.app.VelocityEngine ve)
Allow user to specify a VelocityEngine to be used in place of the Velocity singleton. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PARSE_DEPTH
public static final java.lang.String KEY_PARSE_DEPTH
public static final java.lang.String KEY_CATCH_EXCEPTIONS
private static final java.lang.String LOG_TAG
private org.apache.velocity.app.VelocityEngine engine
private int parseDepth
private boolean catchExceptions
Constructor Detail |
---|
public RenderTool()
Method Detail |
---|
public void configure(java.util.Map params)
public void setVelocityEngine(org.apache.velocity.app.VelocityEngine ve)
public void setParseDepth(int depth)
public int getParseDepth()
public void setCatchExceptions(boolean catchExceptions)
public boolean getCatchExceptions()
true
if this render() and eval() methods will
catch exceptions thrown during rendering.
public 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. By default if this fails, then
null
will be returned, though this tool can be configured
to let Exceptions pass through. This evaluation is not recursive.
ctx
- the current Contextvtl
- the code to be evaluated
java.lang.Exception
private java.lang.String internalEval(org.apache.velocity.context.Context ctx, java.lang.String vtl) throws java.lang.Exception
java.lang.Exception
public 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 or the number of recursive loops exceeds the set parse depth.
ctx
- the current Contextvtl
- the code to be evaluated
java.lang.Exception
protected java.lang.String internalRecurse(org.apache.velocity.context.Context ctx, java.lang.String vtl, int count) throws java.lang.Exception
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |