Class MiscTemplate
- All Implemented Interfaces:
TemplateInterface
- <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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Special version of a properties that uses the sub expresions of the supplied glob pattern and name to define the keys 1-9. -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
Convert an alpha-only string to an integer.boolean
init
(RewriteContext hr) Called before this template processes any tags.void
Append a value to a property, with an optional delimeter.void
Evaluate the contents of a variable as a template, as if it was "inline" here.void
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.void
Increment the value of a variable.void
Set a variable to all the markup 'till the /inline tag.void
Map a set of properties from one namespace to another, and (optionally) change their names and values.void
Treat a variable as a stack, and pop a value from it.void
Treat a variable as a stack, and push a value onto it.void
void
Generate a (mostly) numeric sequence.void
Compute string length from "value" , return in "name"void
String manipulation functions.static String
toAlpha
(int i)
-
Constructor Details
-
MiscTemplate
public MiscTemplate()
-
-
Method Details
-
tag_append
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
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
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
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.
- 0
format="$#,##0.00"
would be typical for expressing monetary values. -
tag_eval
Evaluate the contents of a variable as a template, as if it was "inline" here. <eval markup="..." [atEnd=true|false]> -
init
Description copied from class:Template
Called before this template processes any tags.- Specified by:
init
in interfaceTemplateInterface
- Overrides:
init
in classTemplate
-
tag_push
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
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
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
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]>
- <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().
- <stringop name=xxx range=x,y
[newname=xxx namespace=xxx]>
-
tag_stringlength
Compute string length from "value" , return in "name" -
tag_mapnames
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]> -
tag_random
-
toAlpha
-
fromAlpha
Convert an alpha-only string to an integer. no error checking!
-