You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Strachan <ja...@yahoo.co.uk> on 2002/07/31 13:04:46 UTC

[digester] minor patches for using a Digester as a ContentHandler...

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">
    <Bar>abc</Bar>
    <Bar>xyz</Bar>
  </Foo>
</betwixt:parse>

<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.
    digester.startDocument();
    ...
    digester.endDocument();

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

James

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>