Split text
Value resolver – Abstract
Purpose: Splits the text present as input value at each occurrence for the optionally parameterizable Delimiter (string or a Regular expression) and returns the resulting substrings as a list (String[]).
The Split text value resolver splits the text present as input value at each occurrence for the optionally parameterizable Delimiter (string or a Regular expression) and returns the resulting substrings as a list (String[]).
The Delimiter can be defined either by direct input as static text or by value resolvers.
Character (strings) evaluated as a Delimiter do not appear as part of the substring in the return value.
Overall, the following special cases should be noted:
If the input value is 'No value' ($null), the return value is also 'No value' ($null).
If there is an input value that is not a text (String), then the string image of the input value is processed.
The input value is divided after each character if one of the following conditions is met:
'No value' ($null) was specified as the Delimiter.
An empty string ('') was specified as the Delimiter.
The value configuration for the Delimiter parameter returns 'No value' ($null) or an empty string ('') at runtime.
If all characters from the input value are interpreted as a Delimiter, the value resolver returns an empty list ([]) and not a list with two empty strings.
►WARNING◄ If the Regular expression? option is selected, syntax errors may occur when interpreting the regular expression defined in the Delimiter parameter, which are handled as ProcessException by default.
Configuration
The text to be split is expected as input value. If the input value is not text (String), the string image of the input value is used.
Parameter |
Description |
Example |
Separator |
By default, a text field is provided for the Delimiter for direct input of one or more text characters. The example on the right specifies a string of three characters ' - ' (space, minus, space) as the delimiter, which has been selected in the screenshot to highlight the spaces. An input value like 'New York - Rio - Tokyo' is converted by this Delimiter into a list of three substrings ('New York', 'Rio', 'Tokyo'). |
Direct input
|
Clicking on the small gray arrow at the bottom left switches from direct entry to value configuration, so that a value resolver or a chain of value resolvers can be configured to dynamically assign the Delimiter at runtime. In the example on the bottom right, a Value from localization value separator is used that refers to the Bundle lobsterui and the Resource thousandsSeparator. Obviously, the 'thousands separator' defined as localization (in the Localization or Company specific localization) for the Current locale is used as a Delimiter here. An input value like '12.345.678' would be split into three substrings with digit groups ('12', '345', '678') in a session in the Locale 'German' (with default locale). To achieve the same result in a session with the Locale 'English' (with default localization), the input value would have to be '12,345,678'. |
Value configuration: (directly after switching, still without configuration)
Example:
|
|
Regular expression? |
As long as the Regular expression? option is unchecked (default), input or resolved strings for the Delimiter parameter will be interpreted as plain text, as in the examples above. If the Regular expression? option is checked, then input or resolved strings for the Delimiter parameter will be interpreted as a regular expression. If matches are found in the input value for the parameterized expression, the input value is divided at the respective place where it was found. The sections evaluated as Delimiters are not included in the returned substrings. |
Example:
The regular expression [,.'\s] defined by static direct input qualifies a set of separators to act as equal Delimiters. The input values like '12,345,678' and '12,345,678' (see previous example) or also "12 345 678" und "12'345'678" are thereby divided into the always same three groups of digits. ►NOTE◄ Since the \s character class covers all whitespace characters (not just the space character), a line break in the input value, for example, would also act as a Delimiter. |
►NOTE◄ Of course, the string for the Delimiter parameter can also be defined by value configuration (see above) if the Regular expression? option is checked. Therefore, the regular expression can be defined dynamically at runtime (via value resolvers). |
Examples
Simple use case: 'Parse' list entries from comma-separated text
A comma-separated list of abbreviations for currencies should be able to be entered in a text field of an entity in order to list currencies that are 'accepted' in the context of the business process concerned.
For example, an entry like 'JPY,USD,EUR' should signal that Japanese Yen, US Dollar and Euro are 'acceptable'.
In the context of an event handling, the entered text is 'resolved' into a real list of single values, e.g. so that current exchange rates can be retrieved via a profile in the context of a loop.
In the Resolver for entities parameter of the Für jeden Eintrag wiederholen (Schleife) shown on the right, the Split text value resolver is used to split the text that is to be directly available here as an input value for the loop and therefore also the value resolver.
In the action block, over which the loop iterates, a profile is called up that is supposed to call up the current exchange rate for the respective currency (e.g. via web service). For this purpose, the text key for the currency in question is required as a parameter. The further processing of the exchange rate data should not play a role here. Runtime example: An input value such as 'PY,USD,EUR' triggers an iteration over the listed individual values and thus three profile calls with changing text parameters ('JPY', 'USD', 'EUR'). ►NOTE◄ The Split text value resolver does not automatically 'trim' the substrings, so an input value like 'JPY, USD, EUR' (with space after the comma) could lead to difficulties unless the Trim value resolver is used in the profile call for the parameter. |
|
The variant shown on the right uses the Regular expression? option and the regular expression ',\s*' to define the Delimiter in such a way that all whitespace characters (spaces, line breaks) directly following the comma are interpreted (and therefore 'eliminated' or 'skipped') as part of the separator. Runtime example: An input value like 'JPY,USD,EUR,CHF' returns the text keys 'JPY', 'USD', 'EUR' and 'CHF' in the iteration without unnecessary spaces. ►NOTE◄ Spaces at the beginning and at the end of the comma-separated list are not eliminated by this procedure! |
|
More complex use case: 'Resolve' components of a phone number
The structure of a phone number in a text field is expected in the format <country code> (<area code>) <connection>[-<extension>].
In addition to digits, the individual components (<...>) of the phone number should also be allowed to contain spaces and, with regard to the country code, the plus sign (+).
In the context of event handling, these components are split and assigned to specific variables (countryCode, areaCode, line, extension).
The phone number to be split is passed as input value to the Für jeden Eintrag wiederholen (Schleife) shown on the right. For access within the loop it is stored in the phoneNumber variable.
►NOTE◄ Splitting the components works properly only under the assumption that the string in the phoneNumber variable does not 'skip' any component in the schema and only the extension at the end is optional specification. ►NOTE◄ Considering performance, the Split text value resolver should be placed before the loop to write the list of components into a variable. Then the splitting does not have to be repeated with each iteration. With consideration for the clearer representation (right) here it was renounced. |
|
Runtime example: The following component variables are set with the input value '+49 (89) 12 52 - 3210':
Variable |
Value |
countryCode |
+49 |
areaCode |
89 |
line |
12 52 |
extension |
3210 |
Special use case: Process components from the string image of an entity
If there is no text as input value for the Split text value resolver, the string image of the input value is processed as the text to be split.
A string with the following structure is output for an entity:
<id>:<entityClass>@<objectId>
Runtime example: (String image for a user account with ID 1901)
1901:de.lobster.scm.base.security.user.User@510285c7
To identify an entity in a way that is readable by a user, e.g. in a notification, the ID of the entity (<id>) and the class (<entityClass>) or the localization for the class name are usually used. The ID of the Java object (@<objectId>), on the other hand, usually plays no role.
The following example shows how the components of an entity's string image can be obtained and used to identify the entity (in this case, the User of session) in a notification.
The Ausführen mit event action shown already defines, via the Object resolver parameter as a reference object, the list of substrings obtained from the string image for the entity returned by the User of session:
Runtime examples:
►NOTE◄ Of course, the type of account returned by the User of session interface could also be determined via the variable entityClass, which the system automatically fills depending on the reference object. |
|