abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Constabaris <a...@clownsinmycoffee.net>
Subject Re: Creating "Arbitrary" XML Content
Date Wed, 13 Dec 2006 04:29:30 GMT
On Tue, 2006-12-12 at 20:49 -0500, Garrett Rooney wrote:
> On 12/12/06, Adam Constabaris <adam@clownsinmycoffee.net> wrote:
> > I'd like to write clients that generate entries with DocBook content.
> > Following the examples and the API documentation, the most
> > straightforward-looking approach to this end seems to be something like
> > this:
> >
> > String contentString = // let's imagine a string fulla XML
> > Entry e = factory.newEntry();
> > // set a bunch of other properties
> > e.setContent( contentString, Content.Type.XML );
> >
> > I've tried this, and several variations on it (setting a MimeType
> > directly, etc.), and the content's always null, or, if I get a Writer
> > and serialize the entry, I get an empty content element.  These results
> > were the same with the pre-0.2.0 trunk, the post 0.2.0 trunk, and the
> > 0.2.0 branch.
> >
> > So, I ask:
> >
> > 1) is this supported yet?
> > 2) where would I start scratching this itch if the answer to (1) is no?
> It certainly seems like it should work.  The best way to get started
> on fixing it is probably a failing test case for the test suite.  Then
> start tracing through the code to see why it isn't working ;-)

Got it (I think), but I'm not sure how to proceed.  What I'm seeing
looks like it's the product of the dual-nature of the FOM Model classes
in the parser sub-module.  The default configuration means that the FOM
model implementation is what you get from your default factory.

The FOMContent.setContent(String) method does a lot of aggressive
Exception swallowing of the form "catch (Exception e) {}", I'm guessing
in order to keep on chugging no matter what when parsing content from
who knows where.

What's happening to me when I generate everything programmatically from
scratch, there's no baseURI set on any of the elements, and so an NPE
(in FOMElement._parse(477)) is getting silently ignored.  The result, in
the current implementation, is that the behavior is dependent on the
order of events in a non-obvious (to me, anyhow) way.

The following works:

Entry e = factory.newEntry();
Content c = factory.newContent(Content.Type.XML);

if you call c.setValue() before you've attached it to the Entry, you get
that silent null pointer.

I'm not sure how to proceed from here; it seems to me that the
FOMContent.setValue() should probably be easier to set on fire, and also
more forgiving of a null baseUri, but then that might make it harder to
get a robust and compliant parser.



> > On a related note (leaving aside the application/xml question) is there
> > (yet) some mechanism for generating Content objects from files other
> > than by reading the file's contents into a string and calling
> > setContentAsXhtml() (e.g.)?  If I wanted to add support for taking an
> > AXIOM (or other XML object model), or an InputStream and set the content
> > directly from that, where would I start with that?
> I'm not sure how I feel about exposing Axiom APIs, but an InputStream
> or something like that seems perfectly reasonable to me.
> -garrett

View raw message