Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 70467 invoked from network); 14 Mar 2010 09:42:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Mar 2010 09:42:38 -0000 Received: (qmail 55152 invoked by uid 500); 14 Mar 2010 09:41:55 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 55095 invoked by uid 500); 14 Mar 2010 09:41:55 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 55087 invoked by uid 99); 14 Mar 2010 09:41:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Mar 2010 09:41:54 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.218.224 as permitted sender) Received: from [209.85.218.224] (HELO mail-bw0-f224.google.com) (209.85.218.224) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Mar 2010 09:41:51 +0000 Received: by bwz24 with SMTP id 24so2503075bwz.36 for ; Sun, 14 Mar 2010 01:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=uGG1bKVIyCcVIu7GoghTX6ZBr5Afm7haxPzirOn5v9w=; b=nBJAVeN+ZVGg8Me9OyRFUNK+tgALVkMvKv8CsGfSiALwYqbIGY4WJlAGh4bl+tizxt zP/828luRRAgCya74Y2HaN3lWU0uMdsFuyraIWu9gMRCJr/HyaGKGv8bpefMZaarLIIX M1V2l/Ibgb1msggVS15YXXcwSGdRtbiDL1HLM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=F+LVZaT7WJ69+HSPxSOL8vGNWSM/Htas2hbDscuosolBEZrjbPgEZSD31uzDWpcYt8 exDrjyvpdo8oGwX/d3JiBMv34LXSu8DGGCbSEYJZbN5GZ7PqQIE3BoLGFATV/A8r80UX VMEyqW+yDBtdFmf/UDDiHhJBi74+o21y+BXec= MIME-Version: 1.0 Received: by 10.204.38.73 with SMTP id a9mr5516096bke.46.1268559689165; Sun, 14 Mar 2010 01:41:29 -0800 (PST) From: Claus Ibsen Date: Sun, 14 Mar 2010 10:41:09 +0100 Message-ID: <5380c69c1003140141m145fe617ud65f457d5a4f7a0a@mail.gmail.com> Subject: Help with regular expression repeating group for new OGNL like feature in Camel Simple Language To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 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 ${body.getAddress.getStreet} Obviously used with getters so we will support the short hand syntax as well ${body.address.street} And you can use it with headers as well ${header.user.address.street} And it supports indexing Map/List so you can do ${header.types[admin]} 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 ${header.user?.address.street} 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. ${body.address.street} ${body?.address.street} 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