Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 94482 invoked from network); 11 Aug 2005 08:53:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Aug 2005 08:53:52 -0000 Received: (qmail 59058 invoked by uid 500); 11 Aug 2005 08:53:48 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 58835 invoked by uid 500); 11 Aug 2005 08:53:46 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 58822 invoked by uid 99); 11 Aug 2005 08:53:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2005 01:53:46 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [210.86.15.158] (HELO avmta3-rme.xtra.co.nz) (210.86.15.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2005 01:54:06 -0700 Received: from mta4-rme.xtra.co.nz ([210.86.15.143]) by avmta3-rme.xtra.co.nz with ESMTP id <20050811085341.STD7577.avmta3-rme.xtra.co.nz@mta4-rme.xtra.co.nz>; Thu, 11 Aug 2005 20:53:41 +1200 Received: from [10.1.1.5] ([219.89.109.124]) by mta4-rme.xtra.co.nz with ESMTP id <20050811085340.TYYA5449.mta4-rme.xtra.co.nz@[10.1.1.5]>; Thu, 11 Aug 2005 20:53:40 +1200 Subject: Re: Digester XML rules and more complex pattern evaluation (XPath) From: Simon Kitching Reply-To: skitching@apache.org To: Richard Wood Cc: commons-user@jakarta.apache.org In-Reply-To: <001301c59d74$0f929900$4f1b4854@floyd> References: <001301c59d74$0f929900$4f1b4854@floyd> Content-Type: text/plain Date: Thu, 11 Aug 2005 20:53:42 +1200 Message-Id: <1123750422.4810.20.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Wed, 2005-08-10 at 08:23 +0200, Richard Wood wrote: > Hello > > Didn't get any feedback in the user group. I'll try this one hoping that > somebody might have an idea how to solve... > A digester problem. > I'm trying to trigger different rules depending on the value of an > attribute. > Something like this > > xml > > > > xml rules > > ..do something > > > ..do something else > > > The patterns are using XPath similar notation. > > How can I extend the existing DigesterRuleParser so that I can add my own > "pattern matching" method? > I'm guessing I would have to write my own extension of RulesBase. > But how can I combine an instance of MyRulesBase with FromXMLRuleSet and > DigesterRuleParser? > > Help would be much appreciated Hi Richard, I saw your email on the user list earlier but unfortunately didn't have any time to write a decent reply. I've redirected this email back to the user list as it is more appropriate there. I think the task of writing a RulesBase implementation that supports xpath-like syntax would be very large. I suspect its not actually possible without significantly changing the API between digester and the RulesBase, as currently RulesBase objects aren't passed enough information to match on anything but element names. Changing that API would of course break backwards compatibility unless care is used. I have been working on a digester 2.x design, and supporting xpath-like matching is a goal for that, but there's a long way to go. In the meantime, as long as you only have a few cases where you need to match based on attributes, using custom rules or rule "filters" is more feasable than implementing a custom RulesBase I think. Here's one proposal along those lines, though I haven't analysed the actual design: http://issues.apache.org/bugzilla/show_bug.cgi?id=31329 I think that writing a rule "decorator" might be reasonably easy and effective: public class RuleAttributeFilter implements Rule { public RuleFilter(Map attributes, Rule decoratedRule) { } private StackOfBooleans enabled = new StackOfBooleans(); public void begin(....) { // check the attributes, and push a true or false onto the enabled // stack depending on whether the rule is "enabled" or not. if (enabled) decoratedRule.begin(..); } public void body(...) { if (enabled.peek()) decoratedRule.body(...); } public void end(..) { if (enabled.peek()) decoratedRule.end(...) enabled.pop(); } } Note that this requires each conditional rule to be wrapped individually. All of the above has been discussed before on the commons-user list in various forms, so I suggest searching the archives for past discussions. Of course if you insist on using xmlrules (which I am not at all fond of) then you'll need to go through extra steps to figure out how to make that functionality available via xmlrules. This has also been discussed on the commons-user list in the past, so you should find useful info on this in the archives. If you get something working, then please send an email with the details (or create a wiki entry) as you're not the first to ask about this. Cheers, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org