W3C home > Mailing lists > Public > www-xsl-fo@w3.org > October 2001

Re: Using a org.w3c.dom.Document as indata to the Driver

From: Magnus Sj÷berg <magnus.sjoberg@secode.com>
Date: Fri, 05 Oct 2001 11:13:58 +0200
Message-ID: <3BBD79D6.14EBF40F@secode.com>
To: Erik Melkersson <melker@unit.liu.se>
CC: www-xsl-fo@w3.org
Yep, but using a DocumentInputSource as input to the Driver
class gives the null pointer exception you describe below.

Is this perhaps a known problem???

///Magnus

Erik Melkersson wrote:
> 
> Yes thanks it does do the trick! Which was my main problem.
> 
> But wouldn't it be more efficient to use the DOM tree directly instead
> of transforming it to a string first? (But fop doesn't seen to handle
> this kind of input correct or what?)
> 
> Regards
> /Erik Melkersson
> 
> Magnus Sj÷berg wrote:
> >
> > The following example will do the trick.
> >
> > Rgds///
> >         Magnus Sj÷berg
> >
> > // Small example
> > DocumentBuilderFactory dbf =
> > DocumentBuilderFactory.newInstance();
> > DocumentBuilder db = dbf.newDocumentBuilder();
> > Document doc = db.parse(FoFilename);
> > DOMSource fosource;
> > Serializer serializer =
> > SerializerFactory.getSerializer(OutputProperties.getDefaultMethodProperties("xml"));
> > ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > CharArrayWriter caw = new CharArrayWriter();
> > InputSource is;
> >
> > // Add changes to doc
> > ...
> >
> > // Get source tree
> > fosource = new DOMSource(doc);
> >
> > // Create input source
> > serializer.setWriter(caw);
> > serializer.asDOMSerializer().serialize(fosource.getNode());
> > is = new InputSource(new StringReader(caw.toString()));
> >
> > Driver driver2 = new Driver(is, bos);
> > driver2.setRenderer(Driver.RENDER_PDF);
> > driver2.run();
> >
> > // Result is in 'bos'
> >
> > Erik Melkersson wrote:
> > >
> > > Hi!
> > >
> > > I would like to read a fo file to a DOM tree on startup.
> > > Do some changes to it on runtime and then produce pdf and ps from it.
> > >
> > > I am using version 0.20.1 of fop.
> > >
> > > My try:
> > >
> > > ---
> > > // Fetch xml -> dom tree
> > > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> > > DocumentBuilder docBuilder = dbf.newDocumentBuilder();
> > > Document doc = docBuilder.parse(FOfilename);
> > >
> > > //... some changes to the DOM tree shall be done here (but I aint doing
> > > any changes yet
> > >
> > > Driver driver = new Driver();
> > > driver.setRenderer(Driver.RENDER_PDF);
> > > driver.setOutputStream(new FileOutputStream());
> > >
> > > driver.render(doc); // -> returns fault, se below
> > >
> > > //driver.setInputSource(new DocumentInputSource(doc));
> > > // -> gives the same fault
> > >
> > > /*
> > >   //This works (but it doesn't use the preparsed dom tree
> > >   driver.setInputSource(new InputSource(aPDFfilename));
> > >   driver.run();
> > > */
> > > ---
> > >
> > > The error I get is:
> > > java.lang.NullPointerException
> > >         at java.util.Hashtable.get(Hashtable.java:320)
> > >         at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:191)
> > >         at org.apache.fop.tools.DocumentReader.parse(DocumentReader.java:444)
> > >         at org.apache.fop.apps.Driver.render(Driver.java:449)
> > >         at Avi.main(Avi.java:61) (my file)
> > >
> > > I can only find old examples where a method Driver.format() is used...
> > > and they does not use dom trees as indata.
> > >
> > > Thankful for any help!
> > >
> > >
> > > __________________________
> > > Erik Melkersson, UNIT
> > > melker@unit.liu.se, 013-285794
> > > http://www.unit.liu.se/
> 
> --
> __________________________
> Erik Melkersson, UNIT
> melker@unit.liu.se, 013-285794
> http://www.unit.liu.se/

-- 

Secode - Total Internet Security
Magnus Sj÷berg
Research And Development

email: magnus.sjoberg@secode.com
cell: +46 709 150 710
POTS: +46 8 564 875 05
http://www.secode.com

Internet is to be a safe area for business, transactions and
information exchange
Received on Friday, 5 October 2001 05:12:47 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:08 GMT