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

Applets Java Discussion :

Batik svg applet : problème de lien


Sujet :

Applets Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 4
    Par défaut Batik svg applet : problème de lien
    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)

  2. #2
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 4
    Par défaut
    Personne n'aurait jamais rencontré ce problème avec batik.
    Please i need help

  3. #3
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 4
    Par défaut nouvelle erreur
    J'ai une nouvelle erreur après avoir changé le namespace:

    Code erreur : 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
    java.security.AccessControlException: access denied (java.net.SocketPermission www.w3.org:80 connect,resolve)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkConnect(Unknown Source)
    	at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
    	at sun.net.www.http.HttpClient.openServer(Unknown Source)
    	at sun.net.www.http.HttpClient.<init>(Unknown Source)
    	at sun.net.www.http.HttpClient.New(Unknown Source)
    	at sun.net.www.http.HttpClient.New(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
    	at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
    	at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown Source)
    	at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument(Unknown Source)
    	at org.apache.batik.bridge.DocumentLoader.loadDocument(Unknown Source)
    	at org.apache.batik.swing.svg.SVGDocumentLoader.run(SVGDocumentLoader.java:71)

    Pourtant j'ai bien signé l'applet et changé le java.policy pour donner les droits "connect,resolve,..." à mon applet. Je ne comprends vraiment pas.

  4. #4
    Membre à l'essai
    Inscrit en
    Avril 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 4
    Par défaut Solution
    C'est bon j'ai eu la confirmation que batik(1.7) ne supporte que les liens vers des fichiers SVG. Il a fallu alors intercepté les cliks sur les liens et les traiter soi-même avec eventlistener.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 12/05/2005, 08h16
  2. Problème de lien sur date entre Access et MySQL-4.1
    Par michou42 dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 04/04/2005, 23h31
  3. Problème de lien
    Par D-D dans le forum ASP
    Réponses: 10
    Dernier message: 03/06/2004, 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