Facing new challenges everyday

Handling expressions with Apache Commons Jexl

October 2nd, 2007

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

Post to Twitter

1 Comment »

  1. Fred says

    Cool!

    Muito boa a dica!
    Vou acessar o site e ver a documentação. Valeu!

    Thx!

    October 10th, 2007 | #

Leave a comment

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:
Imagem CAPTCHA

RSS feed for these comments. | TrackBack URI

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

hosted by easy2use.net