abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Source and Result Implementation
Date Mon, 19 Jun 2006 17:44:59 GMT
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

Mime
View raw message