The expression interpreter is a central component which adds the capability to
dynamical evaluate contents. It is heavily used int the printing and the
web module.
Click here to browse the API documentation of the current version.
The basic syntax is very similar to the new JAVA Expression Language, introduced with the JSP 2.0 specification, but this Expression Interpreter can do much more.
You can easily use the ExpressionInterpreter from your own code. Here's a simple example.
try { ExpressionInterpreter exi = new ExpressionInterpreter(); ExpressionContext ctx = new ExpressionContext(); ctx.setProperty("word", "UJAC"); ctx.setProperty("number", new Integer(10)); System.out.println("expression result: " + exi.evalString("${${word} + '-' + ${number + 1}}", properties)); } catch (ExpressionException ex) { // Oops, something went wrong ... ex.printStackTrace(); } |
if (exi.evalBoolean("${word isDefined}", ctx)) { ... } |
Evaluates a text that is allowed to contain exactly one expression as a boolean. |
int len = exi.evalInt("${word length}", ctx); |
Evaluates a text that is allowed to contain exactly one expression as a int. |
It provides type specific handlers to add support for various classes.
By default, the Expression Interpreter handles objects according to the JavaBean
standard, which means it provides access to the object's properties using the
getter methods. In case the object's class matches a registered type, it
adopts the behaviour of this type.
${table.field} |
Gets the field 'field' from the table 'table' |
${1 + 2 + 3} |
Gets the result of the calculation (6 in this case - I guess). |