Package Documentation for org.apache.commons.jexl Package
Provides a framework for evaluating JEXL expressions.
Java Expression Language (JEXL) is an expression language engine which can be
embedded in applications and frameworks. JEXL is inspired by Jakarta Velocity
and the Expression Language defined in the JavaServer Pages Standard Tag Library
version 1.1 (JSTL) and JavaServer Pages version 2.0 (JSP).
JEXL attempts to bring some of the lessons learned by the Velocity
community about expression languages in templating to a wider audience.
Commons Jelly needed
Velocity-ish method access, it just had to have it.
It must be noted that JEXL is not a compatibile implementation of EL as defined
in JSTL 1.1 (JSR-052) or JSP 2.0 (JSR-152). For a compatible implementation of
these specifications, see the
Commons EL project.
When evaluating expressions, JEXL merges an
Expression
with a
JexlContext.
An Expression is created using
ExpressionFactory.createExpression(),
passing a String containing valid JEXL syntax. A JexlContext is created using
JexlHelper.createContext(),
and variables are put into a map exposed through the
getVars()
method on JexlContext. The following example, takes a variable named foo, and
invokes the bar() method on the property innerFoo:
// Create an expression object
String jexlExp = "foo.innerFoo.bar()";
Expression e = ExpressionFactory.createExpression( jexlExp );
// Create a context and add data
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("foo", new Foo() );
// Now evaluate the expression, getting the result
Object o = e.evaluate(jc);
|