TemplateParserUnit
Group |
|
Class Name |
com.ebd.hub.datawizard.iu.TemplateParserUnit |
Function |
This Integration Unit is used to create a text file by using a template file. |
Description
Introduction: Integration Units.
The TemplateParserUnit is used to create a text file by using a template file. The template file uses tags, which are filled by the unit. The text parser saves field values in a map, using the field names as keys. The tag names are then used to retrieve the value for a tag. If the unit cannot find a value for a tag, it will be filled with an empty string. The output encoding is always 8859_1.
Parameter Description
Parameter Name |
Allowed Values |
Default Value |
Description |
create CDDATA for xml |
|
false |
If true, the replacement text will be surrounded by an XML CDATA block. |
start tag |
|
{-- |
The start tag. Default is {. |
end tag |
|
--} |
The end tag. Default is }. |
template-file |
|
|
Path to the template file. |
Use format-field |
|
false |
If true, replacement values are formatted with the specified field template. |
template file encoding |
|
8859_1 |
The encoding used to read the template. |
Structure of a Template
A template is a regular text document containing tags (and loop tags, check block tags) that are replaced with field values during parsing. The description assumes { to be the start tag and } to be the end tag.
Structure of Tags
{--tagname[:index1[|index2][:formatString]]--}
tagname |
The tag name (used as key in the field map). |
index1 |
If the represented value is a one-dimensional array, index1 is literally used as the index of that array (index starts at 0), if it is a number. If it is a string, a loop with that name will be searched for and its value will be used as the index. If the parameter is left empty, the first value of the array will be used. |
index2 |
If the represented value is a one-dimensional array, index1 is literally used as the index of that array (index starts at 0), if it is a number. If it is a string, a loop with that name will be searched for and its value will be used as the index. If the parameter is left empty, the first value of the array will be used. |
formatString |
Specifies a certain format. Note: This feature is recognised by the text parser, but not supported yet. |
Examples for Various Tags
{--key--} |
Tag with the name key. If the name corresponds to an array, the tag will be replaced with the first element of a one-dimensional array or the first element of the first row of a two-dimensional array. |
{--key1DArray:1--} |
Tag with the name key1DArray. If the name corresponds to an array, the tag will be replaced with the second element of a one-dimensional array or the first element of the second row of a two-dimensional array. If the value does not correspond to an array, the index will be ignored. |
{--key2DArray:1|2--} |
Tag with the name key2DArray. If the name corresponds to an array, the tag will be replaced with the second element of a one-dimensional array (the second index will be ignored), or the third element of the second row of a two-dimensional array. If the value does not correspond to an array, the indexes will be ignored. |
{--key::%d{LOCALE}--} |
Tag with the name key that is replaced with the corresponding value and formatted as date with the current (or specific) locale (not supported with version 1.0 of the text parser). |
{--key:loop--} |
Tag with the name key. If key is an array, the index of the element to replace the tag is given by the current value of the loop counter for loop loop. |
{--key:loop1|loop2--} |
Tag with the name key. If key is a two-dimensional array, the row index of the element to replace the tag is given by the current value of the loop counter for loop loop1 and the column index by the current value of the loop counter for loop loop2. |
{--key:0|loop1--} |
The mixture of static values and references is allowed. Additionally, the keywords FIRST and LAST can be used to reference the first, or last element of an array, which can be useful if the size of an array is unknown. |
Loops
For a data sequence (e.g. measurement results) it might be necessary to use a loop. The structure of a loop tag is as follows.
{--LOOP|loopname:start|{reference|index}:end|{reference|index}:step--}
loopname |
Name of the loop. |
start |
Start value of the loop counter (usually 0). |
end |
Value at which the loop is terminated. |
step |
Step size of the loop counter. |
reference |
An array can be used to define the loop length. For one-dimensional arrays, the loop length is defined by the number of rows in the array. For two-dimensional arrays, index can be used to define the row number, of which the number of columns will be used for the loop length. |
Check Blocks
In order to build texts dependent on the existence or non-existence of a value, it is possible to define check blocks. The structure of a check block is as follows.
{--CHECK|blockname:checktyp|reference--}
...
...
{/--CHECK|blockname--}
blockname |
Name of the check block. |
checktyp |
The check type. exist checks, if the specified value key exists and has a value. nonexist checks, if the specified value key does not exist, or has no value. If the check result is true, the text block is inserted. |
reference |
The value key to be checked. |
Examples for Templates
An example of a template that can be used for the creation of bulk letters.
MyCompany Ltd
49 Featherstone Street
LONDON
EC1Y 8SY
{--name--}
{--cofield--}
{--street--}
{--countrycode--}-{--zip--} {--city--}
Dear {--mrextension--} {--mrormrs--} {--surname--}
...
With kind regards
Walter Brown
Marketing
A template that builds a measurement results table, if time and value exist in a two-dimensional array.
Results for {--date--}
Time Value
{--LOOP|loop:0:{value}:1--}{--time:loop--} {--value:loop--}
{--/LOOP|loop--}
An example for the use of check blocks. If there are results, you will get the same output as for the previous example. If there are no results (time is not defined, or there is no first value for it), the following result will be shown: No results table exists.
{--CHECK|check1:exist|time--}Results for {--date--}
Time Value
{--LOOP|loop:0:{value}:1--}{--time:loop--} {--value:loop--}
{--/LOOP|loop--}{--/CHECK|check1--}
{--CHECK|check1:nonexist|time--}No results table exists
{--/CHECK|check1--}