Expression Language Script

Expression Language (EL) is a simple non-procedural scripting language that can be used to evaluate dynamic expressions within Ooyala Flex. This language is used for creating more dynamic configurations. 

In this section we provide an overview of where and how you can use Expression Language and the objects available.

Scripting Context

Any script that you develop has a context where environmental variables are stored. The following objects are available within the context of expression language scripts.

  • asset: Available in the context of plugins that access and manage assets.
  • 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.
  • actionType: Available in the context of plugins that use action types.
  • action: Available in the context of plugins  that use  Ooyala Flex action configs.
  • configs: A list of relevant  Ooyala Flex action configs .
  • workflowContext: Available to plugins that run inside workflows.
  • document: Represents an arbitrary XML document that has been inserted into the context.
  • util: Provides access to common utility methods such as time calculations.

Note: Other variables may be available as some plugins insert variables into a workflow context depending on the outcome 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. This variable can then be referenced from other Jjbs in the same workflow context.

Below we provide some examples of what scripting looks like inside configuration fields:

Scripting Basics

Using Expressions

EL expressions can be used:

  • In static text
  • In any field in Ooyala Flex that is marked as supporting scripting

The value of an expression in static text is computed and inserted into the output. 

There are three ways to set a value:

1) With a single expression construct:

${expr}

The expression is evaluated and the result is coerced to the expected output type.

2) 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.

3) 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, a 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

Ooyala 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:

Table 1.
  asset event job user actionType action configs workflowContext
Actions
Timed Actions
Event Handlers
Event Handler Expression Filter
Validation Profile (within Validation Action)
Transcode Profile
Task Assignment
Email Templates
Action Run Rules
Asset Run Rules
SMS URL Property

Using Variables

Ooyala Flex evaluates a variable that appears in an expression by looking up its value in the context. For example, when evaluating the expression ${asset}, Ooyala Flex will look for object of name "asset" in the context scope and will return its value. If "asset" 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:

expr-a.identifier-b

is equivalent to

expr-a["identifier-b"];

that is, the expression expr-b is used to construct a literal whose value is the identifier, and then the [] operator is used with that value.

To evaluate

expr-a[expr-b]

evaluate expr-a into value-a and evaluate expr-b into value-b. If either value-a or value-b is null, return null.

  • 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 int 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 JavaBeans 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:

  • Boolean: true and false
  • Integer: as in Java
  • Floating point: as in Java
  • String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
  • Null: null

Operators

In addition to the . and [] operators discussed in variables, EL provides the following operators:

  • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
  • 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

Table 2.
 {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

Advanced Scripting

As well as standard Expression Language, Ooyala Flex also offers some advanced features for the creation of more advanced evaluation.

Metadata Expressions

Ooyala Flex supports some operators that assist with locating metadata field values within asset hierarchies.

Table 3.
Expression Explanation
@@fieldname@@ Expression starts with @@ and ends with @@. Using this expression we can access metadata variable values. e.g. @@film_id@@ - returns value of film_id variable from metadata associated with current asset.
%%assetContext%% Metadata Expressions also support embedded asset hierarchy expressions. These start with %% and ends with %%. If we want to retrieve values from parent or child metadata then we can also specify the asset hierarchy expressions e.g. @@%%./..%%artist[0]:first_name[0]@@ - evaluates metadata expression "artist[0]:first_name[0]" against metadata of parent.

System Properties

Table 4.
Expression Explanation
@[propertyName] System properties are variables that are available in the Ooyala Flex system. Super users can create their own system properties, that can be accessed through scripting. System Properties support scoping.

Was this article helpful?