[jdom-interest] jdom and fop

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Nov 5 01:21:59 PST 2002


Hi,

pdlnhrd at yahoo.com wrote:

> here is the error I am getting:
>  pdfDriver.setInputSource(xmlResult);
>         <--------------------------------->
> *** Error: No match was found for method
> "setInputSource(org.jdom.transform.JDOMResult)".

You get this error because JDOMResult is not a SAX InputSource; it extends 
javax.xml.transform.sax.SAXResult. So, you can not use JDOMResult to interface 
the XSLT processor with FOP. Anyway, this would only lead to poor performances 
as FOP expects a SAX event flow as input and the XSLT processor can't directly 
generate it, thus avoiding the overhead (CPU, memory + GC) of creating a 
temporary JDOM document and firing the SAX events from it.

> like I said, i am completely new to this and I am trying to make this
> work by piecing bits of information that I have found all over the
> place, there might be and easier way to do this... any information
> would be helpfull or maybe even a tutorial taht someone knows of.

The best way to interface the XSLT processor and FOP is to use a SAX pipeline. 
The FOP Driver class provides specific methods to ease this, the input of your 
XSL transformation can still be a JDOM document (using JDOMSource).
Here's an example (using FOP 0.20.3 API):

    ByteArrayOutputStream output = new ByteArrayOutputStream();

    // Get a FOP rendering engine.
    Driver pdfDriver = new Driver();
    pdfDriver.setRenderer(Driver.RENDER_PDF);
    pdfDriver.setOutputStream(output);

    // Get a JAXP TrAX Transformer (please use Templates to cache stylesheets).
    Transformer transformer = ...;

    // Apply XSL Transformation on the JDOM Document, redirecting the
    // result to the FOP rendering engine.
    transformer.transform(new JDOMSource(doc),
                          new SAXResult(pdfDriver.getContentHandler()));

    // Send result to navigator.
    byte[] content = output.toByteArray();
    ...

That's it. No need to call Driver.run(), etc.

Hope this helps,

Laurent




More information about the jdom-interest mailing list