Class MacroTemplate

  extended by sunlabs.brazil.template.Template
      extended by sunlabs.brazil.template.MacroTemplate (view source)
All Implemented Interfaces:

public class MacroTemplate
extends Template

Template class for defining macros. Macros are defined by:

 <definemacro name=macro-name [global=true|false]> .... </definemacro>
The text (.....) has any leading and trailing whitespace removed.

To expand a macro: <macro-name name1=value1 ...>. All ${...} constructs in The previously saved macro body are processed, and the result replaces the macro-name tag. Attributes provided in the macro name override any variables that exist in the request properties.

Several special variables are supplied, as if they were specified as attributes, but only if otherwise not already defined either as an attribute or as a property,

is set to "true" or "false" to indicate the tag has been specified as a singleton.
is the string of un-parsed arguments to this macro.

Templates are processed by reading the input "document" a tag at a time to generate the output document. By default, the macro body is pushed onto the not-yet-processed input stream; any tags contained in the macro body will be processed. If the defer attribute is present, the macro body is placed onto the output stream instead. This is more efficient, but requires an additional filter pass if the body of the macro contains tags that need to be processed in the current context.

The name of the file (or resource) to read a default set of macro definitions from. If an absolute path isn't specified, the file is taken relative to the document root. The default macros are kept in the SessionManager on a per-server basis. All macros defined in the "init" file are global. All markup in this file outside of a macro definition is ignored. If "subst" is present as an attribute of a macro definition in this file, then all ${...} are evaluated relative to "server.props" before the macro is defined.
If specified, then any tags that are not processed by any templates will have all ${..} contructs in attribute values substituted. This subsumes the function of the "SubstAllTemplate".

This is an experiment. The current implementation is flawed, although it is less flawed than the previous one.

The init files in previous releases used java properties format files to define macros; This version uses xml templates. See "main" below for a utility to convert the old properties format files to the new format.

Field Summary
 Properties macroTable
Fields inherited from class sunlabs.brazil.template.Template
Constructor Summary
Method Summary
 void defaultTag(RewriteContext hr)
          Run the macro, push formal parameters on the stack first.
 boolean init(RewriteContext hr)
          Read in the inital macros, if needed.
static void main(String[] args)
          Convert stdin properties format macro definition files to the new template style.
static String snarfTillClose(LexML lex, String tag)
          Grab all the markup starting from the current tag until the matching closing tag, and return as a string.
 void tag_definemacro(RewriteContext hr)
          Define a new macro.
Methods inherited from class sunlabs.brazil.template.Template
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public Properties macroTable
Constructor Detail


public MacroTemplate()
Method Detail


public boolean init(RewriteContext hr)
Read in the inital macros, if needed.

Specified by:
init in interface TemplateInterface
init in class Template


public static String snarfTillClose(LexML lex,
                                    String tag)
Grab all the markup starting from the current tag until the matching closing tag, and return as a string.


public void tag_definemacro(RewriteContext hr)
Define a new macro. use "name" as the macro name. Once defined, the tag <name ...> will be replaced by the contents of the macro named "name".
 <definemacro name=nnn [global=true|false]>...</definemacro>


public void defaultTag(RewriteContext hr)
Run the macro, push formal parameters on the stack first. This examimes all non-processed tags to see if they are macros, and processes those that are.

If the parameter defer=true is present, the text of the macro is output directly, with only ${..} substitutions performed. Otherwise, the markup in the macro body is rescanned and processed.


public static void main(String[] args)
                 throws IOException
Convert stdin properties format macro definition files to the new template style. Use this to update to the new initial macro template format.


Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.