You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by James M Snell <ja...@gmail.com> on 2006/06/19 19:44:59 UTC

Source and Result Implementation

I've implemented two utility classes (attached) that implement the
javax.xml.transform.Source and javax.xml.transform.Result interfaces.
These allows us to apply XSLT transforms to Abdera objects.  For instance:

// yes... abdera can parse XSLT too :-)
    InputStream xslt = Test.class.getResourceAsStream("/test.xslt");
    Document<Element> xsltdoc = Parser.INSTANCE.parse(xslt);
    BaseSource source = new BaseSource(xsltdoc);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(source);

// let's first transform a parsed feed
    InputStream feed = Test.class.getResourceAsStream("/test.xml");
    Document<Feed> doc = Parser.INSTANCE.parse(feed);
    BaseSource feedSource = new BaseSource(doc);

    BaseResult result = new BaseResult();

    transformer.transform(feedSource, result);

// did it work?
    Document<Element> doc2 = result.getDocument();
    doc2.writeTo(System.out);

// it even works with dynamically created feeds
    Feed dynamicFeed = Factory.INSTANCE.newFeed();
    dynamicFeed.setId("urn:foo");
    feedSource = new BaseSource(feed);
    result = new BaseResult();
    transformer.transform(feedSource, result);
    doc2 = result.getDocument();
    doc2.writeTo(System.out);

I would like to add these to org.apache.abdera.util.*
(I'll likely rename them to AbderaSource and AbderaResult)

- James