About Us Home Contributors License Components Sandbox Commons Jexl Overview API Documentation Examples Release Builds Nightly Builds Reference JEXL Wiki Project Documentation About Commons JEXL Downloads Project Info Project Reports Development Process General Information Charter Volunteering Contributing Patches Releasing Components Jakarta Community Get Involved Mailing Lists Access CVS Repositories Commons Resources (Unofficial) Wiki Japanese Translation Korean Translation Related Apache Commons DB Commons XML Commons | ### Overview This reference is split up into the following sections: Language Elements Literals Functions Operators For more technical information about the JEXL Grammar, you can find the JavaCC grammar for JEXL here: Parser.jj ### Language Elements
Item | Description
--- | ---
Comments | Specified using `##` and extend to the end of line, e.g.
    ## This is a comment
Identifiers / variables | Must start with `a-z`, `A-Z`, `_` or `$`. Can then be followed by `0-9`, `a-z`, `A-Z`, `_` or `$`. e.g. Valid: `var1`,`_a99`,`$1` Invalid: `9v`,`!a99`,`1$` JEXL also supports `ant-style` variables, e.g.
    my.dotted.var
is a valid variable name. NOTE: JEXL does not support variables with hyphens in them, e.g.
    commons-logging
is not a valid variable, but instead is treated as a subtraction of the variable `logging` from the variable `commons`
Scripts | A script in Jexl is made up of zero or more statements.
Statements | A statement can be the empty statement, the semicolon (`;`) , block, assignment or an expression. Statements are optionally terminated with a semicolon.
Block | A block is simply multiple statements inside curly braces (`{, }`).
### Literals
Item | Description
--- | ---
Integer Literals | 1 or more digits from `0` to `9`
Floating point Literals | 1 or more digits from `0` to `9`, followed by a decimal point and then one or more digits from `0` to `9`.
String literals | Can start and end with either `'` or `"`, e.g.
    "Hello world"
and
    'Hello world'
are equivalent.
Boolean literals | The literals `true` and `false` can be used, e.g.
    val1 == true
Null literal | The null value is represented as in java using the literal `null`, e.g.
    val1 == null
### Functions
Function | Description
--- | ---
empty | Returns true if the expression following is either: `null` An empty string An array of length zero A collection of size zero An empty map
    empty(var1)
size | Returns the information about the expression: Length of an array Size of a List Size of a Map Size of a Set Length of a string
    size("Hello")
returns 5.
### Operators
Operator | Description
--- | ---
Boolean `and` | The usual `&&` operator can be used as well as the word `and`, e.g.
    cond1 and cond2
and
    cond1 && cond2
are equivalent
Boolean `or` | The usual `||` operator can be used as well as the word `or`, e.g.
    cond1 or cond2
and
    cond1 || cond2
are equivalent
Boolean `not` | The usual `!` operator can be used as well as the word `not`, e.g.
    !cond1
and
    not cond1
are equivalent
Equality | The usual `==` operator can be used as well as the abbreviation `eq`. For example
    val1 == val2
and
    val1 eq val2
are equivalent. `null` is only ever equal to null, that is if you compare null to any non-null value, the result is false. Equality uses the java `equals` method
Inequality | The usual `!=` operator can be used as well as the abbreviation `ne`. For example
    val1 != val2
and
    val1 ne val2
are equivalent.
Less Than | The usual `<` operator can be used as well as the abbreviation `lt`. For example
    val1 < val2
and
    val1 lt val2
are equivalent.
Less Than Or Equal To | The usual `<=` operator can be used as well as the abbreviation `le`. For example
    val1 <= val2
and
    val1 le val2
are equivalent.
Greater Than | The usual `>` operator can be used as well as the abbreviation `gt`. For example
    val1 > val2
and
    val1 gt val2
are equivalent.
Greater Than Or Equal To | The usual `>=` operator can be used as well as the abbreviation `ge`. For example
    val1 >= val2
and
    val1 ge val2
are equivalent.
Addition | The usual `+` operator is used. For example
    val1 + val2
Subtraction | The usual `-` operator is used. For example
    val1 - val2
Multiplication | The usual `*` operator is used. For example
    val1 * val2
Division | The usual `/` operator is used. For example
    val1 / val2
Integer Division | The `div` operator is used. For example
    4 div 3
gives 1.
Modulus (or remainder) | The `%` operator is used. An alternative is the `mod` operator. For example
    5 mod 2
gives 1 and is equivalent to
    5 % 2
Negation | The unary `-` operator is used. For example
    -12
Array access | Array elements may be accessed using either square brackets or a dotted numeral, e.g.
    arr1[0]
and
    arr1.0
are equivalent