commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject [digester] minor patches for using a Digester as a ContentHandler...
Date Wed, 31 Jul 2002 11:04:46 GMT
I've been working on a Betwixt library for Jelly, so that in Jelly we can do
things like...

<betwixt:parse var="mybean" rootClass="com.acme.Foo">
  <Foo id="123" name="cheese">

<j:forEach items="${mybean.bars}">

Or a URI can be specified like this...

<betwixt:parse var="mybean" rootClass="com.acme.Foo" uri="foo.xml"/>

In the first case, I need to be able to use Betwixt's BeanReader, which is-a
Digester in a new way that I'm not sure folks have done before.

Digester implements the SAX ContentHandler interface, so you can just stream
SAX events into digester rather than calling the one of the parse() methods.
So in the first example, the <betwixt:parse> tag will fire all the SAX
events of its body (the <Foo> and <Bar> elements) directly into the digester
rather than calling a parse() method.

I've made 2 minor patches to Digester so that it can be used properly as a
SAX ContentHandler, rather than via the parse() methods...

* ensured that configure() is called in the startDocument() to ensure that
digester rules are properly configured before any XML events are consumed.

* added a getRoot() property, so that after the SAX events have been fired
into the digester, the calling code can extract the root object.

So now folks should be able to use the digester (if they wish) like this...

    Digester digester = new MyDigester();

    // fire SAX events into the digester.

    // now retrieve the object that digester parsed
    Object object = digester.getRoot();


Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message