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 Weiqi Gao <we...@networkusa.net> on 2001/05/02 08:32:16 UTC

What's wrong with this code

Hi,

In the following code, I'm attempting to transform an XML file with an
XSLT stylesheet using the appropriate JAXP 1.1 XSLT transformer, and use
the resulting DOM tree as the source for the FOP processing step.  I use
the simplest foo.xml and foo.xslt files possible as data files
(Attached).

import org.apache.fop.apps.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;

public class TrAXFOPDOM {
    public static void main(String[] args) {
        try {
            InputStream is =
                new BufferedInputStream(new FileInputStream("foo.xml"));
            StreamSource xmlSource = new StreamSource(is);
            is = new BufferedInputStream(new
FileInputStream("foo.xslt"));
            StreamSource xslSource = new StreamSource(is);
            DOMResult result = new DOMResult();
            TransformerFactory f = TransformerFactory.newInstance();
            Templates templates = f.newTemplates(xslSource);
            Transformer transformer = templates.newTransformer();
            transformer.transform(xmlSource, result);
            Driver driver = new Driver();
            driver.setRenderer(Driver.RENDER_PDF);
            driver.buildFOTree((Document) result.getNode());
            driver.format();
            driver.setOutputStream(new FileOutputStream("foo.pdf"));
            driver.render();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

When I run this with Xerces+Xalan on my classpath, I get the expected
result.  When I run this with Xerces+Saxon on my classpath, I get an
exception like the following exception:

[weiqi@gao]$ java TrAXFOPDOM
null
java.lang.NullPointerException
	at org.apache.fop.tools.DocumentReader.parse(DocumentReader.java:434)
	at org.apache.fop.apps.Driver.buildFOTree(Driver.java:422)
	at TrAXFOPDOM.main(TrAXFOPDOM.java:36)

What seems to be my problem?  (I used the appropriate defines on the
java command line:
-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Djavax.xml.transform.TransformerFactory=com.icl.saxon.TransformerFactoryImpl)

Any help would be appreciated.

-- 
Weiqi Gao
weiqigao@networkusa.net