Salut à tous

J'ai une petite application Java qui à partir d'un XML et d'un XSL génère un PDF.
L'XSL contient une référence à une image de façon à ce que celle ci soit insérée dans le PDF.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
...
<fo:block>
  <fo:external-graphic src="img/logo.gif"/>
</fo:block>
...
Lorsque j'exécute mon application, pas de problèmes. Mon PDF est correctement généré avec mon image dedans.

Voici le code (C'est juste une classe java nommée Process.java avec une méthode "process" qui s'attends à 2 paramètres: l'XML et le nom du fichier XSL):

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
 
 
public static String process(String xml, String xsl) {
	String sResult = null;
 
	try {
 
		ByteArrayOutputStream foOut = new ByteArrayOutputStream();
 
		ByteArrayOutputStream bOut = new ByteArrayOutputStream();
		InputStream iss = Process.class.getClassLoader().getResourceAsStream(brique);
		copyFile(new BufferedInputStream(iss), bOut);
 
		SAXBuilder builder = new SAXBuilder();
		Document document = builder.build(new ByteArrayInputStream(xml.getBytes()));
 
		TransformerFactory factory = TransformerFactory.newInstance();
		InputStream iXsl = Process.class.getClassLoader().getResourceAsStream(xsl);
		StreamSource iSource = new StreamSource(iXsl);
 
		Transformer foTrans = factory.newTransformer(iSource);
 
		StreamSource strSourceXML = new StreamSource(new ByteArrayInputStream(xml.getBytes()));
		foTrans.transform(strSourceXML, new StreamResult(foOut));
		foOut.flush();
 
		ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
		TransformerFactory tFactoryFO2PDF = TransformerFactory.newInstance();
		Transformer pdfTrans = tFactoryFO2PDF.newTransformer();
		FopFactory fopFactory = FopFactory.newInstance();
		FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
		Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, pdfOut);
		Result res = new SAXResult(fop.getDefaultHandler());
		StreamSource streamSourceXml = new StreamSource(new ByteArrayInputStream(foOut.toByteArray()));
		pdfTrans.transform(streamSourceXml, res);
 
		java.io.File file = new java.io.File("d:/res.pdf");
		FileOutputStream foStream = new FileOutputStream(file);
		pdfOut.writeTo(foStream);			
 
 
	} catch(Exception e) {
		e.printStackTrace();
	}
 
	return sResult;
}
 
private static boolean copyFile(InputStream in, OutputStream out) {
	try {
		int c;
		while ((c = in.read()) != -1)
			out.write(c);
 
		in.close();
		out.close();
	} catch (IOException io) {
		return false;
	}
	return true;
}

J'ai développé un petit web service qui ne fait qu'appeler mon application. Bien sur, le JAR de mon application se trouve dans le classpath de mon webservice.

Le jar de mon application a la structure/contenu suivante:

Name Path
logo.gif img\
Manifest.mf meta-inf\
Process.class tst
saxon-licence.lic
xsl2.xslt


Mon web service n'a qu'une seule classe. Voici son code:

Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
public static String process(String xml, String xsl) {
	String sResult = null;
 
	try {
		sResult = Process.process(xml, xsl);
		System.out.println("sss");
	} catch(Exception e) {
		e.printStackTrace();
	}
	return sResult;
}

Lorsque j'appelle mon webservice je le fait avec les paramètres suivants:

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
 
xml = "<?xml version='1.0' encoding='UTF-8'?>"+
							 "<Catalog>"+
								"<Book>"+
									"<Title>Mastering EJB</Title>"+
									"<Author>Ed Roman</Author>"+
									"<Price>$45.00</Price>"+
								"</Book>"+
								"<Book>"+
									"<Title>Design Patterns</Title>"+
									"<Author>Erich Gamma</Author>"+
									"<Price>$50.00</Price>"+
								"</Book>"+
								"<Book>"+
									"<Title>Effective Java</Title>"+
									"<Author>Josch Bloch</Author>"+
									"<Price>$30.00</Price>"+
								"</Book>" +
							"</Catalog>";
 
et
 
xsl = "xsl2.xslt";
Lorsque j'exécute le web service, le PDF est généré. Le problème c'est qu'il est généré sans l'image.
Dans le log, le message d'erreur est affiché:
"[ERROR] Image not found: img/logo.gif"

J'ai fais le test avec fop 093 et fop 095 avec les mêmes résultats.
J'utilise jdk1.6

Pouvez vous m'aider à trouver d'où provient mon problème?

merci