Class MiscTemplate

  • All Implemented Interfaces:
    TemplateInterface

    public class MiscTemplate
    extends Template
    Template for misc string manipulation functions.
    <append name="..." value="..." [delim=".." namespace="..."]>
    Append a value to an existing variable, using an (optional) delimiter to separate values.
    <push name="..." value="..." namespace="...">
    Push a variable value on a stack, and replace the value with a new one.
    <pop name="..." namespace="...">
    Pop a previously pushed value from the stack.
    <increment name="..." [incr=n namespace="..."]>
    Increment the value of a variable.
    <sequence [name=".."] count=".." [start=".." incr=".." delim=".."]>
    Generate a sequence of values.
    <expr value="..." [name="..." namespace="..." format="..."]>
    Do an arithmetic expression evaluation on "value".
    <inline name="..." [eval="true|false]> ... </inline>
    Place all the text between the "inline" and "/inline" tags into the variable indicated by "name".
    <eval markup="..." [atEnd=true|false]>
    Evaluate a variable as if the value was in-line markup. If "atEnd" is specified, the markup is interpolated at the end of the file.
    <stringop name="..." [newname="..." range="start,end" trim="left|right|both" case="upper|lower|title" convert="url|html">
    Perform misc. string functions on the value of a named variable.
    <mapnames src=src_pattern dst=dst_pattern [namespace=dest_namespace] [range="start,end", trim="left,right", case="upper|lower|title" convert=url|html]>
    Map a set of variables from one namespace to another, and optionally change the names and process the values. The "src" parameter is a glob pattern that is expected to match the names of one of more properties. The "dst" parameter (which defaults to the name actually matched) is the new name of the variable that is copied into the specified "namespace" (which defaults to "local"). ${...} substitutions are performed on the value of "dst" separately for each matched variable. The variables ${1}, ${2} ... ${i} ... ${9} take on the value of the "i"th wildcard match, as in Glob.match(). ${0} refers to the actual name of the matched variable, and ${mapCount} is the index of the current variable being mapped, starting with "1".

    If "remove" is specified, then the source variables are removed. If

    All the conversion options provided by <stringop> are also available.

    Example:

     <mapnames src=query.pref_* dst="pref_${1}" namepace=${SessionID}.pref>
     
    Will take the query parameters from the current form that refer to user preferences, and save them in a preferences namespace associated with the current session.
    <stringlength name="xxx" value="${...}">
    Compute the length of the string specified in "value" and place it in the property "name".
    <random name=xxx [count=xxx start=xxx type=int|hex|alpha>
    Generate a random value. if "type=int", the default, then count (defaults to 2) specifies the range of integers from which the value is taken, and "start" (defaults to 1) specifies the minimum value.

    When "type=hex", then "start" is taken to be a hex value (or 0 if start is not a valid hex value).

    When "type=alpha", the "start" must contain only a-z, and the result is the alpabetic result, in radix 26.

    • Constructor Detail

      • MiscTemplate

        public MiscTemplate()
    • Method Detail

      • tag_append

        public void tag_append​(RewriteContext hr)
        Append a value to a property, with an optional delimeter. <append name="..." value="..." [delim="..." namespace="..."]> If "name" is undefined or empty, it is set to "value". The result is placed in the local namespace, unless the "namespace" is used to override it. Use namespace=${SessionID} to put the result into the current session. Use the ListTemplate for more generic list manipulation.
      • tag_increment

        public void tag_increment​(RewriteContext hr)
        Increment the value of a variable. <incr name=variable [incr=n namespace="..."]> -If undefined or empty, assume it was '0'.
        -If the value was non numeric, append or modify any numeric suffix.
        The result is placed in the local namespace, unless the "namespace" is used to override it. Use namespace=${SessionID} to put the result into the current session.
      • tag_sequence

        public void tag_sequence​(RewriteContext hr)
        Generate a (mostly) numeric sequence. <sequence name="..." count="..." [start="..." incr="..." delim=".."]>
        name
        Where to put the result. Defaults to the local namespace, but may be overridden with "namespace=".
        count
        the number of values to generate
        start
        The start value. Defaults to "1". If non numeric, any trailing digits are incremented, if present, or appended otherwise.
        The increment value. Defaults to "1" if the value is not an integer.
        start
        The starting value
        delim
        The delimiter between values. defaults to " ".
      • tag_expr

        public void tag_expr​(RewriteContext hr)
        Set a variable to the result of an arithmetic expression <expr [name=nnn] value="expr" [format="..." ] [namespace="..."]> sets name to "NaN" if the expression was invalid. The result is placed in the local namespace, unless the "namespace" is used to override it. Use namespace=${SessionID} to put the result into the current session.

        If "name" is omitted, the result is placed in the document. If "format" is used, it is java.text.DecimalFormat format specifier. Briefly:

        $
        currency
        %
        percent
        .
        decimal point
        ,
        group separator, as in: 1,000
        #
        a digit, if required, blank otherwise
        0
        a digit, if required, 0 otherwise.
        Example: format="$#,##0.00" would be typical for expressing monetary values.
      • tag_eval

        public void tag_eval​(RewriteContext hr)
        Evaluate the contents of a variable as a template, as if it was "inline" here. <eval markup="..." [atEnd=true|false]>
      • tag_push

        public void tag_push​(RewriteContext hr)
        Treat a variable as a stack, and push a value onto it. <push name="..." value="..." [clear=true|false namespace="..."]> For more generic list manipulation, use the ListTemplate.

        The result is placed in the local namespace, unless the "namespace" is used to override it. Use namespace=${SessionID} to put the result into the current session.

      • tag_pop

        public void tag_pop​(RewriteContext hr)
        Treat a variable as a stack, and pop a value from it. <pop name="..." [clear=true|false namespace="..."]> The result is placed in the local namespace, unless the "namespace" is used to override it. Use namespace=${SessionID} to put the result into the current session.
      • tag_inline

        public void tag_inline​(RewriteContext hr)
        Set a variable to all the markup 'till the /inline tag. <inline name="..." [eval=true|false] [append=true|false]> ... </inline>

        If "eval" is true, then ${..} substitutions are performed before assigning the markup the the named variable. If "esc" is also true, the \X sequences will be replaced as well. If "append" is true and "name" is specified, then the markup is appended to the current contents of "name". If no "name" is specified, the markup is output as-is, after ${..} substitutions (e.g. eval=true is implied).

      • tag_stringop

        public void tag_stringop​(RewriteContext hr)
        String manipulation functions. Any of the following options are supported. If more than one of "range", "trim", "case", or "convert" is specified, they are performed in the order listed below. The value named by the "name" attribute is modified, and the result is placed in the local namespace, using the same name, unless "newname" is specified, in which case "newname" is used instead.

        The "namespace" attribute can be used to alter the namespace to put the result into, in which case the "sessionTable" configuration parameter can be used to alter the namespace class, which defaults to the template handler's (or filter's) prefix.

        <stringop name=xxx range=x,y [newname=xxx namespace=xxx]>
        <stringop name=xxx range=x [newname=xxx namespace=xxx]>
        Do a substring from character position 'x' (starting at 0) up to but not including character position 'y'. Negative values count from the end of the string. If no "y" is specified, then the end of the string is assumed.
        <stringop name=xxx trim=left|right|both [newname=xxx namespace=xxx]>
        Trim whitespace from the string. "trim=true" is equivalent to "both".
        <stringop name=xxx case=lower|upper|title [newname=xxx namespace=xxx]>
        Do case conversions. "title" causes the entire string to be lower cased, except for the first character after any whitespace, which is upper-cased.
        <stringop name=xxx convert=html|url [newname=xxx namspace=xxx]>
        The string is converted exactly the same as the "convert" option of the "get" tag in the SetTemplate().
      • tag_stringlength

        public void tag_stringlength​(RewriteContext hr)
        Compute string length from "value" , return in "name"
      • tag_mapnames

        public void tag_mapnames​(RewriteContext hr)
        Map a set of properties from one namespace to another, and (optionally) change their names and values. <mapnames src=glob-pattern namespace=dst_space dst=dst-pattern [stringops options] [remove=true|false]>
      • toAlpha

        public static java.lang.String toAlpha​(int i)
      • fromAlpha

        public static int fromAlpha​(java.lang.String s)
        Convert an alpha-only string to an integer. no error checking!