abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: Graceful handling of non-atom 1.0 feeds
Date Sun, 11 Jun 2006 16:22:50 GMT
The generics are an API optimization.  The code autodetects what is
being parsed. In every case, Document.getRoot() returns some derivative
of the FOM Element interface.  If you know what you're parsing, use the
generics; if you're not sure what you're parsing, don't use the generics
and do an instanceof to see what you ended up with.  I'm not sure I see
the "problem".

Alternatively, plug in an Atom 0.3 Extension Factory and provide a set
of classes that implement the FOM on top of the Atom 0.3 model.  Then
you could continue to use the generics form.  By Tuesday I should be
able to post some sample code that illustrates this...

  Document<Feed> doc = Parser.INSTANCE.parse(atom03FeedStream);
  Feed feed = doc.getRoot();
  System.out.println(feed.getClass());   // outputs sample.Atom03Feed

- James

Garrett Rooney wrote:
> On 6/10/06, James M Snell <jasnell@gmail.com> wrote:
>> Abdera will successfully parse any well-formed XML.  The trick is not to
>> use generics when parsing.
>> Document doc = Parser.INSTANCE.parse(someInputStream);
>> The parser will automatically detect whether the XML stream is an Atom
>> document (Feed, Entry or Atom Publishing Protocol Introspection doc) or
>> whether it is some other XML.
>> Element element = doc.getRoot();
>> if (element instanceof Feed) {
>>   // it was an Atom Feed document }
>> if (element instanceof Entry) {
>>   // it was an Atom Entry document }
>> if (element instanceof Service) {
>>   // it was an APP Introspection document }
>> if (element instanceof ExtensionElement) {
>>   // it was arbitrary XML }
>> More below.
> Makes one wonder what the point of the generics is, if you can't use
> them if you want to be able to recover gracefully from such
> problems...
> -garrett

View raw message