Class EmbeddedScriptEvaluation

java.lang.Object
org.frankframework.extentions.script.EmbeddedScriptEvaluation
All Implemented Interfaces:
AdditionalStringResolver

public class EmbeddedScriptEvaluation extends Object implements 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: You should not use the package names when using these classes, just the class name and the method name. See the examples above.
See Also:
  • 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 interface AdditionalStringResolver
      Parameters:
      key - Key to look up
      props1 - First property map in which to look up values
      props2 - Second property map in which to look up values
      propsToHide - List of properties to hide. If null, then no hiding of properties should be done. If not null, 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 caller
      delimStop - End delimiter, normally only needed by caller
      resolveWithPropertyName - 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. If Optional.empty() is returned, the StringResolver will then continue to try resolving the key. If any non-empty Optional is returned, the StringResolver will use the value of that as value for the key and not look for other resolutions for the key.