ee.mare.indrek.jtlt.macros
Class MacroAdapter

Object
  extended byee.mare.indrek.jtlt.macros.MacroAdapter
All Implemented Interfaces:
TemplateMacro
Direct Known Subclasses:
AliasMacro, EncloseMacro, IncludeMacro, SepMacro

public class MacroAdapter
extends Object
implements TemplateMacro

Adapter class for easy macro creation. By default it is set to parsetime, non-recursive and will return an empty string, name is specified by the constructor.


Constructor Summary
MacroAdapter(String name)
          Construct a simple macro with given name.
 
Method Summary
 String getName()
          Get the name of the macro.
 boolean isParsetime()
          Returns whether a macro is parsetime or not.
 boolean isRecursive()
          Whether to recursively parse the output of this the macro.
 String process(TemplateParams ctx, String name, String args)
          This method is called with given block context whenever a macro with registered name is found inside the tempalate.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MacroAdapter

public MacroAdapter(String name)
Construct a simple macro with given name.

Method Detail

getName

public String getName()
Description copied from interface: TemplateMacro
Get the name of the macro. Macro is called whenever a name is used inside the template.

Specified by:
getName in interface TemplateMacro

isParsetime

public boolean isParsetime()
Description copied from interface: TemplateMacro
Returns whether a macro is parsetime or not. Being parsetime means here that the macro does not depend on template instance specified parameters and can be resolved at parsing time. But resolving macros only at parsetime is faster than doing it on every created template. Not all instances of macro usage may be parsed at parsetime tho. For example when the result of recursive macro contains it.

Specified by:
isParsetime in interface TemplateMacro

isRecursive

public boolean isRecursive()
Description copied from interface: TemplateMacro
Whether to recursively parse the output of this the macro. If the macro is used at parsetime the result can contain additional sub blocks.

Specified by:
isRecursive in interface TemplateMacro

process

public String process(TemplateParams ctx,
                      String name,
                      String args)
Description copied from interface: TemplateMacro
This method is called with given block context whenever a macro with registered name is found inside the tempalate. The macros are resolved immediately only if they are parsetime, otherwise on every Template.toString the data structures are parsed and macros expanded. If macro is parsetime the ctx is taken from the generator. You can add parameters into the template using the Template.addParam, for parsetime macros you'd have to extend the TemplateGenerator.

Specified by:
process in interface TemplateMacro
Returns:
the string value to be replaced into the template
See Also:
TemplateParams.findParam(java.lang.String, boolean), Template.addParam(java.lang.String, java.lang.Object)