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: Erik Melkersson <melker@unit.liu.se>
Date: Fri, 05 Oct 2001 09:03:55 +0200
To: www-xsl-fo@w3.org
Message-id: <3BBD5B5B.C5801FD5@unit.liu.se>
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/
Received on Friday, 5 October 2001 03:04:26 GMT

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