Class EmbeddedScriptEvaluation
java.lang.Object
org.frankframework.extentions.script.EmbeddedScriptEvaluation
- All Implemented Interfaces:
AdditionalStringResolver
Evaluate a JEXL expression embedded in a string substitution performed by
StringResolver
.
For a string substitution to be evaluated as expression, it has to be prefixed with a "=" inside
the string substitution delimiters, so by default this would be ${=...}
.
Inside the expression you can reference other properties from the source maps, either as nested string substitutions or as direct references. Since Java properties are loaded as string values, numerical or boolean values would be strings if referenced directly and this can have confusing effects when using them in calculations or boolean evaluations.
Some examples
my.custom.value=Hello!
padding.size=5
total.length=${=my.custom.value.length() + ${padding.size}}
The result of evaluating total.length
would be 11. The padding size is used here as an embedded string
substitution, which is evaluated before the expression is evaluated. As you can see, it is possible to use regular Java string
functions inside the expressions.
value1=5
value2=10
sum=${=value1 + value2}
Because direct references are strings when loaded as Java properties, the result of this expression is the string-concatenations 510 instead of the sum 15.
To get the correct outcome, you can write either:
value1=5
value2=10
sum=${=Integer.parseInt(value1) + Integer.parseInt(value2)}
Or, perhaps easier:
value1=5
value2=10
sum=${=${value1} + ${value2}}
Here is an example with a conditional evaluation giving a warning:
remote.host=
remote.port=
remote.url=${= if (StringUtils.isBlank(remote.host) || StringUtils.isBlank(remote.port) { ApplicationWarnings.add(log, "properties remote.host and remote.port should be set"} else { return "http://$s:$s/api/".formatted(remote.host, remote.port); }}
Available Classes
The following classes are available in the evaluation context so that static methods of these classes can be used in expressions:String
Boolean
Integer
Long
Double
Math
Arrays
Collections
Collectors
Strings
StringUtils
StringUtil
Misc
ApplicationWarnings
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
EmbeddedScriptEvaluation
public EmbeddedScriptEvaluation()
-
-
Method Details
-
resolve
public Optional<String> resolve(String key, Map<?, ?> props1, Map<?, ?> props2, Set<String> propsToHide, String delimStart, String delimStop, boolean resolveWithPropertyName) Description copied from interface:AdditionalStringResolver
Method to implement string resolution.Parameters are mostly as from
StringResolver.substVars(String, Map, Map, Set, String, String, boolean)
, except the first parameter,key
, which is the key to be resolved instead of the full string in which to substitute.- Specified by:
resolve
in interfaceAdditionalStringResolver
- Parameters:
key
- Key to look upprops1
- First property map in which to look up valuesprops2
- Second property map in which to look up valuespropsToHide
- List of properties to hide. Ifnull
, then no hiding of properties should be done. If notnull
, any properties whose name is in the collection will be hidden by the caller but the implementation may make its own decision on hiding property values. For instance, hiding credentials.delimStart
- Start delimiter, normally only needed by callerdelimStop
- End delimiter, normally only needed by callerresolveWithPropertyName
- Flag if values should be prefixed with name of resolved property, normally only needed by caller.- Returns:
- Resolved property value, or
Optional.empty()
if it cannot be resolved by this implementation. IfOptional.empty()
is returned, theStringResolver
will then continue to try resolving thekey
. If any non-emptyOptional
is returned, theStringResolver
will use the value of that as value for thekey
and not look for other resolutions for the key.
-