The Expression Language (EL) is a simple non-procedural scripting language that can be used to evaluate dynamic expressions within Dalet Flex. This language is used for creating more dynamic configurations.
The Scripting Context
Any script that you develop has a context where variables may be stored. The following objects are available within the context of expression language scripts.
Context | Description |
asset | Available in the context of plugins that access and manage assets. |
actionType | Available in the context of plugins that use action types. |
action | Available in the context of plugins that use Dalet Flex action configs. |
configs | A list of relevant Dalet Flex action configs. |
document | Represents an arbitrary XML document that has been inserted into the context. |
event | Available in the context of events. |
job | Available in the context of plugins that are run inside jobs. |
user | Available in the context of plugins that access and manage users. |
util | Provides access to common utility methods such as time calculations. |
workflowContext | Available to plugins that run inside workflows. |
Note: Other variables may be available in the workflow context. The are inserted by plugins as a result of their execution. A good example is the HTTP Request Message plugin that inserts an httpResponse variable into the workflow context once a message has been sent. These variable can then be referenced by other jobs in the same workflow context.
Below we provide some examples of what scripting looks like inside configuration fields:
Using Expressions
EL expressions can be used in static text fields or any field in Dalet Flex that is marked as supporting scripting.
At runtime the value of the expression is evaluated and set as the value of the field.
There are three ways to set a value:
- With a single expression construct - ${expr}. The expression is evaluated and the result is coerced to the expected output type.
- With one or more expressions separated or surrounded by text - some${expr}${expr}text${expr}. The expressions are evaluated from left to right. Each expression is coerced to a string and then concatenated with any intervening text. The resulting string is then coerced to the expected output type.
- With text only - sometext. In this case, the string value is coerced to the expected output type.
Expressions used to set configuration values are evaluated in the context of an expected type. If the result of the expression evaluation does not match the expected type exactly, type conversion will be performed. For example, the expression ${1.2E4} provided as the value of a type float will result in the following conversion Float.valueOf("1.2E4").floatValue().
Implicit Objects
Dalet Flex defines a set of implicit objects. These objects exist within the scope of the expression that is being evaluated. Please note that not all objects are available in all contexts. A table showing which objects are available in each script-enabled plugin is shown in the table below:
asset | event | job | user | actionType | action | configs | workflowContext | |
Actions | ||||||||
Timed Actions | ||||||||
Event Handlers | ||||||||
Event Handler Expression Filter | ||||||||
Validation Profile | ||||||||
Transcode Profile | ||||||||
Task Assignment | ||||||||
Email Templates | ||||||||
Action Run Rules | ||||||||
Asset Run Rules | ||||||||
SMS URL Property |
Using Variables
Dalet Flex evaluates a variable that appears in an expression by looking up its value in the context. For example, when evaluating the expression ${asset}, Dalet Flex will look for object of name "asset" in the context scope and return its value. If the object is not found, null is returned. A variable that matches one of the implicit objects described in implicit objects will return that implicit object instead of the variable's value.
Properties of variables are accessed using the . operator and can be nested arbitrarily.
The expression language unifies the treatment of the . and [] operators: object-a.property-b is equivalent to object-a["property-b"] that is, the expression property-b is used to construct a literal whose value is the identifier, and the [] operator is used with that value.
To evaluate object-a["property-b"] evaluate object-a into value-a and evaluate property-b into value-b.
If either value-a or value-b is null, return null otherwise return the value.
- If value-a is a map, return value-a.get(value-b). If !value-a.containsKey(value-b), then return null.
- If value-a is a list or array, coerce value-b to an integer and return value-a.get(value-b) or array.get(value-a, value-b), as appropriate. If the coercion couldn't be performed, an error is returned.
- If the get call returns an IndexOutOfBoundsException, null is returned. If the get call returns another exception, an error is returned.
- If value-a is a JavaBean object, coerce value-b to string. If value-b is a readable property of value-a, then return the result of a get call. If the get method throws an exception, an error is returned.
Literals
EL defines the following literals.
Type | Description |
Boolean | true and false |
Integer | as in Java |
Float | as in Java |
String | with single and double quotes " is escaped as \", ' is escaped as \', and \ is escaped as \\. |
Null | a null value |
Operators
In addition to the . and [] operators discussed in variables, EL provides the following operators.
Type | Operator |
Arithmetic | +, -, *, / and div, % and mod, - |
Logical | and, &&, or, ;, not, ! |
Relational | ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals. |
Empty | The empty operator is a prefix operation that can be used to determine whether a value is null or empty. |
Conditional | A ? B : C. Evaluate B or C, depending on the result of the evaluation of A. |
The precedence of operators highest to lowest, left to right is as follows:
[]
.
()
- Used to change the precedence of operators -
(unary) not
!
empty
*
/
div
%
mod
+
-
(binary) <
>
<=
>=
lt
gt
le
ge
==
!=
eq
ne
&&
and
||
or
?
:
The following words are reserved for expression language and should not be used as identifiers:
and, eq, gt, true, instanceof, or, ne, le, false, empty, not, lt, ge, null, div, mod
Note: Many of these words are not in the language now, but they may be in the future, so you should avoid using them.
Examples
Expression | Result |
{1 > (4/2)} | FALSE |
${4.0 >= 3} | TRUE |
${100.0 == 100} | TRUE |
${(10*10) ne 100} | FALSE |
${'a' < 'b'} | TRUE |
${'hip' gt 'hit'} | FALSE |
${4 > 3} | TRUE |
${1.2E4 + 1.4} | 12001.4 |
${3 div 4} | 0.75 |
${10 mod 4} | 2 |
Comments
0 comments
Please sign in to leave a comment.