Handling expressions with Apache Commons Jexl
Yesterday I started a project task here where I need implement a kind of expression language, after some web search I finally found the Apache Common Jexl library that aims to provide an expression language that can be embedd into your applications, my first piece of code using this library is something like we have below:
[code lang="java"]
HashMap meta = new HashMap();
meta.put("key", "Google");
meta.put("type", "Company");
String exp = "meta['key'] + ' is a ' + meta['type']";
Expression e = ExpressionFactory.createExpression(exp);
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("meta", meta);
Object o = e.evaluate(jc);
System.out.println(o);
[/code]
The output of this code is something like this:
Google is a company
You can do much more than this, you can check the complete list of Jexl features at Apache Commons Jexl website: http://commons.apache.org/jexl/index.html
Cool!
Muito boa a dica!
Vou acessar o site e ver a documentação. Valeu!
Thx!
October 10th, 2007 | #