You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Pricilla Yin <pr...@transcanada.com> on 2000/09/12 17:06:03 UTC

[BUG] FOTreeBuilder exception

The following is re-posted as a bug.

I have an application that generate pdf document by feeding a DOM
directly to FOP. It works well with fop_bin_0_12_1.jar.
However, when I switched to use fop_bin_0_14_0.jar, I got the following
exception when I run the application :

java.lang.reflect.InvocationTargetException:
java.lang.NullPointerException
 at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java,
Compiled Code)
 at org.apache.fop.apps.Driver.buildFOTree(Driver.java, Compiled Code)

When I used the XalanCommandLine to test my stylesheet templates, the
pdf document was generated properly.

The following code is used to generate the document:

    public void buildDocument(Document xmlDoc, String xmlTemplateSource)

throws IOException{

        Document xmlTemplate = null;
        InputStream in = null;

        if (fopDriver == null) {
           fopDriver = new Driver();

fopDriver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",
Version.getVersion());

fopDriver.addElementMapping("org.apache.fop.fo.StandardElementMapping");



fopDriver.addElementMapping("org.apache.fop.svg.SVGElementMapping");

fopDriver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");



fopDriver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
           // Setup the writer for pdf mime type
           fopDriver.setWriter(writer);
        }

        // Render the document
        try {

            in =
ClassLoader.getSystemResourceAsStream(xmlTemplateSource);
            xmlTemplate = XsltSimpleProcessor.newDocument(new
InputSource(in));

            // Must generate the XMLFO document
            XsltSimpleProcessor processor = new
XsltSimpleProcessor(xmlTemplate);
            Document fopDoc = processor.process(xmlDoc);

            // Build the FO tree from the xslfoDoc
            fopDriver.buildFOTree(fopDoc);

            // Complete the rendering
            fopDriver.format();
            fopDriver.render();
        }
        catch (FOPException ex) {
            throw new IOException("Failed to load document: " +
ex.getMessage());
        }
        catch (org.xml.sax.SAXException ex) {
            throw new IOException("Failed to parse document: " +
ex.getMessage());
        } finally {
            if (in != null)
                in.close();
        }
    }

I did some debugging and found the null pointer exception was caused by
a null "plBuilder" in
org.apache.fop.fo.FOTreeBuilder.startElement() method. This method was
invoked by the
org.apache.fop.apps.Driver.buildFOTree(Document) method as following :

      this.treeBuilder.startElement("", currentNode.getNodeName(), "",
currentAtts);

As the first parameter (uri) is an empty string, the lookup of plBuilder

in startElement() using the empty string uri returns a  null
"plBuilder".

Is this a bug or did I miss some steps before calling the buildFOTree()
method?

Pricilla Yin