Bonjour,
Je dois faire un import de fichier svg dans une page web (jsp). L’affichage nécessite l’installation d’un plugin et c’est là tout le problème car il ne faut pas qu'on installe de plugin sur le client. J'utilise alors le Framework Batik pour créer un document qui sera affiché par une applet java (à l’aide des canvas : JSVGCanvas).
Tout marche bien jusque là. Le fichier SVG comporte des liens par exemple <a xlink:href="test.html">.
Le problème que j’ai est que les liens fonctionnent très bien quand ils pointent vers des fichiers SVG mais ne marchent pas quand ils pointent vers des pages web (html, jsp).
Malgré la signature de l’applet ca ne fonctionne pas.
J’ai vraiment besoin d’aide sur ce coup car ca fait des jours que je suis dessus.
Merci
le code de mon applet:
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 import java.net.URL; import java.util.logging.Logger; import javax.swing.JApplet; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.util.XMLResourceDescriptor; import org.w3c.dom.Element; import org.w3c.dom.svg.SVGDocument; public class BatikApplet extends JApplet { private static Logger LOG = Logger.getLogger(BatikApplet.class.toString()); protected JSVGCanvas canvas; protected SVGDocument doc; protected Element svg; public void init() { LOG.info("Init Batik applet"); // Create a new JSVGCanvas. canvas = new JSVGCanvas(); getContentPane().add(canvas); try { //Parse the barChart.svg file into a Document. String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); //URL url = new URL(getCodeBase(), "SVGLigneBuilderServlet?goal=svgLigne&resolution=1280x800"); String fileName = "test3.svg"; URL url = new URL(getCodeBase(), fileName); doc = f.createSVGDocument(url.toString()); LOG.info("File " + url.toString() + " has been loaded"); svg = doc.getDocumentElement(); // Make the text look nice. svg.setAttributeNS(null, "text-rendering", "geometricPrecision"); /** // Remove the xml-stylesheet PI. for (Node n = svg.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { doc.removeChild(n); break; } } // Remove the Batik sample mark 'use' element. for (Node n = svg.getLastChild(); n != null; n = n.getPreviousSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE && n.getLocalName().equals("use")) { svg.removeChild(n); break; } } */ } catch (Exception ex) { System.err.println("Exception occured during initialization"); ex.printStackTrace(System.err); } } public void start() { LOG.info("Start Batik applet"); // Display the document. canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); canvas.setSVGDocument(doc); } public void stop() { LOG.info("Stop Batik applet"); // Remove the document. canvas.setSVGDocument(null); } public void destroy() { LOG.info("Destroy Batik applet"); //canvas.dispose(); } }
le code svg
Code svg : 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 <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg width="5cm" height="3cm" viewBox="0 0 5 3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <desc>Exemple link01 - un lien sur une ellipse </desc> <rect x=".01" y=".01" width="4.98" height="2.98" fill="none" stroke="blue" stroke-width=".03"/> <g> <a xlink:href="test.html"> <ellipse cx="2.5" cy="1.5" rx="2" ry="1" fill="red" /> </a> </g> </svg>
fichier html:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <html:html xmlns:html="http://www.w3.org/1999/xhtml" > <html:head> <html:title>Insert title here</html:title> </html:head> <html:body> TEST </html:body> </html:html>
Message d'erreur:
Code erreur : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 java.io.IOException: Root element namespace does not match that requested: Requested: http://www.w3.org/2000/svg Found: http://www.w3.org/1999/xhtml at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:369) at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:200) at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument(SAXSVGDocumentFactory.java:124) at org.apache.batik.bridge.DocumentLoader.loadDocument(DocumentLoader.java:106) at org.apache.batik.swing.svg.SVGDocumentLoader.run(SVGDocumentLoader.java:84)
Partager