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 "Mitchell, Scott(LIT)" <S....@Liberty-IT.co.uk> on 2002/01/03 11:32:32 UTC

Running fop from Java

Hi,

I am trying to use jox to take a java bean and create an xml file.  With
this file, I use fop to convert to a pdf.  I get the following error when
running the code.  

Input XSL; Line 1; Column 1
XSL Error: Could not parse Input XML document!
XSL Error: SAX Exception
org.apache.xalan.xslt.XSLProcessorException: The markup in the document
preceding the root element must be well-formed.
        at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1630)
        at
org.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.j
ava:852)
        at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:552)
        at com.wutka.jox.test.TestSer.main(TestSer.java:82)

This is the code, the red line is where the error occurs.

public class TestSer
{
    public static void main(String[] args)
    {
        try
        {
            TestBean b = new TestBean();
            b.setFoo(5);
            b.setBar("This is the bar value");
            b.setThingies(new String[] {
                "Moe", "Larry", "Curly", "Shemp", "Curly Joe" });
            TestSubbean sub = new TestSubbean();
            sub.setName("Mark");
            sub.setAge(35);
            b.setSub(sub);

            FileOutputStream fileOut = new
FileOutputStream("f:/ProgramFiles/jox/source/com/wutka/jox/test/bean.xml");
            JOXBeanOutputStream joxOut = new JOXBeanOutputStream(fileOut);

            joxOut.writeObject("MarkTest", b);

            joxOut.close(); 
                   
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Reader stylesheet = null;
            
            // Get the XSLT processor
            XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
	
            // Create the input source
            Reader responseReader = new
StringReader("f:/ProgramFiles/jox/source/com/wutka/jox/test/bean.xml");
                      
            XSLTInputSource responseSource = new
XSLTInputSource(responseReader);

            // Get the stylesheet
            String stylesheetPath = "";

            try {
                stylesheet = new FileReader("c:/stylesheet.css");
            } 
            catch (FileNotFoundException fnfe) {}
        	
            if (stylesheet == null) {                    
                    stylesheet = new FileReader("c:/stylesheet.css");
            }

            XSLTInputSource stylesheetSource = new
XSLTInputSource(stylesheet);

            // Get a target to contain the output
            Writer formWriter  = new StringWriter();
            XSLTResultTarget target = new XSLTResultTarget(formWriter);

            // Transform the XML response to fo format
            processor.process(responseSource, stylesheetSource, target);

            // Redirect the fo file from a Writer to a Reader
            Reader formReader = new StringReader(formWriter.toString());

            // Transform from fop to pdf
            XMLReader xmlReader = new SAXParser();	
            Driver driver = new Driver();
            driver.setRenderer(new org.apache.fop.render.pdf.PDFRenderer());
 
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
 
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
 
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
 
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
            driver.setOutputStream(new BufferedOutputStream(baos));
            driver.buildFOTree(xmlReader, new InputSource(formReader));
            driver.format();
            driver.render();

            // Clean up
            baos.close();
            stylesheet.close();
	}
        catch (Exception exc)
        {
            exc.printStackTrace();
        }
    }
}


Any ideas would be appreciated.

Scott Mitchell
Experienced Software Developer

Liberty Information Technology      Direct Line:     ++44 (0) 28 9044 5582
Clarendon House	              Fax:               ++44 (0) 28 9044 5511
9-21 Adelaide Street                    Switchboard:   ++44 (0) 28 9044 5500
Belfast, Northern Ireland BT2 8DJ  Email:
S.Mitchell@Liberty-IT.co.uk

Disclaimer: The contents of this e-mail and attached files in no way reflect
any policies of Liberty Information Technology Ltd.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org