IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XSL/XSLT/XPATH XML Discussion :

fo:external-graphic dans une servlet [FOP]


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut fo:external-graphic dans une servlet
    Bonjour,

    Je suis en train de créer une application qui transforme un xml en png, via un xsl, le tout dans une servlet utilisant la bibliothèque FOP.

    Je m'arrache les cheveux depuis 2 jours pour intégrer à mon document une image. Cette image est créée par la servlet puis stockée dans un fichier temporaire sur le disque, quelque part.
    En mode test (avec une méthode main) j'arrive à créer le document que je veux. En mode servlet, je n'ai jamais réussi à afficher l'image. Et de plus tout ce qui est censé se trouver après ne s'affiche pas non plus.

    Voici le code Java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    File mapFile = File.createTempFile("mapfile", "");
    // là je mets quelque chose dans mon mapFile
    String path = "file:///" + mapFile.getAbsolutePath().replaceAll("\\\\", "/") + ".png";
    try {
    	String xmlContent = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><root><name>Machin</name>" + 
    		                    "<friend><name>truc_1</name><phNo>" + "truc_2" + "</phNo></friend>" + 
    				    "<path>" + path + "</path>" +
    				    "</root>";
    et voici le xsl :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
     
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.1"
    	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    		xmlns:fo="http://www.w3.org/1999/XSL/Format"
    	exclude-result-prefixes="fo">
    <xsl:template match="root">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page">
          <fo:region-body margin="1in"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
     
      <fo:page-sequence master-reference="my-page">
        <fo:flow flow-name="xsl-region-body">
          <fo:block>Hello, <xsl:value-of select="name" />!</fo:block>
          <fo:block>
          	<fo:table>
          		 <fo:table-body>
          		 	<fo:table-row>
                    	<fo:table-cell border="solid 1px black" text-align="center" font-weight="bold">
                    		<fo:block>No.</fo:block>
                    	</fo:table-cell>
                    	<fo:table-cell border="solid 1px black" text-align="center" font-weight="bold">
                    		<fo:block>Name</fo:block>
                    	</fo:table-cell>
                    	<fo:table-cell border="solid 1px black" text-align="center" font-weight="bold">
                    		<fo:block>Phone Number</fo:block>
                    	</fo:table-cell>
                    </fo:table-row>
                    <xsl:for-each select="./friend">
                    	<fo:table-row>
                    	<fo:table-cell border="solid 1px black" text-align="center">
                    		<fo:block>
                        		<xsl:value-of select="position()" />
                      		</fo:block>
                    	</fo:table-cell>
                    	<fo:table-cell border="solid 1px black" text-align="center">
                    		<fo:block>
                        		<xsl:value-of select="name" />
                      		</fo:block>
                    	</fo:table-cell>
                    	<fo:table-cell border="solid 1px black" text-align="center">
                    		<fo:block>
                        		<xsl:value-of select="phNo" />
                      		</fo:block>
                    	</fo:table-cell>
                    </fo:table-row>
                    </xsl:for-each>
          		 </fo:table-body>
          	</fo:table>
          </fo:block>
          <fo:block>
          <xsl:text> ************ </xsl:text>
          <xsl:value-of select="path" />
          <xsl:text> ************ </xsl:text>
          Voici une image youpi : 
          	<fo:external-graphic width="5cm" src="">
          		<xsl:attribute name="src">
          			<xsl:value-of select="path" />
          		</xsl:attribute>
          	</fo:external-graphic>
          	Et une autre : 
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
    </xsl:template>
    </xsl:stylesheet>
    L'exécution de la servlet me donne l'image suivante
    Nom : Capture_fo.JPG
Affichages : 649
Taille : 18,4 Ko

    Le "path" que j'inclue dans le document (file:/// ...) me renvoie bien vers l'image quand je tape l'adresse dans le navigateur.

    J'ai essayé plusieurs façons de déclarer le src dans la balise fo:external-graphic (en utilisant ur('') notamment) mais rien n'a fonctionné.

    Dans les logs de TomCat, j'ai cette erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    oct. 09, 2015 5:45:07 PM org.apache.fop.fo.FOTreeBuilder fatalError
    Grave: org.xml.sax.SAXParseException; systemId: file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/webapps/s_calac/templates_xsl/test.xsl; lineNumber: 67; columnNumber: 48; java.lang.NullPointerException
    Mais je ne vois vraiment pas quel est le problème, même si je sens bien que ça vient de ce fichu src

    Merci par avance de votre aide

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Il y a quoi à lineNumber: 67; columnNumber: 48;?
    Tu peux montrer comment tu lance ta génération de png, depuis la création du xml jusqu'à la sortie du png?

  3. #3
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    à la ligne incriminée dans les logs de tomCat il y a ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <fo:external-graphic width="5cm" src="">
    Je ne pense pas que ce soit la génération du png qui pose problème (puisque j'arrive bien à afficher le reste de la page). J'ai simplement repris le code exemple de FOP (version 2.0) visible ici : https://svn.apache.org/repos/asf/xml...opServlet.java

    J'ai juste remplacé le MimeConstants.MIME_PDF par MimeConstants.MIME_PNG (et le Content-type du fichier de sortie aussi). En entrée je n'ai pas un fichier xml physique, mais un xml construit à la volée.

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    je retirerais pour commencer ce src vide. Ensuite la servlet que tu pointe ne génère pas de xml comme tu le fais, donc ça ne réponds pas à la question du lien entre la génération du xml contenant l'image et la génération du png. Donc décrit comment tu passe de ces trois ligne de java où tu génère le xml à l'image finale.

  5. #5
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    En fait je ne génère pas de xml, mais seulement un contenu (une chaîne) qui est ensuite lu comme un xml.
    Le "xml" ne contient pas une image mais seulement le chemin.

    J'ai essayé sans le src="", mais sans succès.


    Voici ma classe java complète :
    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    package fr.ign.calac.s_calac.controller;
     
    import [...];
    public class GenerateSampleServlet extends BaseHttpServlet {
     
     
    	private static final long serialVersionUID = -908918093488215264L;
     
        /** The TransformerFactory used to create Transformer instances */
        protected TransformerFactory transFactory;
        /** The FopFactory used to create Fop instances */
        protected FopFactory fopFactory = null;
        /** URIResolver for use by this servlet */
        protected transient URIResolver uriResolver;
     
        @Override
        public void init() throws ServletException {
    		this.uriResolver = new ServletContextURIResolver(getServletContext());
            this.transFactory = TransformerFactory.newInstance();
            this.transFactory.setURIResolver(this.uriResolver);
            //Configure FopFactory as desired
            // TODO: Double check this behaves properly!!
            ResourceResolver resolver = new ResourceResolver() {
                public OutputStream getOutputStream(URI uri) throws IOException {
                    URL url = getServletContext().getResource(uri.toASCIIString());
                    return url.openConnection().getOutputStream();
                }
     
                public Resource getResource(URI uri) throws IOException {
                    return new Resource(getServletContext().getResourceAsStream(uri.toASCIIString()));
                }
            };
            FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI(), resolver);
            configureFopFactory(builder);
            fopFactory = builder.build();
     
    	}
     
        /**
         * This method is called right after the FopFactory is instantiated and can be overridden
         * by subclasses to perform additional configuration.
         */
        protected void configureFopFactory(FopFactoryBuilder builder) {
            //Subclass and override this method to perform additional configuration
        }
     
    	@Override
        public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    		doPost(request, response);
        }
     
     
    	@Override
        public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    		//Get parameters
    		Map<String,String[]> params = request.getParameterMap();
    		// -> Ici je récupère mes paramètres de requête
            File mapFile = File.createTempFile("mapfile", "");
            // -> là je mets quelque chose dans mon mapFile
            String path = "file:///" + mapFile.getAbsolutePath().replaceAll("\\\\", "/") + ".png";// -> j'ai vérifié en affichant ce chemin : il y a bien un image 
            try {
    	     String xmlContent = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><root><name>Machin</name>" + 
    		                    "<friend><name>truc_1</name><phNo>" + "truc_2" + "</phNo></friend>" + 
    				    "<path>" + path + "</path>" +
    				    "</root>";
     
                 String xsltParam = getServletContext().getRealPath(getServletConfig().getInitParameter("templatesDirectory") + "/test.xsl");
     
                 renderXML(xmlContent, xsltParam, response);
     
            } catch (Exception ex) {
                throw new ServletException(ex);
            }
        }
     
     
     
     
    	/**
         * Converts a String parameter to a JAXP Source object.
         * @param param a String parameter
         * @return Source the generated Source object
         */
        protected Source convertString2Source(String param) {
            Source src;
            try {
                src = uriResolver.resolve(param, null);
            } catch (TransformerException e) {
                src = null;
            }
            if (src == null) {
                src = new StreamSource(new File(param));
            }
            return src;
        }
     
        private void sendPDF(byte[] content, HttpServletResponse response) throws IOException {
     
        	response.setHeader("Content-Type", MimeConstants.MIME_PNG);
        	response.setHeader("Content-Length", String.valueOf(content.length));
            response.setHeader("Content-Disposition", "inline; filename=\"test\"");
            response.getOutputStream().write(content);
            response.getOutputStream().flush();
     
        }
     
        /**
         * Renders an XML file into a PDF file by applying a stylesheet
         * that converts the XML to XSL-FO. The PDF is written to a byte array
         * that is returned as the method's result.
         * @param xml the XML file
         * @param xslt the XSLT file
         * @param response HTTP response object
         * @throws FOPException If an error occurs during the rendering of the
         * XSL-FO
         * @throws TransformerException If an error occurs during XSL
         * transformation
         * @throws IOException In case of an I/O problem
         */
        protected void renderXML(String xml, String xslt, HttpServletResponse response)
                    throws FOPException, TransformerException, IOException {
     
            //Setup sources
            //Source xmlSrc = convertString2Source(xml);
        	Source xmlSrc = new StreamSource(new StringReader(xml));
            Source xsltSrc = convertString2Source(xslt);
     
            //Setup the XSL transformation
            Transformer transformer = this.transFactory.newTransformer(xsltSrc);
            transformer.setURIResolver(this.uriResolver);
     
            //Start transformation and rendering process
            render(xmlSrc, transformer, response);
        }
     
        /**
         * Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP
         * transformer given to optionally transform the input document to XSL-FO.
         * The transformer may be an identity transformer in which case the input
         * must already be XSL-FO. The PDF is written to a byte array that is
         * returned as the method's result.
         * @param src Input XML or XSL-FO
         * @param transformer Transformer to use for optional transformation
         * @param response HTTP response object
         * @throws FOPException If an error occurs during the rendering of the
         * XSL-FO
         * @throws TransformerException If an error occurs during XSL
         * transformation
         * @throws IOException In case of an I/O problem
         */
        protected void render(Source src, Transformer transformer, HttpServletResponse response)
                    throws FOPException, TransformerException, IOException {
     
            FOUserAgent foUserAgent = getFOUserAgent();
     
            //Setup output
            ByteArrayOutputStream out = new ByteArrayOutputStream();
     
            //Setup FOP
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG, foUserAgent, out);
     
            //Make sure the XSL transformation's result is piped through to FOP
            Result res = new SAXResult(fop.getDefaultHandler());
     
            //Start the transformation and rendering process
            transformer.transform(src, res);
     
            //Return the result
            sendPDF(out.toByteArray(), response);
        }
     
        /** @return a new FOUserAgent for FOP */
        protected FOUserAgent getFOUserAgent() {
            FOUserAgent userAgent = fopFactory.newFOUserAgent();
            //Configure foUserAgent as desired
            return userAgent;
        }
     
    }

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu as exactement le même message d'erreur après? :/ Dans ton catch, tu peux ajouter un ex.printStackTrace() que l'on aie la stacktrace complète?

  7. #7
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Oui, il y a seulement le columnNumber qui change (41 au lieu de 48, ce qui correspond pile poil aux caractères retirés !)

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Il faudrait la stacktrace complète, on verrait mieux où se trouve l'erreur au niveau du code. Tu peux l'afficher?

  9. #9
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    J'ai ajouté ex.printStackTrace() mais je n'ai rien de plus dans mes logs. (ou alors je ne sais pas comment afficher les erreurs)
    En fait je n'ai pas d'erreur de servlet. Je n'ai pas non plus d'erreur d'exécution de FOP puisque j'ai bien une image qui est renvoyée.
    Par contre mon document semble s'arrêter à cette balise fo:external-graphic.

  10. #10
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu peux ajouter un EventListener comme ici

    https://xmlgraphics.apache.org/fop/1.1/events.html

    et essayer d'afficher tout ce que tu peux dans le event en cas de error? Genre ceci?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    import org.apache.fop.events.Event;
    import org.apache.fop.events.EventFormatter;
    import org.apache.fop.events.EventListener;
    import org.apache.fop.events.model.EventSeverity;
     
    /** A simple event listener that writes the events to stdout and stderr. */
    public class SysOutEventListener implements EventListener {
     
        /** {@inheritDoc} */
        public void processEvent(Event event) {
            String msg = EventFormatter.format(event);
            EventSeverity severity = event.getSeverity();
            if (severity == EventSeverity.INFO) {
                System.out.println("[INFO ] " + msg);
            } else if (severity == EventSeverity.WARN) {
                System.out.println("[WARN ] " + msg);
                new Exception("WARN").printStackTrace();
            } else if (severity == EventSeverity.ERROR) {
                System.err.println("[ERROR] " + msg);
                new Exception("ERROR").printStackTrace();
            } else if (severity == EventSeverity.FATAL) {
                System.err.println("[FATAL] " + msg);
                new Exception("FATAL").printStackTrace();
            } else {
                assert false;
            }
        }
    }

  11. #11
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Bonjour.

    J'ai ajouté la classe SysOutEventListener et j'affiche les messages dans un fichier de log. Voilà ce que ça écrit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    SysOutEventListener [WARN ] The following feature isn't implemented by Apache FOP, yet: table-layout="auto" (on fo:table) (No context info available)
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [WARN ] Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
    SysOutEventListener [WARN ] Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
    SysOutEventListener [INFO ] Rendered page #1.
    J'ai même rajouté, comme cela est suggéré dans la doc, d'arrêter FOP quand un image n'est pas trouvée (ce qui n'est pas le comportement par défaut).
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if ("org.apache.fop.ResourceEventProducer".equals(
                    event.getEventGroupID())) {
                event.setSeverity(EventSeverity.FATAL);
            } else {
                //ignore all other events (or do something of your choice)
            }
    dans SysOutEventListener

    Mais je n'ai pas plus de message. Ce qui me fais dire que c'est bien la syntaxe du xsl qui pose problème et pas le chemin de l'image.
    L'erreur que j'ai toujours dans les logs TomCat (catalina[...].log) est toujours là, mais elle n'est pas catchée par cette classe SysOutEventListener
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    oct. 09, 2015 5:45:07 PM org.apache.fop.fo.FOTreeBuilder fatalError
    Grave: org.xml.sax.SAXParseException; systemId: file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/webapps/s_calac/templates_xsl/test.xsl; lineNumber: 67; columnNumber: 48; java.lang.NullPointerException

  12. #12
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    En ouvrant mon fichier test.xsl dans un autre éditeur (NotePad++ au lieu d'Eclipse), je m'aperçois que juste avant la balise <xsl:attribute name="src"> j'ai une tabulation au lieu de 4 espaces.
    J'ai lu quelque part sur ce forum ( discussion) que ça pouvait poser problème...
    Je croyais avoir fait le nécessaire au niveau d'Eclipse avant de poster mon message, mais visiblement non.

    J'essaye de modifier le xsl directement dans l'arborescence de mon projet mais à la création du war, Eclipse vient systématiquement modifier mon fichier :-(

    Est-ce que vous pensez que ça peut être la cause de mon problème?

  13. #13
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    ce qu'il faudrait ce serait que tu poste le .fo qui sort après application du XSLT, c'est la seule chose que vois FOP. Ce serait utile de le voir aussi.

  14. #14
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Voilà le .fo qui ressort :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <?xml version="1.0" encoding="UTF-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set><fo:simple-page-master master-name="my-page"><fo:region-body margin="1in"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="my-page"><fo:flow flow-name="xsl-region-body"><fo:block>Hello, shyam!</fo:block><fo:block><fo:table><fo:table-body><fo:table-row><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>No.</fo:block></fo:table-cell><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>Name</fo:block></fo:table-cell><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>Phone Number</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>1</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>cx_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>658718.7240559732</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>2</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>cy_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>6863022.7829199955</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>3</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>composition</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>atab</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>4</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>layers_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>EM40</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>5</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>layout</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>poster-histo1</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>6</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>logoId</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block/></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>7</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>orientation</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>pa</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>8</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>scale_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>35000</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>9</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>size</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>pe</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>10</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>titre1</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block> bb,,</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>11</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>titre2</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block/></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>12</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>traces_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>[]</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>13</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>zoomGP_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>14</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><fo:block> ************ file:///C:/Program Files/Apache Software Foundation/Tomcat 7.0/temp/mapfile589772638615713549.png ************ 
          Voici une image youpi : 
          	<fo:external-graphic max-height="5cm" src="file:///C:/Program Files/Apache Software Foundation/Tomcat 7.0/temp/mapfile589772638615713549.png"/>
          	Et une autre : 
          </fo:block></fo:flow></fo:page-sequence></fo:root>
    Est-ce que ça peut venir des espaces dans le src? Dans mon éditeur, il n'y a que "file:///Crogram" qui est souligné

  15. #15
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    J'ai remplacé dans mon chemin les espaces par des %20.
    J'ai maintenant un fichier fo qui paraît correct
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <?xml version="1.0" encoding="UTF-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set><fo:simple-page-master master-name="my-page"><fo:region-body margin="1in"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="my-page"><fo:flow flow-name="xsl-region-body"><fo:block>Hello, shyam!</fo:block><fo:block><fo:table><fo:table-body><fo:table-row><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>No.</fo:block></fo:table-cell><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>Name</fo:block></fo:table-cell><fo:table-cell font-weight="bold" text-align="center" border="solid 1px black"><fo:block>Phone Number</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>1</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>cx_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>658718.7240559732</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>2</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>cy_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>6863022.7829199955</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>3</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>composition</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>atab</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>4</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>layers_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>EM40</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>5</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>layout</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>poster-histo1</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>6</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>logoId</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block/></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>7</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>orientation</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>pa</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>8</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>scale_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>35000</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>9</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>size</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>pe</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>10</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>titre1</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block> bb,,</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>11</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>titre2</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block/></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>12</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>traces_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>[]</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" border="solid 1px black"><fo:block>13</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>zoomGP_string</fo:block></fo:table-cell><fo:table-cell text-align="center" border="solid 1px black"><fo:block>14</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><fo:block> ************ file:///C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/temp/mapfile1647083979915496405.png ************ 
          Voici une image youpi : 
          	<fo:external-graphic max-height="5cm" src="url('file:///C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/temp/mapfile1647083979915496405.png')"/>
          	Et une autre : 
          </fo:block></fo:flow></fo:page-sequence></fo:root>
    J'ai téléchargé FOP en version exécutable et j'ai demandé la conversion de ce .fo en pdf. Et là j'ai bien tout ce qu'il me faut!! Le .fo est bon.
    Donc a priori ça viendrait plutôt de la sortie et de son interprétation par le navigateur?

  16. #16
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Avec la version exécutable, si je demande du png, j'ai bien tout ce qu'il faut!

  17. #17
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    J'ai modifié ma servlet pour qu'à partie des mêmes sources, elle écrive un png en dur sur le disque et qu'elle retourne un OutputStream dont le content-Type est MIME_PNG.
    Et les 2 sorties ne sont pas les mêmes...
    Dans le fichier en dur j'ai tout ce qu'il faut, alors qu'il me manque l'image avec le stream.

    Sans la sortie stream (la servlet ne retourne rien mais écrit un png en dur), je n'ai plus l'erreur de tomCat qui me renvoie à la balise fo:externalGraphic.

  18. #18
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Je n'y comprends plus rien, je pensais faire quelque chose de très simple !

  19. #19
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    désolé, je suis à cours d'idée là. Je ne suis pas non plus toutes les manipulations que tu fais. Dans tous les cas, le PNG mentionné dans src="" doit être accessible au serveur qui fait la transformation. Mais ça n'explique nullement le NullPointerException.

    Tu peux essayer de mettre un breakpoint sur la servlet, puis quand tu rentre dedans, activer un BreakPoint sur les exception de type NullPointerException et voir où ça se déclenche. Avoir la stack de l'exception permettrait de savoir ce qui pose problème.

  20. #20
    Membre à l'essai
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    Oui je vais essayer d'exécuter ma servlet en mode débug pour voir ce qui s'y passe.
    En tout cas merci beaucoup d'avoir suivi mon problème! J'espère pouvoir mettre un "résolu" bientôt...

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [applet]utilser des infos pour les traiter dans une servlet
    Par jeromejanson dans le forum Applets
    Réponses: 5
    Dernier message: 07/03/2010, 23h22
  2. [Struts] Element de formulaire dans une servlet
    Par Adrien09 dans le forum Struts 1
    Réponses: 4
    Dernier message: 17/03/2006, 15h14
  3. Réponses: 2
    Dernier message: 15/02/2006, 17h35
  4. [webservices] heberger un webservices dans une servlet ?
    Par n!co dans le forum Services Web
    Réponses: 14
    Dernier message: 07/12/2005, 14h44
  5. [Session]Récupération d'une session dans une servlet
    Par frizby dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 18/11/2005, 17h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo