org.webmacro.servlet
Class TemplateTool.MacroTemplate

java.lang.Object
  extended byorg.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".


Constructor Summary
TemplateTool.MacroTemplate(Context c, java.lang.String src)
          Construct a MacroTemplate with a StringTemplate
TemplateTool.MacroTemplate(Context c, Template t)
          Constructor
 
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.util.Map map)
           
 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
 

Constructor Detail

TemplateTool.MacroTemplate

public TemplateTool.MacroTemplate(Context c,
                                  Template t)
Constructor

Parameters:
c - the current request context
t - 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 request
src - the string for the StringTemplate
Method Detail

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
Throws:
PropertyException

eval

public java.lang.Object eval(java.lang.Object[] args,
                             java.lang.Object[] names)
                      throws PropertyException
Throws:
PropertyException

eval

public java.lang.Object eval(java.util.Map map)
                      throws PropertyException
Throws:
PropertyException

copyCurrentContext

public void copyCurrentContext()
Copies all variables from the current request context into the context of the macro.



Copyright © 1999-2006 WebMacro. All Rights Reserved.