abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Extending Abdera - Atom 0.3 Example
Date Mon, 12 Jun 2006 21:34:16 GMT

attached is a small sample project that shows how someone could extend
Abdera to support Atom 0.3 and possibly even RSS ... without requiring
*any* changes to any of the internals.

Note: this code will only work with the code snapshot I will be posting
later today, so you won't be able to run the code yet.

The zip contains the following files

 |-- /src
      |-- Test.java
      |-- /sample
      |    |
      |    |-- Atom03ExtensionFactory
      |    |-- Atom03Feed
      |-- /META-INF
           |-- /services
                 |-- org.apache.abdera.factory.ExtensionFactory

The file named "org.apache.abdera.factory.ExtensionFactory" in the
/META-INF/services directory is a simple text file used to register
static extension factories with the Abdera parser.  Each line in the
file lists the class name of the extension factory.  In this case, there
is only a single line in the file "sample.Atom03ExtensionFactory"

When the Abdera parser encounters an element in the XML that it does not
understand, it goes out and looks for an ExtensionFactory capable of
handling the element.  If it finds one, it hands the parsing of that
element off to the ExtensionFactory.  If it doesn't find one, it creates
a default FOMExtensionElement instance.

In the above example, when the parser encounters elements from the Atom
0.3 namespace, it asks the sample.Atom03ExtensionFactory to handle them.
 Right now, that extension factory is only handling instances of the
Atom 0.3 feed element, which implements the FOM Feed interface.

This allows me to do the following in code:

    URL url = new URL("http://scobleizer.wordpress.com/feed/atom");
        // a known Atom 0.3 Atom feed
    Document<Feed> doc = Parser.INSTANCE.parse(url.openStream());
    Feed feed = doc.getRoot();

The last line outputs: "class sample.Atom03Feed"

- James

View raw message