Class MacroTemplate

  • All Implemented Interfaces:
    TemplateInterface

    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,

    isSingleton
    is set to "true" or "false" to indicate the tag has been specified as a singleton.
    args
    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.

    init
    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.
    subst
    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.

    NOTE:
    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.

    Version:
    MacroTemplate.java 2.10
    Author:
    Stephen Uhler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.Properties macroTable  
    • Constructor Summary

      Constructors 
      Constructor Description
      MacroTemplate()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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​(java.lang.String[] args)
      Convert stdin properties format macro definition files to the new template style.
      static java.lang.String snarfTillClose​(LexML lex, java.lang.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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • macroTable

        public java.util.Properties macroTable
    • Constructor Detail

      • MacroTemplate

        public MacroTemplate()
    • Method Detail

      • snarfTillClose

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

        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>
         
        • If "global" is true, then the macro is defined for the entire server, otherwise it is for the session only.
        • if the body of the macro is an empty string, the macro definition is removed
        • Macros defined for the session override the global ones.
        • <definemacro nnn> is a shortcut for <definemacro name=nnn>
      • defaultTag

        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.

      • main

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