Thanks for all your help on this. I have Fop-0.20.1-src.tar. How can I tell
which cvs this is? I only ask because I have no inet access right now.
I did discover that render(dom) does work if I load the dom object straight
from a file instead of obtaining it as the output of an xslt transform. I
serialized both objects and their xml-content is exactly the same.
So I ran every get method that outputs a string object to compare the two
DOM objects. I also compared the docTypes of each object. The only
difference I found was for the file DOM, docType.getName()="fo:root" (no
quotes), for the xslt-generated dom, docType.getName()=null (all other
docType values are null for both docTypes). I don't know whether this is
causing the problem or not. Unfortuantely DOM Level 2 doesn't support
editing DocumentType nodes.
I'm experimenting with several work-arounds right now but have had no luck.
Any ideas?
Thanks a lot,
Matt
Here is the source I'm using:
DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();
dFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
org.w3c.dom.Document xmlDoc = dBuilder.parse(xmlFilename);
DOMSource xmlDomSource = new DOMSource(xmlDoc);
org.w3c.dom.Document xslDoc = dBuilder.parse(xslFilename);
DOMSource xslDomSource = new DOMSource(xslDoc);
org.w3c.dom.Document foDoc = dBuilder.parse(foFilename);
DOMSource foDomSource = new DOMSource(foDoc);
DOMResult domResult = new DOMResult();
TransformerFactory tFactory = TransformerFactory.newInstance();
javax.xml.transform.Templates templates =
tFactory.newTemplates(xslDomSource);
Transformer transformer = templates.newTransformer();
transformer.transform( xmlDomSource, domResult );
org.w3c.dom.Document foOutDoc =
(org.w3c.dom.Document)domResult.getNode();
System.out.println("\foDoc:");
System.out.println(foDoc.getLocalName());
System.out.println(foDoc.getNamespaceURI());
System.out.println(foDoc.getNodeName());
System.out.println(foDoc.getNodeValue());
System.out.println(foDoc.getPrefix());
org.w3c.dom.DocumentType foDocType = foDoc.getDoctype();
System.out.println("\foDocType:");
if (foDocType != null) {
System.out.println(foDocType.getInternalSubset());
System.out.println(foDocType.getName());
System.out.println(foDocType.getPublicId());
System.out.println(foDocType.getSystemId());
}
System.out.println("\nfoOutDoc:");
System.out.println("foOutDoc.getLocalName()=" +
foOutDoc.getLocalName());
System.out.println(foOutDoc.getNamespaceURI());
System.out.println(foOutDoc.getNodeName());
System.out.println(foOutDoc.getNodeValue());
System.out.println(foOutDoc.getPrefix());
org.w3c.dom.DocumentType foOutDocType = foOutDoc.getDoctype();
System.out.println("\nfoOutDocType:");
if (foOutDocType != null) {
System.out.println(foOutDocType.getInternalSubset());
System.out.println(foOutDocType.getName());
System.out.println(foOutDocType.getPublicId());
System.out.println(foOutDocType.getSystemId());
}
org.apache.fop.apps.Driver driver = new
org.apache.fop.apps.Driver();
driver.setErrorDump(true);
driver.setRenderer(driver.RENDER_PDF);
driver.setupDefaultMappings() ;
driver.setOutputStream(new FileOutputStream(pdfFilename));
System.out.println("\ndriver.render(foDoc)");
driver.render(foDoc);
System.out.println("\ndriver.render(foOutDoc)");
driver.render(foOutDoc);
This is the output:
foDoc:
foDoc.getLocalName()=null
foDoc.getNamespaceURI()=null
foDoc.getNodeName()=#document
foDoc.getNodeValue()=null
foDoc.getPrefix()=null
foDocType:
foDocType.getInternalSubset()=null
foDocType.getName()=fo:root
foDocType.getPublicId()=null
foDocType.getSystemId()=null
foOutDoc:
foOutDoc.getLocalName()=null
foOutDoc.getNamespaceURI()=null
foOutDoc.getNodeName()=#document
foOutDoc.getNodeValue()=null
foOutDoc.getPrefix()=null
foOutDocType:
driver.render(foDoc)
building formatting object tree
setting up fonts
[1]
[2]
Parsing of document complete, stopping renderer
Initial heap size: 1766Kb
Current heap size: 2586Kb
Total memory used: 820Kb
Memory use is indicative; no GC was performed
These figures should not be used comparatively
Total time used: 734ms
Pages rendererd: 2
Avg render time: 367ms/page
driver.render(foOutDoc)
building formatting object tree
setting up fonts
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 FOtoPDF.applyFop(FOtoPDF.java:214)
at FOtoPDF.main(FOtoPDF.java:41)
> -----Original Message-----
> From: Keiron Liddle [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 20, 2001 12:00 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Does render(dom) actually work?
>
>
> Hi,
>
> This may be a problem that I have fixed.
> The line number (167) doesn't seem to match anything I can
> find so I'm not
> sure.
> There was a problem where text outside the root element would
> cause a null
> pointer exception.
>
> Actually after a second look I think it was due to the stream redner
> changes.
> Could you try the current cvs and see if that helps.
>
> Thanks
> Keiron
>
> On Thu, 20 Sep 2001 08:46:08 "Beer, Christian" wrote:
> > Hi Savino, hi Suhail, hi group!
> >
> > In the moment I transform my source-xml to a
> ByteArrayOutputStream and
> > then
> > use a ByteArrayInputStream as input for FOP.
> >
> > I tried to do it the same way as Suhails example, but I get the same
> > error
> > Savino got.
> >
> > How can I be sure there are no nulls in the source??
> >
> > Christian
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Suhail Rashid [mailto:[EMAIL PROTECTED]]
> > Gesendet: Donnerstag, 20. September 2001 06:29
> > An: [EMAIL PROTECTED]
> > Betreff: RE: Does render(dom) actually work?
> >
> >
> > Hi Savino,
> >
> > Make sure there
> > are NO nulls making their way
> > into the text nodes of your xml stream.
> > <these would not give problems if u
> > wrote the xml to a file first>
> >
> > suhail
> >
> > -----Original Message-----
> > From: Savino, Matt C [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, September 20, 2001 3:59 AM
> > To: '[EMAIL PROTECTED]'
> > Subject: RE: Does render(dom) actually work?
> >
> >
> > Yuri, thanks for your help. I tried your solution and I
> still get the
> > following error:
> >
> > building formatting object tree
> > building formatting object tree
> > javax.xml.transform.TransformerException
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transformNode(Tra
> nsformerIm
> > pl.j
> > ava:1212)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transform(Transfo
> rmerImpl.j
> > ava:
> > 479)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transform(Transfo
> rmerImpl.j
> > ava:
> > 1118)
> > at FOtoPDF.applyFop(FOtoPDF.java:127)
> > at FOtoPDF.main(FOtoPDF.java:40)
> > ---------
> > java.lang.NullPointerException
> > at
> >
> org.apache.fop.fo.FOTreeBuilder.startDocument(FOTreeBuilder.java:167)
> > at
> >
> org.apache.xalan.transformer.QueuedStartDocument.flush(QueuedS
> tartDocume
> > nt.j
> > ava:108)
> > at
> >
> org.apache.xalan.transformer.ResultTreeHandler.flushPending(Re
> sultTreeHa
> > ndle
> > r.java:758)
> > at
> >
> org.apache.xalan.transformer.ResultTreeHandler.startElement(Re
> sultTreeHa
> > ndle
> > r.java:245)
> > at
> >
> org.apache.xalan.transformer.ResultTreeHandler.startElement(Re
> sultTreeHa
> > ndle
> > r.java:209)
> > at
> >
> org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiter
> alResult.j
> > ava:
> > 704)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.executeChildTempl
> ates(Trans
> > form
> > erImpl.java:2154)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.executeChildTempl
> ates(Trans
> > form
> > erImpl.java:2097)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.applyTemplateToNo
> de(Transfo
> > rmer
> > Impl.java:2029)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transformNode(Tra
> nsformerIm
> > pl.j
> > ava:1189)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transform(Transfo
> rmerImpl.j
> > ava:
> > 479)
> > at
> >
> org.apache.xalan.transformer.TransformerImpl.transform(Transfo
> rmerImpl.j
> > ava:
> > 1118)
> > at FOtoPDF.applyFop(FOtoPDF.java:127)
> > at FOtoPDF.main(FOtoPDF.java:40)
> >
> > It looks very similar to the one before to me. Has anyone tried this
> > with
> > v.0.20.1 yet? Should it say "building formatting object
> tree" twice? I'm
> > wondering if this is some kind of issue with namespaces and the DOM2
> > implementation. Anyone have any ideas?
> >
> > By the way, if I use a DOMResult instead of a SAXResult I
> get no error.
> > I
> > then serialized the DOMResult to a file and FO works fine
> with that file
> > as
> > an input.
> >
> > Thanks,
> > Matt
> >
> >
> > > -----Original Message-----
> > > From: Shkuro, Yuri [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, September 19, 2001 2:03 PM
> > > To: '[EMAIL PROTECTED]'
> > > Subject: RE: Does render(dom) actually work?
> > >
> > >
> > > Matt,
> > >
> > > Why don't you do it all in one pass? I have a servlet,
> that calls
> > > some bean to get XML document in a DOM format (actually
> JDOM), then
> > > registers fop driver as receiver of SAX events and runs
> XSLT on the
> > > JDOM tree.
> > >
> > > // 1. Generate XML tree
> > > Document xmlSummary = DataLoader.getSummary();
> > >
> > > // 2. Get stylesheet transformer
> > > Transformer transformer =
> > > transformerFactory.getTransformer(
> > > <xsl-file> );
> > >
> > > // 3. Create FOP driver and set rendering mode
> > > and output stream
> > > org.apache.fop.apps.Driver driver = new
> > > org.apache.fop.apps.Driver();
> > > driver.setRenderer(driver.RENDER_PDF);
> > > driver.setOutputStream( out );
> > >
> > > // 4. Create SAXResult based on FOP Driver
> > > content handler which
> > > will accept
> > > // SAX events and build FOP tree
> > > javax.xml.transform.sax.SAXResult saxResult =
> > > new javax.xml.transform.sax.SAXResult(
> > > driver.getContentHandler() );
> > >
> > > // 5. Use the Transformer to transform an XML
> > > Source and send
> > > the output
> > > // to a Result object.
> > > // Implicitely it will create the FOP tree by
> > > firing SAX events
> > > transformer.transform( new
> > > org.jdom.transform.JDOMSource( xml ),
> > > saxResult );
> > >
> > > YS
> > >
> > > -----Original Message-----
> > > From: Savino, Matt C [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, September 19, 2001 4:33 PM
> > > To: '[EMAIL PROTECTED]'
> > > Subject: Does render(dom) actually work?
> > >
> > >
> > > Hello everyone. By any chance can someone point me to some
> > > example code
> > > which uses render(dom)? No matter what combination of driver
> > > methods or Fop
> > > versions (.17,.19,.20.1) I use I seem to get the same error:
> > >
> > > building formatting object tree
> > > setting up fonts
> > > 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 FOtoPDF.applyFop(FOtoPDF.java:83)
> > > at FOtoPDF.main(FOtoPDF.java:24)
> > >
> > > Here is the source I'm using under v.0.20.1:
> > > org.apache.fop.apps.Driver driver = new
> > > org.apache.fop.apps.Driver();
> > > driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
> > > driver.setOutputStream(new FileOutputStream(pdfFilename));
> > > driver.setupDefaultMappings() ;
> > >
> > >
> driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
> > >
> > > driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
> > >
> > > driver.addElementMapping("org.apache.fop.extensions.ExtensionE
> > > lementMapping"
> > > );
> > > driver.render(dom);
> > >
> > > I have tried it with and without any of the mapping methods.
> > >
> > > I am building the Dom object from a file. The sax input
> > > handler created from
> > > the same file works fine in render(parser, inputSource). I
> > > have read through
> > > the dev archives and found a few suggestions but none helped.
> > > Is there some
> > > configuration I'm missing? Or did this "break a long time
> > > ago" as someone
> > > suggested in the archives?
> > >
> > > I am hoping to use FOP in a major production app, but if I
> > > can't solve this
> > > I may not be able to. I am currently receiving a DOM object
> > > (a small report)
> > > from some database access classes. I then perform an XSLT
> > > transform which
> > > outputs my FO input as another DOM object. I suppose I could
> > > pipe the output
> > > of that to SAX? I'd really rather not have to do anything
> klugy like
> > > serialize it to a stream and then feed it in as SAX. But
> I'll consider
> > > anything that doesn't cause too much of a performace hit. We
> > > definitely
> > > don't want to have temp files sitting around, for a host
> of reasons.
> > >
> > > Thank you very much for your help.
> > >
> > > Matt Savino
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]