commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [digester] nested element detection
Date Wed, 14 Dec 2005 08:00:16 GMT
Hi Ryan,

On Tue, 2005-12-13 at 16:00 -0700, Graham, Ryan - WMD wrote:
> <log>
>    <logitem timestamp="Fri Dec 09 14:16:18 MST 2005">
>       <error from="...">
>          <message>...</message>
>       </error>
>    </logitem>
>    <logitem timestamp="Fri Dec 09 14:18:55 MST 2005">
>       <warning from="...">
>          <message>...</message>
>       </warning>
>    </logitem>
>    <logitem timestamp="Fri Dec 09 14:30:05 MST 2005">
>       <info from="...">
>          <message>...</message>
>       </info>
>    </logitem>
> </log>
> 
> I want to create an object for each logitem, set the timestamp, set the
> type based on the next element (error, warning or info) and then get the
> message text. I've tried to do something like this without much success:
>       
> digester.addObjectCreate("log/logitem", LogItem.class);
> digester.addSetProperties("log/logitem", "timestamp", "timestamp");
> 
> //here is where I get stuck...
> digester.addSetProperties("log/logitem/*", "type", "type");
> digester.addSetNext("log/logitem ", "addLogItem");
> 
> Any help would be greatly appreciated.

As you've only got a limited set of possible loglevels, I would suggest
this:
  digester.addCallMethod("log/logitem/error", 1, "setType");
  digester.addObjectParam("log/logitem/error", 0, "error");
  digester.addSetProperties("log/logitem/error");
  digester.addCallMethod("log/logitem/error/message", "setMessage");
Repeat for every possible level.

Trailing wildcards are not supported by the default digester
rule-matcher. You could get fancier by using one of the enhanced
rule-matching engines (ExtendedBaseRules or RegexRules) which do support
trailing wildcards and other stuff; see method Digester.setRules. And
you could write your own "SetLevelRule" that fires for the level
element, and calls the setLevel method on the top object on the stack
using the current element name. That will need a reasonable amount of
learning about digester though - probably not necessary here.

Hope this helps...

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message