org.webmacro.servlet
Class TemplateTool.MacroTemplate
java.lang.Object
|
+--org.webmacro.servlet.TemplateTool.MacroTemplate
- Enclosing class:
- TemplateTool
- public class TemplateTool.MacroTemplate
- extends java.lang.Object
Encapsulates a template and a context, allowing a template
to be used like a function or "macro".
Method Summary |
void |
copyCurrentContext()
Copies all variables from the current request context into the context
of the macro. |
java.lang.Object |
eval()
Evaluates the macro's template against its context and returns the
resulting string. |
java.lang.Object |
eval(java.lang.Object[] args)
|
java.lang.Object |
eval(java.lang.Object[] args,
java.lang.Object[] names)
|
Context |
getArgs()
Exposes the context of the current MacroTemplate. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TemplateTool.MacroTemplate
public TemplateTool.MacroTemplate(Context c,
Template t)
- Constructor
- Parameters:
c
- the current request contextt
- the template to be used as a macro
TemplateTool.MacroTemplate
public TemplateTool.MacroTemplate(Context c,
java.lang.String src)
- Construct a MacroTemplate with a StringTemplate
- Parameters:
c
- The context of the current requestsrc
- the string for the StringTemplate
getArgs
public Context getArgs()
- Exposes the context of the current MacroTemplate. This allows
"arguments" to be set from a template. E.g.,
#set $myMacro.Args.Name = $User.Name
- Returns:
- the context of the macro
eval
public java.lang.Object eval()
throws PropertyException
- Evaluates the macro's template against its context and returns the
resulting string.
- Returns:
- the resultant string after the template is evaluated.
- Throws:
PropertyException
- runtime errors in evaluating the macro's template
eval
public java.lang.Object eval(java.lang.Object[] args)
throws PropertyException
eval
public java.lang.Object eval(java.lang.Object[] args,
java.lang.Object[] names)
throws PropertyException
copyCurrentContext
public void copyCurrentContext()
- Copies all variables from the current request context into the context
of the macro.