You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Xavier Ottolini <xa...@adelis.com> on 2007/01/11 16:30:07 UTC

XSL transformation throws a NullPointerException

Hi,

I want to build a PDF file with a XSL transformation. I use FOP 0.93 on 
Tomcat 4.3 (Windows)
1) I load the XSLT
2) I create a DOM Document
3) I create de DOMSource Element
4) I process the XSL transformation

public ByteArrayOutputStream convertDocumentToPDF(DOMSource source, 
String xsltPath) throws IOException, FOPException, TransformerException, 
Exception {
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired

// Setup output
ByteArrayOutputStream out = new ByteArrayOutputStream();

try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
//Setup Transformer
System.out.println("xsltPath:"+ xsltPath);
File xslFile = new File(xsltPath);
Source xsltSrc = new StreamSource(xslFile);
Transformer transformer = factory.newTransformer(xsltSrc);

// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
if(source == null) throw new Exception("Document DOMSource est null");
// Start XSLT transformation and FOP processing
Line 180 ---> transformer.transform(source, res);
fop = null;
} finally {
out.close();
}
return out;
}

The problem is that ther is an error on the line
transformer.transform(source, res);

Here is the detail of the error message
java.lang.NullPointerException at 
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java: 416)
at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
at 
org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler.java:192)
at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1224)
at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:668)
at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129)
at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107)
at 
com.adelis.roederer.fop.DecompteSante.convertDocumentToPDF(DecompteSante.java:180)

I looked at the source of the endDocument method of the AreaTreeHandler 
class. I did not understant why is the Exception thrown :
/**
* End the document.
*
* @throws SAXException if there is some error
*/
public void endDocument() throws SAXException {

finishPrevPageSequence(null);
// process fo:bookmark-tree
Line 416 : --> BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();

Has anybody any idea ? What is this rootFObj ?

Regards,

Xavier

-- 
Pour préservez l’environnement n’imprimez cet e-mail qu’en cas de nécessité.

Xavier Ottolini
Développeur multimédia

Adelis
37 rue d'Engwiller
67350 La Walck
France
Téléphone : +33 (0) 3 69 20 29 02
Télécopie : +33 (0) 3 88 72 29 19
http://www.adelis.com



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL transformation throws a NullPointerException

Posted by Xavier Ottolini <xa...@adelis.com>.
I finally found the problem :

The there was an error in the DOM document. The root node was not append 
to the document; It was replaced by the first child.

Xavier Ottolini a écrit :
> Hi Adrian ,
> Thank you for your answer.
>
> Here is the XSLT file
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <xsl:template match="/decompte">
>     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
>
>       <fo:layout-master-set>
>         <fo:simple-page-master master-name="decomptes"
>                       page-height="29.7cm"
>                       page-width="21cm"
>                       margin-top="2cm"
>                       margin-bottom="1cm"
>                       margin-left="2.5cm"
>                       margin-right="2.5cm">
>           <fo:region-body margin-top="1cm"  margin-bottom="2cm"/>
>           <fo:region-before region-name="header" extent="3cm"/>
>           <fo:region-after region-name="footer" extent="1.5cm"/>
>         </fo:simple-page-master>
>       </fo:layout-master-set>
>
>       <fo:page-sequence master-reference="decomptes">
>        <fo:static-content flow-name="footer">
>            <fo:block text-align="right">
>                Page
>                <fo:page-number />/<fo:page-number-citation  
> ref-id="theEnd" />
>            </fo:block>
>         </fo:static-content>
>         <fo:static-content flow-name="header">
>           <fo:block-container height="7cm" width="100%" top="7cm" 
> left="0cm" position="absolute">
>              <fo:block background-color="transparent">
>                <fo:external-graphic src="copie-conforme.svg"  
>                                     content-height="6.7cm"  
>                                     vertical-align="middle" />
>              </fo:block>
>           </fo:block-container>
>         </fo:static-content>
>         <fo:flow flow-name="xsl-region-body">
>
>           <fo:block-container height="6cm" width="6cm" top="0cm" 
> left="0cm" position="absolute">
>              <fo:block font-size="9pt" space-after.optimum="15pt" 
> background-color="transparent">
>
>                 <fo:inline><xsl:value-of select="./assure/ititr" 
> /></fo:inline><fo:inline font-size="4pt" >&#160; 
> </fo:inline><fo:inline><xsl:value-of select="./assure/ipnom" 
> /></fo:inline><fo:inline font-size="4pt" >&#160; 
> </fo:inline><fo:inline><xsl:value-of select="./assure/inom" 
> /></fo:inline>
>
>              </fo:block>
>              <fo:block font-size="9pt" text-align="start">Votre 
> adresse :</fo:block>
> <xsl:if test="./assure/iadr1!=''">
>              <fo:block font-size="9pt" 
> text-align="start"><xsl:value-of select="./assure/iadr1"/></fo:block>
> </xsl:if>
> <xsl:if test="./assure/iadr2!=''">
>              <fo:block font-size="9pt" 
> text-align="start"><xsl:value-of select="./assure/iadr2"/></fo:block>
> </xsl:if>
> <xsl:if test="./assure/iadr3!=''">
>              <fo:block font-size="9pt" 
> text-align="start"><xsl:value-of select="./assure/iadr3"/></fo:block>
> </xsl:if>
> <xsl:if test="./assure/iadr4!=''">
>              <fo:block font-size="9pt" 
> text-align="start"><xsl:value-of select="./assure/iadr4"/></fo:block>
> </xsl:if>
> <xsl:if test="./assure/iadr5!=''">
>              <fo:block font-size="9pt" 
> text-align="start"><xsl:value-of select="./assure/iadr5"/></fo:block>
> </xsl:if>
>           </fo:block-container>
>
>           <fo:block-container height="5cm" width="6cm" top="0cm" 
> left="6.5cm" position="absolute" background-color="transparent">
>              <fo:block font-size="9pt" text-align="start">N&#176; 
> d'adh&#233;sion : <xsl:value-of select="./assure/iadh"/></fo:block>
>              <fo:block font-size="9pt" text-align="start" 
> space-after.optimum="15pt">N&#233;<xsl:if 
> test="./assure/ititr='MME'">e</xsl:if><xsl:if 
> test="./assure/ititr='MLE'">e</xsl:if> le <xsl:value-of 
> select="./assure/idtn"/></fo:block>
>              <fo:block font-size="9pt" text-align="start">2, rue 
> Bartisch</fo:block>
>              <fo:block font-size="9pt" text-align="start">67100 
> STRASBOURG</fo:block>
>              <fo:block font-size="9pt" text-align="start">T&#233;l : 
> 03 88 76 73 00</fo:block>
>           </fo:block-container>
>
>           <fo:block-container height="5cm" width="3.5cm" top="0cm" 
> left="12.5cm" position="absolute" background-color="rgb(255,255,255)">
>              <fo:block text-align="end">
>                <fo:external-graphic src="logo-roederer.svg"  
>                                     content-height="2.9cm"  
>                                     vertical-align="middle" />
>              </fo:block>
>           </fo:block-container>
>           <fo:block-container height="7cm" width="100%" top="5cm" 
> left="0cm" position="absolute">
>              <fo:block background-color="transparent">
>                <fo:external-graphic src="copie-conforme.svg"  
>                                     content-height="6.7cm"  
>                                     vertical-align="middle" />
>              </fo:block>
>           </fo:block-container>
>           <fo:block-container height="2cm" width="16cm" top="4cm" 
> left="0cm" position="absolute">
>              <fo:block font-size="9pt" text-align="start">
>
>     D&#233;compte santé n&#176; <xsl:value-of select="./iref"/>.
>
>              </fo:block>
>              <fo:block font-size="9pt" text-align="start">
>
>     D&#233;tail du d&#233;compte pay&#233; le <xsl:value-of 
> select="./idapi"/> d'un montant total de <xsl:value-of 
> select="./imont"/> Euros.
>
>              </fo:block>
>           </fo:block-container>
>            <fo:block space-after.optimum="5.5cm" />
>
>            <fo:table width="100%" table-layout="fixed" 
> background-color="transparent">
>                <fo:table-column column-width="20%" />
>                <fo:table-column column-width="20%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-column column-width="10%" />
>                <fo:table-header  color="rgb(0,0,0)" font-weight="bold">
>                    <fo:table-row>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">B&#233;n&#233;ficiaire</fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Nature des soins</fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Date</fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">D&#233;pense</fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Base de Rembt</fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Rembt CPAM</fo:block>
>                        </fo:table-cell>
>                         <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Rembt Mutuelle</fo:block>
>                        </fo:table-cell>
>                         <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="center">Rembt Roederer</fo:block>
>                        </fo:table-cell>
>                   </fo:table-row>
>                </fo:table-header>
>                <fo:table-body>
> <xsl:apply-templates select="detail/ligne"/>
>               </fo:table-body>
>            </fo:table>
>            <fo:block id="theEnd" />
>         </fo:flow>
>       </fo:page-sequence>
>     </fo:root>
> </xsl:template>
> <xsl:template match="detail/ligne">
>                    <fo:table-row>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt"><xsl:value-of 
> select="ipnom"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt"><xsl:value-of 
> select="iacte"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt"><xsl:value-of 
> select="idsoin"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="right"><xsl:value-of select="idepen"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="right"><xsl:value-of select="itconv"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="right"><xsl:value-of select="ircpam"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="right"><xsl:value-of select="irmutu"/></fo:block>
>                        </fo:table-cell>
>                        <fo:table-cell padding="2pt" border="0.5pt 
> solid black">
>                            <fo:block font-size="8pt" 
> text-align="right"><xsl:value-of select="irroed"/></fo:block>
>                        </fo:table-cell>
>                    </fo:table-row>
> </xsl:template>
> </xsl:stylesheet>
>
>
> Here is the code to create the dom document
>
>
>
>
>    /**
>     * Crée le document DOM
>     * @see com.adelis.roederer.xml.AbstractDocument#getDocument()
>     */
>    public Document getDocument() throws Exception {
>        boolean zeroLigne = true;
>        Document document;
>        DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy", 
> Locale.FRENCH);
>        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
>
>        try {
>            DocumentBuilderFactory factory = 
> DocumentBuilderFactory.newInstance();
>            DocumentBuilder builder = factory.newDocumentBuilder();
>            Document doc = builder.newDocument() ;
>        } catch (javax.xml.parsers.ParserConfigurationException pe) {
>            pe.printStackTrace();
>            throw new Exception("Impossible de créer un document");
>        }
>
>        Node decompte = document.createElement("decompte");
>        Node assure = this.getAssureNode(document);
>        decompte.appendChild(assure);
>        decompte = this.getShortDecompte(document,decompte);
>              Node detail = document.createElement("detail");
>              super.jdbcConnect.executeQuery("SELECT * FROM mytable");
>
>              while(super.jdbcConnect.getResultSet().next()) {
>            Node ligne = document.createElement("ligne");
>            Node iref = document.createElement("iref");
>            Text irefText = 
> document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IREF)); 
>
>            iref.appendChild(irefText);
>            Node ilig = document.createElement("ilig");
>            Text iligText = 
> document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_ILIG)); 
>
>            ilig.appendChild(iligText);
>            Node ipnom = document.createElement("ipnom");
>            Text ipnomText = 
> document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IPNOM)); 
>
>            ipnom.appendChild(ipnomText);
>            Node iacte = document.createElement("iacte");
>            Text iacteText = 
> document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IACTE)); 
>
>            iacte.appendChild(iacteText);
>            Node idsoin = document.createElement("idsoin");
>            Text idsoinText = 
> document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IDSOIN)); 
>
>            idsoin.appendChild(idsoinText);
>            Node idepen = document.createElement("idepen");
>            Text idepenText = 
> document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IDEPEN))); 
>
>            idepen.appendChild(idepenText);
>            Node itconv = document.createElement("itconv");
>            Text itconvText = 
> document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_ITCONV))); 
>
>            itconv.appendChild(itconvText);
>            Node ircpam = document.createElement("ircpam");
>            Text ircpamText = 
> document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRCPAM))); 
>
>            ircpam.appendChild(ircpamText);
>            Node irmutu = document.createElement("irmutu");
>            Text irmutuText = 
> document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRMUTU))); 
>
>            irmutu.appendChild(irmutuText);
>            Node irroed = document.createElement("irroed");
>            Text irroedText = 
> document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRROED))); 
>
>            irroed.appendChild(irroedText);
>            ligne.appendChild(iref);
>            ligne.appendChild(ilig);
>            ligne.appendChild(ipnom);
>            ligne.appendChild(iacte);
>            ligne.appendChild(idsoin);
>            ligne.appendChild(idepen);
>            ligne.appendChild(itconv);
>            ligne.appendChild(ircpam);
>            ligne.appendChild(irmutu);
>            ligne.appendChild(irroed);
>            detail.appendChild(ligne);
>        }
>            if(!zeroLigne) document.appendChild(detail);
>              super.jdbcConnect.closeResultSet();
>        return document;
>    }
>
>    /**
>     * Convertis un objet DOM en une source DOMSource
>     * @return
>     */
>    public DOMSource getDocumentSource() throws Exception {
>        return new DOMSource(this.getDocument());
>    }
>
>
> Adrian Cumiskey a écrit :
>> Hi Xavier,
>>
>> The exception is thrown on this line because of the method call on a 
>> null rootFObj object reference.
>>
>> 416: BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
>>
>> Although not sure why the rootFObj reference is null...
>>
>> I am new to the fop project and still finding my way but will do my 
>> best to find some answers to your problem.
>>
>> Do you have the XSLT source document?
>> Do you have the code creates the DOMSource object and which calls 
>> convertDocumentToPDF?
>> To try and answer your question about the rootFObj.  I believe it 
>> represents and object reference representation of  the parent node 
>> (the fo::root node) of the page sequence node (fo::page-sequence) in 
>> your document.
>>
>> Adrian.
>>
>> Xavier Ottolini wrote:
>>> Hi,
>>>
>>> I want to build a PDF file with a XSL transformation. I use FOP 0.93 
>>> on Tomcat 4.3 (Windows)
>>> 1) I load the XSLT
>>> 2) I create a DOM Document
>>> 3) I create de DOMSource Element
>>> 4) I process the XSL transformation
>>>
>>> public ByteArrayOutputStream convertDocumentToPDF(DOMSource source, 
>>> String xsltPath) throws IOException, FOPException, 
>>> TransformerException, Exception {
>>> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
>>> // configure foUserAgent as desired
>>>
>>> // Setup output
>>> ByteArrayOutputStream out = new ByteArrayOutputStream();
>>>
>>> try {
>>> // Construct fop with desired output format
>>> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
>>>
>>> // Setup XSLT
>>> TransformerFactory factory = TransformerFactory.newInstance();
>>> //Setup Transformer
>>> System.out.println("xsltPath:"+ xsltPath);
>>> File xslFile = new File(xsltPath);
>>> Source xsltSrc = new StreamSource(xslFile);
>>> Transformer transformer = factory.newTransformer(xsltSrc);
>>>
>>> // Resulting SAX events (the generated FO) must be piped through to FOP
>>> Result res = new SAXResult(fop.getDefaultHandler());
>>> if(source == null) throw new Exception("Document DOMSource est null");
>>> // Start XSLT transformation and FOP processing
>>> Line 180 ---> transformer.transform(source, res);
>>> fop = null;
>>> } finally {
>>> out.close();
>>> }
>>> return out;
>>> }
>>>
>>> The problem is that ther is an error on the line
>>> transformer.transform(source, res);
>>>
>>> Here is the detail of the error message
>>> java.lang.NullPointerException at 
>>> org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java: 
>>> 416)
>>> at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
>>> at 
>>> org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler.java:192) 
>>>
>>> at 
>>> org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1224) 
>>>
>>> at 
>>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:668) 
>>>
>>> at 
>>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) 
>>>
>>> at 
>>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107) 
>>>
>>> at 
>>> com.adelis.roederer.fop.DecompteSante.convertDocumentToPDF(DecompteSante.java:180) 
>>>
>>>
>>> I looked at the source of the endDocument method of the 
>>> AreaTreeHandler class. I did not understant why is the Exception 
>>> thrown :
>>> /**
>>> * End the document.
>>> *
>>> * @throws SAXException if there is some error
>>> */
>>> public void endDocument() throws SAXException {
>>>
>>> finishPrevPageSequence(null);
>>> // process fo:bookmark-tree
>>> Line 416 : --> BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
>>>
>>> Has anybody any idea ? What is this rootFObj ?
>>>
>>> Regards,
>>>
>>> Xavier
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>

-- 
Pour préservez l’environnement n’imprimez cet e-mail qu’en cas de nécessité.

Xavier Ottolini
Développeur multimédia

Adelis
37 rue d'Engwiller
67350 La Walck
France
Téléphone : +33 (0) 3 69 20 29 02
Télécopie : +33 (0) 3 88 72 29 19
http://www.adelis.com



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL transformation throws a NullPointerException

Posted by Xavier Ottolini <xa...@adelis.com>.
Hi Adrian ,
Thank you for your answer.

Here is the XSLT file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/decompte">
     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

       <fo:layout-master-set>
         <fo:simple-page-master master-name="decomptes"
                       page-height="29.7cm"
                       page-width="21cm"
                       margin-top="2cm"
                       margin-bottom="1cm"
                       margin-left="2.5cm"
                       margin-right="2.5cm">
           <fo:region-body margin-top="1cm"  margin-bottom="2cm"/>
           <fo:region-before region-name="header" extent="3cm"/>
           <fo:region-after region-name="footer" extent="1.5cm"/>
         </fo:simple-page-master>
       </fo:layout-master-set>

       <fo:page-sequence master-reference="decomptes">
        <fo:static-content flow-name="footer">
            <fo:block text-align="right">
                Page
                <fo:page-number />/<fo:page-number-citation  
ref-id="theEnd" />
            </fo:block>
         </fo:static-content>
         <fo:static-content flow-name="header">
           <fo:block-container height="7cm" width="100%" top="7cm" 
left="0cm" position="absolute">
              <fo:block background-color="transparent">
                <fo:external-graphic src="copie-conforme.svg"  
                                     content-height="6.7cm"  
                                     vertical-align="middle" />
              </fo:block>
           </fo:block-container>
         </fo:static-content>
         <fo:flow flow-name="xsl-region-body">

           <fo:block-container height="6cm" width="6cm" top="0cm" 
left="0cm" position="absolute">
              <fo:block font-size="9pt" space-after.optimum="15pt" 
background-color="transparent">

                 <fo:inline><xsl:value-of select="./assure/ititr" 
/></fo:inline><fo:inline font-size="4pt" >&#160; 
</fo:inline><fo:inline><xsl:value-of select="./assure/ipnom" 
/></fo:inline><fo:inline font-size="4pt" >&#160; 
</fo:inline><fo:inline><xsl:value-of select="./assure/inom" /></fo:inline>

              </fo:block>
              <fo:block font-size="9pt" text-align="start">Votre adresse 
:</fo:block>
<xsl:if test="./assure/iadr1!=''">
              <fo:block font-size="9pt" text-align="start"><xsl:value-of 
select="./assure/iadr1"/></fo:block>
</xsl:if>
<xsl:if test="./assure/iadr2!=''">
              <fo:block font-size="9pt" text-align="start"><xsl:value-of 
select="./assure/iadr2"/></fo:block>
</xsl:if>
<xsl:if test="./assure/iadr3!=''">
              <fo:block font-size="9pt" text-align="start"><xsl:value-of 
select="./assure/iadr3"/></fo:block>
</xsl:if>
<xsl:if test="./assure/iadr4!=''">
              <fo:block font-size="9pt" text-align="start"><xsl:value-of 
select="./assure/iadr4"/></fo:block>
</xsl:if>
<xsl:if test="./assure/iadr5!=''">
              <fo:block font-size="9pt" text-align="start"><xsl:value-of 
select="./assure/iadr5"/></fo:block>
</xsl:if>
           </fo:block-container>

           <fo:block-container height="5cm" width="6cm" top="0cm" 
left="6.5cm" position="absolute" background-color="transparent">
              <fo:block font-size="9pt" text-align="start">N&#176; 
d'adh&#233;sion : <xsl:value-of select="./assure/iadh"/></fo:block>
              <fo:block font-size="9pt" text-align="start" 
space-after.optimum="15pt">N&#233;<xsl:if 
test="./assure/ititr='MME'">e</xsl:if><xsl:if 
test="./assure/ititr='MLE'">e</xsl:if> le <xsl:value-of 
select="./assure/idtn"/></fo:block>
              <fo:block font-size="9pt" text-align="start">2, rue 
Bartisch</fo:block>
              <fo:block font-size="9pt" text-align="start">67100 
STRASBOURG</fo:block>
              <fo:block font-size="9pt" text-align="start">T&#233;l : 03 
88 76 73 00</fo:block>
           </fo:block-container>

           <fo:block-container height="5cm" width="3.5cm" top="0cm" 
left="12.5cm" position="absolute" background-color="rgb(255,255,255)">
              <fo:block text-align="end">
                <fo:external-graphic src="logo-roederer.svg"  
                                     content-height="2.9cm"  
                                     vertical-align="middle" />
              </fo:block>
           </fo:block-container>
           <fo:block-container height="7cm" width="100%" top="5cm" 
left="0cm" position="absolute">
              <fo:block background-color="transparent">
                <fo:external-graphic src="copie-conforme.svg"  
                                     content-height="6.7cm"  
                                     vertical-align="middle" />
              </fo:block>
           </fo:block-container>
           <fo:block-container height="2cm" width="16cm" top="4cm" 
left="0cm" position="absolute">
              <fo:block font-size="9pt" text-align="start">

     D&#233;compte santé n&#176; <xsl:value-of select="./iref"/>.

              </fo:block>
              <fo:block font-size="9pt" text-align="start">

     D&#233;tail du d&#233;compte pay&#233; le <xsl:value-of 
select="./idapi"/> d'un montant total de <xsl:value-of 
select="./imont"/> Euros.

              </fo:block>
           </fo:block-container>
            <fo:block space-after.optimum="5.5cm" />

            <fo:table width="100%" table-layout="fixed" 
background-color="transparent">
                <fo:table-column column-width="20%" />
                <fo:table-column column-width="20%" />
                <fo:table-column column-width="10%" />
                <fo:table-column column-width="10%" />
                <fo:table-column column-width="10%" />
                <fo:table-column column-width="10%" />
                <fo:table-column column-width="10%" />
                <fo:table-column column-width="10%" />
                <fo:table-header  color="rgb(0,0,0)" font-weight="bold">
                    <fo:table-row>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">B&#233;n&#233;ficiaire</fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">Nature des soins</fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">Date</fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">D&#233;pense</fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">Base de Rembt</fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="center">Rembt CPAM</fo:block>
                        </fo:table-cell>
                         <fo:table-cell padding="2pt" border="0.5pt 
solid black">
                            <fo:block font-size="8pt" 
text-align="center">Rembt Mutuelle</fo:block>
                        </fo:table-cell>
                         <fo:table-cell padding="2pt" border="0.5pt 
solid black">
                            <fo:block font-size="8pt" 
text-align="center">Rembt Roederer</fo:block>
                        </fo:table-cell>
                   </fo:table-row>
                </fo:table-header>
                <fo:table-body>
<xsl:apply-templates select="detail/ligne"/>
               </fo:table-body>
            </fo:table>
            <fo:block id="theEnd" />
         </fo:flow>
       </fo:page-sequence>
     </fo:root>
</xsl:template>
<xsl:template match="detail/ligne">
                    <fo:table-row>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt"><xsl:value-of 
select="ipnom"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt"><xsl:value-of 
select="iacte"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt"><xsl:value-of 
select="idsoin"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="right"><xsl:value-of select="idepen"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="right"><xsl:value-of select="itconv"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="right"><xsl:value-of select="ircpam"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="right"><xsl:value-of select="irmutu"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" border="0.5pt solid 
black">
                            <fo:block font-size="8pt" 
text-align="right"><xsl:value-of select="irroed"/></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
</xsl:template>
</xsl:stylesheet>


Here is the code to create the dom document




    /**
     * Crée le document DOM
     * @see com.adelis.roederer.xml.AbstractDocument#getDocument()
     */
    public Document getDocument() throws Exception {
        boolean zeroLigne = true;
        Document document;
        DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy", 
Locale.FRENCH);
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");

        try {
            DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.newDocument() ;
        } catch (javax.xml.parsers.ParserConfigurationException pe) {
            pe.printStackTrace();
            throw new Exception("Impossible de créer un document");
        }

        Node decompte = document.createElement("decompte");
        Node assure = this.getAssureNode(document);
        decompte.appendChild(assure);
        decompte = this.getShortDecompte(document,decompte);
       
        Node detail = document.createElement("detail");
       
        super.jdbcConnect.executeQuery("SELECT * FROM mytable");

       
        while(super.jdbcConnect.getResultSet().next()) {
            Node ligne = document.createElement("ligne");
            Node iref = document.createElement("iref");
            Text irefText = 
document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IREF));
            iref.appendChild(irefText);
            Node ilig = document.createElement("ilig");
            Text iligText = 
document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_ILIG));
            ilig.appendChild(iligText);
            Node ipnom = document.createElement("ipnom");
            Text ipnomText = 
document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IPNOM));
            ipnom.appendChild(ipnomText);
            Node iacte = document.createElement("iacte");
            Text iacteText = 
document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IACTE));
            iacte.appendChild(iacteText);
            Node idsoin = document.createElement("idsoin");
            Text idsoinText = 
document.createTextNode(super.jdbcConnect.getResultSet().getString(CHAMP_IDSOIN));
            idsoin.appendChild(idsoinText);
            Node idepen = document.createElement("idepen");
            Text idepenText = 
document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IDEPEN)));
            idepen.appendChild(idepenText);
            Node itconv = document.createElement("itconv");
            Text itconvText = 
document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_ITCONV)));
            itconv.appendChild(itconvText);
            Node ircpam = document.createElement("ircpam");
            Text ircpamText = 
document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRCPAM)));
            ircpam.appendChild(ircpamText);
            Node irmutu = document.createElement("irmutu");
            Text irmutuText = 
document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRMUTU)));
            irmutu.appendChild(irmutuText);
            Node irroed = document.createElement("irroed");
            Text irroedText = 
document.createTextNode(decimalFormat.format(super.jdbcConnect.getResultSet().getDouble(CHAMP_IRROED)));
            irroed.appendChild(irroedText);
            ligne.appendChild(iref);
            ligne.appendChild(ilig);
            ligne.appendChild(ipnom);
            ligne.appendChild(iacte);
            ligne.appendChild(idsoin);
            ligne.appendChild(idepen);
            ligne.appendChild(itconv);
            ligne.appendChild(ircpam);
            ligne.appendChild(irmutu);
            ligne.appendChild(irroed);
            detail.appendChild(ligne);
        }
   
   
        if(!zeroLigne) document.appendChild(detail);
       
        super.jdbcConnect.closeResultSet();
        return document;
    }

    /**
     * Convertis un objet DOM en une source DOMSource
     * @return
     */
    public DOMSource getDocumentSource() throws Exception {
        return new DOMSource(this.getDocument());
    }


Adrian Cumiskey a écrit :
> Hi Xavier,
>
> The exception is thrown on this line because of the method call on a 
> null rootFObj object reference.
>
> 416: BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
>
> Although not sure why the rootFObj reference is null...
>
> I am new to the fop project and still finding my way but will do my 
> best to find some answers to your problem.
>
> Do you have the XSLT source document?
> Do you have the code creates the DOMSource object and which calls 
> convertDocumentToPDF?
> To try and answer your question about the rootFObj.  I believe it 
> represents and object reference representation of  the parent node 
> (the fo::root node) of the page sequence node (fo::page-sequence) in 
> your document.
>
> Adrian.
>
> Xavier Ottolini wrote:
>> Hi,
>>
>> I want to build a PDF file with a XSL transformation. I use FOP 0.93 
>> on Tomcat 4.3 (Windows)
>> 1) I load the XSLT
>> 2) I create a DOM Document
>> 3) I create de DOMSource Element
>> 4) I process the XSL transformation
>>
>> public ByteArrayOutputStream convertDocumentToPDF(DOMSource source, 
>> String xsltPath) throws IOException, FOPException, 
>> TransformerException, Exception {
>> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
>> // configure foUserAgent as desired
>>
>> // Setup output
>> ByteArrayOutputStream out = new ByteArrayOutputStream();
>>
>> try {
>> // Construct fop with desired output format
>> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
>>
>> // Setup XSLT
>> TransformerFactory factory = TransformerFactory.newInstance();
>> //Setup Transformer
>> System.out.println("xsltPath:"+ xsltPath);
>> File xslFile = new File(xsltPath);
>> Source xsltSrc = new StreamSource(xslFile);
>> Transformer transformer = factory.newTransformer(xsltSrc);
>>
>> // Resulting SAX events (the generated FO) must be piped through to FOP
>> Result res = new SAXResult(fop.getDefaultHandler());
>> if(source == null) throw new Exception("Document DOMSource est null");
>> // Start XSLT transformation and FOP processing
>> Line 180 ---> transformer.transform(source, res);
>> fop = null;
>> } finally {
>> out.close();
>> }
>> return out;
>> }
>>
>> The problem is that ther is an error on the line
>> transformer.transform(source, res);
>>
>> Here is the detail of the error message
>> java.lang.NullPointerException at 
>> org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java: 
>> 416)
>> at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
>> at 
>> org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler.java:192) 
>>
>> at 
>> org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1224) 
>>
>> at 
>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:668) 
>>
>> at 
>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) 
>>
>> at 
>> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107) 
>>
>> at 
>> com.adelis.roederer.fop.DecompteSante.convertDocumentToPDF(DecompteSante.java:180) 
>>
>>
>> I looked at the source of the endDocument method of the 
>> AreaTreeHandler class. I did not understant why is the Exception 
>> thrown :
>> /**
>> * End the document.
>> *
>> * @throws SAXException if there is some error
>> */
>> public void endDocument() throws SAXException {
>>
>> finishPrevPageSequence(null);
>> // process fo:bookmark-tree
>> Line 416 : --> BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
>>
>> Has anybody any idea ? What is this rootFObj ?
>>
>> Regards,
>>
>> Xavier
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>

-- 
Pour préservez l’environnement n’imprimez cet e-mail qu’en cas de nécessité.

Xavier Ottolini
Développeur multimédia

Adelis
37 rue d'Engwiller
67350 La Walck
France
Téléphone : +33 (0) 3 69 20 29 02
Télécopie : +33 (0) 3 88 72 29 19
http://www.adelis.com



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL transformation throws a NullPointerException

Posted by Adrian Cumiskey <ad...@gmail.com>.
Hi Xavier,

The exception is thrown on this line because of the method call on a 
null rootFObj object reference.

416: BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();

Although not sure why the rootFObj reference is null...

I am new to the fop project and still finding my way but will do my best 
to find some answers to your problem.

Do you have the XSLT source document?
Do you have the code creates the DOMSource object and which calls 
convertDocumentToPDF?
To try and answer your question about the rootFObj.  I believe it 
represents and object reference representation of  the parent node (the 
fo::root node) of the page sequence node (fo::page-sequence) in your 
document.

Adrian.

Xavier Ottolini wrote:
> Hi,
>
> I want to build a PDF file with a XSL transformation. I use FOP 0.93 
> on Tomcat 4.3 (Windows)
> 1) I load the XSLT
> 2) I create a DOM Document
> 3) I create de DOMSource Element
> 4) I process the XSL transformation
>
> public ByteArrayOutputStream convertDocumentToPDF(DOMSource source, 
> String xsltPath) throws IOException, FOPException, 
> TransformerException, Exception {
> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
> // configure foUserAgent as desired
>
> // Setup output
> ByteArrayOutputStream out = new ByteArrayOutputStream();
>
> try {
> // Construct fop with desired output format
> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
>
> // Setup XSLT
> TransformerFactory factory = TransformerFactory.newInstance();
> //Setup Transformer
> System.out.println("xsltPath:"+ xsltPath);
> File xslFile = new File(xsltPath);
> Source xsltSrc = new StreamSource(xslFile);
> Transformer transformer = factory.newTransformer(xsltSrc);
>
> // Resulting SAX events (the generated FO) must be piped through to FOP
> Result res = new SAXResult(fop.getDefaultHandler());
> if(source == null) throw new Exception("Document DOMSource est null");
> // Start XSLT transformation and FOP processing
> Line 180 ---> transformer.transform(source, res);
> fop = null;
> } finally {
> out.close();
> }
> return out;
> }
>
> The problem is that ther is an error on the line
> transformer.transform(source, res);
>
> Here is the detail of the error message
> java.lang.NullPointerException at 
> org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java: 
> 416)
> at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
> at 
> org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler.java:192) 
>
> at 
> org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1224) 
>
> at 
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:668) 
>
> at 
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) 
>
> at 
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107) 
>
> at 
> com.adelis.roederer.fop.DecompteSante.convertDocumentToPDF(DecompteSante.java:180) 
>
>
> I looked at the source of the endDocument method of the 
> AreaTreeHandler class. I did not understant why is the Exception thrown :
> /**
> * End the document.
> *
> * @throws SAXException if there is some error
> */
> public void endDocument() throws SAXException {
>
> finishPrevPageSequence(null);
> // process fo:bookmark-tree
> Line 416 : --> BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
>
> Has anybody any idea ? What is this rootFObj ?
>
> Regards,
>
> Xavier
>


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org