camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Help with regular expression repeating group for new OGNL like feature in Camel Simple Language
Date Sun, 14 Mar 2010 09:41:09 GMT
Hi

I am working on adding a lightweight OGNL capabilities into the Camel
EL, know as the Simple language.
This allows you to use the simple language, which is shipped out of
the box in camel-core, to invoke methods in a OGNL like notation.

For example you may have an User object on the body then you can do
<simple>${body.getAddress.getStreet}</simple>

Obviously used with getters so we will support the short hand syntax as well
<simple>${body.address.street}</simple>

And you can use it with headers as well
<simple>${header.user.address.street}</simple>

And it supports indexing Map/List so you can do

<simple>${header.types[admin]}</simple>
To lookup the types header as a Map with the key admin.

And we are also throwing in the elvis operator so you can avoid NPE,
for example if the User does NOT have an address
<simple>${header.user?.address.street}</simple>


Well my problem is we need to parse the OGNL and I am not bringing in
the guns with some AST like grammar and whatnot.
Just using dumb Java String and Reg Exp to do the work as the Camel
OGNL is so simple currently.

I was trying out regexp to parse the OGNL but I got stuck on repeating groups.

The problem is that the beginning of a group is either: . or ?.
And the end of the group is until the next dot. In between there are
the method name and optional and index [foo] to lookup in Map/List.

<simple>${body.address.street}</simple>
<simple>${body?.address.street}</simple>

Currently I use some good old fashioned Java method to parse it, but I
am sure a reg exp guru can construct this in less than 15 chars of reg
exp.
I may give a go later, but I wanted to get all the rough work done
first, before returning to the reg exp dilemma.

And the reg exp should also be readable and understandable for the
future maintainers of Camel, so it cant be very complex.


-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message