xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessandro Marcellini <amarc...@tiscalinet.it>
Subject Re: Problem with DOM Document -> FO
Date Fri, 16 Mar 2001 09:35:28 GMT
The problem is:
If I run xalan from the command line to build the fo document
(from the input.xml with the stylesheet.xsl) and then
I run fop from the command line to transform the fo doc. into Pdf
I don't encounter any problem!
So I think to wrong somethin in my program ...

Belmonte Laurent wrote:

> Alessandro Marcellini a écrit :
> >
> > Hi,
> > I'm a newbie with FOP: I've an application that generates a XML DOM
> > Document,
> > I want to transform it to PDF with a StyleSheet.
> > I'm working on a WINNT SP6, with jdk1.2.2 and I use Xerces1.3.0 to parse
> > the XML Input File and Xalan 2.0.0 to trnsform it.
> > I use FOP 0.17.0 to format my document.
> > But when FOP begin to Build the FOTree  throws this Exception:
> > java.lang.NullPointerException:
> >    at
> > org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:271)
> >    at org.apache.fop.apps.Driver.buildFOTree(Driver.java, Compiled Code)
> >
> >    at transform.main(transform.java:45)
> >
>
> maybe you have put a null String in a Text tag
>
> > Here I've written a little Example program that do this job with the
> > input.xml and stylesheet.xsl.
> > Thank's in advance
> >         Alessandro Marcellini
> >
> > /* PROGRAM BEGIN */
> > import java.io.File;
> > import java.io.FileOutputStream;
> >
> > public class transform
> > {
> >
> >  public static boolean VERBOSE = true;
> > /*
> >    To run program:
> >    tranform fileToTransform.xml stylesheet.xsl output.pdf
> > */
> >  public static void main(String[] argv)
> >  {
> >   try{
> >   String xml = argv[0];
> >   File xslt = new File(argv[1]);
> >   FileOutputStream out = new FileOutputStream(argv[2]);
> >
> >   if(VERBOSE) System.out.println("Instatiate Xerces1.3.0 Parser");
> >   org.apache.xerces.parsers.DOMParser parser = new
> > org.apache.xerces.parsers.DOMParser();
> >   if(VERBOSE) System.out.println("Parse the Input Document");
> >   parser.parse(xml);
> >
> >   if(VERBOSE) System.out.println("Instatiate TransformerFactory for
> > Xalan2.0.0");
> >   javax.xml.transform.TransformerFactory tFactory =
> > javax.xml.transform.TransformerFactory.newInstance();
> >   if(VERBOSE) System.out.println("Instatiate Transformer");
> >   javax.xml.transform.Transformer transformer =
> > tFactory.newTransformer(new
> > javax.xml.transform.stream.StreamSource(xslt));
> >   if(VERBOSE) System.out.println("Instatiate the DOMResult");
> >   javax.xml.transform.dom.DOMResult domResult = new
> > javax.xml.transform.dom.DOMResult();
> >   if(VERBOSE) System.out.println("Transform the Document with the
> > stylesheet");
> >   transformer.transform(new
> > javax.xml.transform.dom.DOMSource(parser.getDocument()), domResult);
> >   if(VERBOSE) System.out.println("getting the DOM Document");
> >   org.w3c.dom.Document doc = (org.w3c.dom.Document) domResult.getNode();
> >
> >   if(VERBOSE) System.out.println("Instatiate Formatter FOP 0.17.0");
> >   org.apache.fop.apps.Driver drv = new org.apache.fop.apps.Driver();
> >   if(VERBOSE) System.out.println("Set Driver Properties");
> >   drv.setRenderer("org.apache.fop.render.pdf.PDFRenderer",
> > org.apache.fop.apps.Version.getVersion());
> >   drv.addElementMapping("org.apache.fop.fo.StandardElementMapping");
> >   drv.addElementMapping("org.apache.fop.svg.SVGElementMapping");
> >   if(VERBOSE) System.out.println("Set Output Stream ");
> >   drv.setOutputStream(out);
> >   if(VERBOSE) System.out.println("Build FO Tree ");
> >   drv.buildFOTree(doc);
> >   if(VERBOSE) System.out.println("Format the document ");
> >   drv.format();
> >   if(VERBOSE) System.out.println("Render the document ");
> >   drv.render();
> >   if(VERBOSE) System.out.println("Close OutputStream ");
> >   out.close();
> >
> >   } catch(Exception e)
> >   {
> >    System.err.println("Errore: " + e.getMessage());
> >    e.printStackTrace();
> >   }
> >  }
> > }
> >
> > /* PROBRAM END */
> >
> > /* INPUT FILE  */
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <rowset>
> >   <row>
> >     <field1>F1R1</field1>
> >     <field2>F2R1</field2>
> >     <field3>F3R1</field3>
> >     <field4>F4R1</field4>
> >   </row>
> >   <row>
> >     <field1>F1R2</field1>
> >     <field2>F2R2</field2>
> >     <field3>F3R2</field3>
> >     <field4>F4R2</field4>
> >   </row>
> >   <row>
> >     <field1>F1R3</field1>
> >     <field2>F2R3</field2>
> >     <field3>F3R3</field3>
> >     <field4>F4R3</field4>
> >   </row>
> >   <row>
> >     <field1>F1R3</field1>
> >     <field2>F2R3</field2>
> >     <field3>F3R3</field3>
> >     <field4>F4R3</field4>
> >   </row>
> > </rowset>
> >
> > /* END INPUT FILE */
> >
> > /* BEGIN STYLESHEET */
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"
> >                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >                 version="1.0">
> >   <xsl:output method="xml" indent="yes"/>
> >   <xsl:template match="/">
> >   <fo:root>
> >    <xsl:call-template name="master"/>
> >    <!-- starts actual layout -->
> >    <fo:page-sequence master-name="first">
> >     <fo:flow flow-name="xsl-region-body">
> >      <xsl:apply-templates />
> >     </fo:flow>
> >    </fo:page-sequence>
> >   </fo:root>
> >   </xsl:template>
> >
> >  <xsl:template match="rowset">
> >   <!-- table start -->
> >   <fo:table>
> >        <fo:table-column column-width="50mm"/>
> >        <fo:table-column column-width="50mm"/>
> >        <fo:table-column column-width="50mm"/>
> >        <fo:table-column column-width="50mm"/>
> >        <fo:table-column column-width="50mm"/>
> >        <fo:table-body>
> >     <xsl:apply-templates />
> >        </fo:table-body>
> >   </fo:table>
> >  </xsl:template>
> >
> >  <xsl:template match="row">
> >   <fo:table-row>
> >    <xsl:apply-templates />
> >   </fo:table-row>
> >  </xsl:template>
> >
> >  <xsl:template match="row/*">
> >   <fo:table-cell >
> >    <fo:block>
> >     <xsl:value-of select="."/>
> >    </fo:block>
> >   </fo:table-cell >
> >  </xsl:template>
> >
> >  <xsl:template name="master">
> >   <fo:layout-master-set>
> >    <fo:simple-page-master master-name="first"
> >            page-height="29.7cm"
> >            page-width="21cm"
> >            margin-top="1cm"
> >            margin-bottom="2cm"
> >            margin-left="2.5cm"
> >            margin-right="2.5cm">
> >     <fo:region-body margin-top="3cm"/>
> >     <fo:region-before extent="3cm"/>
> >     <fo:region-after extent="1.5cm"/>
> >    </fo:simple-page-master>
> >   </fo:layout-master-set>
> >  </xsl:template>
> >
> >  <xsl:template name="head">
> >       <!-- this defines a title level 1-->
> >       <fo:block font-size="18pt"
> >             font-family="sans-serif"
> >             line-height="24pt"
> >             space-after.optimum="15pt"
> >             background-color="blue"
> >             color="white"
> >             text-align="center"
> >             padding-top="3pt">
> >         How to use table elements
> >       </fo:block>
> >
> >       <!-- this defines a title level 2-->
> >       <fo:block font-size="16pt"
> >             font-family="sans-serif"
> >             space-after.optimum="15pt"
> >             text-align="center">
> >         A simple table, 3 columns, 4 rows
> >       </fo:block>
> >
> >     <!-- normal text -->
> >     <fo:block text-align="start">this is normal text. this is normal
> > text. this is normal text.
> >                                  this is normal text. this is normal
> > text. this is normal text.
> >     </fo:block>
> >  </xsl:template>
> > </xsl:stylesheet>
> >
> > /* END STYLESHEET */
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> > For additional commands, email: fop-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org


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


Mime
View raw message