Thanks Ryan, it works now !!!

In fact when you said that this problem was not there in FOP 0.20.3 I tried 
that first :-) and it worked. Once I knew it did I went ahead to experiment 
with FOP 0.20.1

And the fix you suggested worked.

So the code, just for reference (to others who may need it at a later time) 
is

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;

import org.apache.fop.apps.Driver;
import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.fo.FOTreeBuilder;

public class TestXml {

    public static void main(String[] args) {

        try {

                // XML Will eventually be a Java String or Stream from another 
source.
                StreamSource xmlsource = new StreamSource(new 
FileReader("simple.xml"));

                Driver driver =new Driver();
                FileOutputStream fos = new FileOutputStream("simple.pdf");
                driver.setOutputStream(fos);            
                driver.setRenderer(Driver.RENDER_PDF);

                // Fix : ADDED this code as suggested by Ryan to work with FOP 
0.20.1 
(yeah, not required by FOP 0.20.3)
                        StreamRenderer x = new StreamRenderer(fos, 
driver.getRenderer());
                ((FOTreeBuilder) 
driver.getContentHandler()).setStreamRenderer(x);
                // Fix ends

                Transformer transformer = 
TransformerFactory.newInstance().newTransformer(new StreamSource(new 
FileReader("simple.xsl")));

                // Previously threw error without above 2 line Fix
                transformer.transform(xmlsource,  new 
SAXResult(driver.getContentHandler()));
                
                //For test purposes only
                //transformer.transform(xmlsource,  new 
StreamResult(System.out));
                
    } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Ryan, Mehmood I really appreciate your help guys. It did help.

Anil.

-----Original Message-----
From:   [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]
Sent:   Friday, June 21, 2002 2:56 PM
To:     [EMAIL PROTECTED]
Subject:        Re: Using Xalan Transformer with FOP Driver problem



I use 0.20.1 also with SAX events.  I had to add this to get rid of the
null pointer:


            //Hack fix for FOP bug.  Might be unnecessary in FOP 0.20.3.
            StreamRenderer x = new StreamRenderer(outputStream,
pdfDriver.getRenderer());
            ((FOTreeBuilder)pdfDriver.getContentHandler
()).setStreamRenderer(x);


Hope this helps,

-Ryan







Reply via email to