You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Mathieu Pedrero <ma...@gmail.com> on 2009/09/02 20:44:04 UTC

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Hi Everybody!

I didn't forget my problem, but i was away from any kind of web connection
for a long time!


> > java.lang.NullPointerException
> >     at
> >
> org.apache.batik.bridge.BridgeContext.getInterpreter(BridgeContext.java:566)
> [...]
> > And it's when i try to display the previewDocument into any JSVGCanvas
> that
> > I get my Exception. The exception is thrown even if I skip the
> > serialization/deserialization step.
>
> This still suggests missing jar files. Note that not only "js.jar" is
> required but also the ones that this one depends upon. Please double
> check your environment (classpath/includes) comparing with the
> dependency graph [1].
>
>
I double-checked my classpath, and every one (i say everyone; the white
ones, the light blue ones, and the dark ones) of the different libraries of
the dependency graph are present in my class path.


>
> > I apologize for aving writen earlier that the documents were the sames in
> > the two case: I thought it realy was the case, because it was working
> good
> > with documents without JavaScript.
>
> That's why you should avoid replacing a clear, detailed explanation
> with (one or more) assumptions [2]. Of course a guess usually won't
> hurt (when the rest is provided). :-)
>
>
>
I'll try to write you a little script in order to show precisely the problem
(whithout any assuptions). But, waiting for it, can you help me, please,
whith the DOMUtilities.parseXML method? I'm not very comfortable using this
method (and the correct parameters to feed it), and the Batik Javadoc
doesn't help me very much.

Thanks a lot!

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Posted by th...@kodak.com.
Hi Mathieu,

> 2009/9/3 <th...@kodak.com>
>>     Can I suggest, you use the following instead: 
>> 
>>          Document document2 = (Document) 
DOMUtilities.parseXML(documentString,null, 
>>                jfc.getSelectedFile().toURI().toString(),null,null,f);
>> 
>>     This will ensure the document as a 'base URI' associated with it 
>> in case it needs to resolve relative URL's. 

Mathieu Pedrero <ma...@gmail.com> wrote on 09/03/2009 08:32:21 
AM:

> Thanks: This modification resolve my problem in the case of the code
> of my precedent message...
> 
> But let's wonder... If I call the DOMUtilities.parseXML method to 
> build a document from a String which has not any URI?

   Actually, in this case I don't think it matters what URL you give it as
long as it's a 'valid' URL (i.e. you can parse it). 

Can you try the following patch to see if the original code 
(w/o the URL works)?

Index: sources/org/apache/batik/script/InterpreterPool.java
===================================================================
--- sources/org/apache/batik/script/InterpreterPool.java        (revision 
810866)
+++ sources/org/apache/batik/script/InterpreterPool.java        (working 
copy)
@@ -116,12 +116,13 @@
 
         Interpreter interpreter = null;
         SVGOMDocument svgDoc = (SVGOMDocument) document;
+        URL url = null;
         try {
-            URL url = new URL(svgDoc.getDocumentURI());
-            interpreter = factory.createInterpreter(url, 
svgDoc.isSVG12(),
-                                                    imports);
+            url = new URL(svgDoc.getDocumentURI());
         } catch (MalformedURLException e) {
         }
+        interpreter = factory.createInterpreter(url, svgDoc.isSVG12(),
+                                                imports);
 
         if (interpreter == null) return null;

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Posted by Mathieu Pedrero <ma...@gmail.com>.
Hi!

2009/9/3 <th...@kodak.com>

>
> Hi Mathieu,
>
> Mathieu Pedrero <ma...@gmail.com> wrote on 09/03/2009 05:06:55
> AM:
>
> >     public Molasson() {
>
> > // I add this document to the canvas, and the canvas to the panel.
> >         canvas.setDocument(document);
> >         jPanel1.add(canvas);
>
>     It's not likely to be the problem, but it's _much_ better to
> add the canvas to the panel before you set the document on it.
>
> >         String documentString =
> DOMUtilities.getXML(document.getDocumentElement());
> >
> >         Document document2 = (Document)
> DOMUtilities.parseXML(documentString,null,null,null,null,f);
>
>     Can I suggest, you use the following instead:
>
>          Document document2 = (Document)
> DOMUtilities.parseXML(documentString,null,
>
>        jfc.getSelectedFile().toURI().toString(),null,null,f);
>
>     This will ensure the document as a 'base URI' associated with it
> in case it needs to resolve relative URL's.
>
>
Thanks: This modification resolve my problem in the case of the code of my
precedent message...

But let's wonder... If I call the DOMUtilities.parseXML method to build a
document from a String which has not any URI? Here the URI we give to the
method is the one of the file chosen by the JFileChooser, but let's imagine
i wrote a string representing a svg doc on my keabord: What kind of URI
should I give to feed the parseXML method?


> > java.lang.NullPointerException
> >     at org.apache.batik.bridge.BridgeContext.
> > getInterpreter(BridgeContext.java:566)
>
>    Can you send what your version of the Batik Source has at
> BridgeContext.java line 566?
>

It's the following line:
                String[] mimeTypes = interpreter.getMimeTypes();

Thaks for your help!

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Posted by th...@kodak.com.
Hi Mathieu,

Mathieu Pedrero <ma...@gmail.com> wrote on 09/03/2009 05:06:55 
AM:

>     public Molasson() {

> // I add this document to the canvas, and the canvas to the panel.
>         canvas.setDocument(document);
>         jPanel1.add(canvas);

    It's not likely to be the problem, but it's _much_ better to
add the canvas to the panel before you set the document on it.

>         String documentString = 
DOMUtilities.getXML(document.getDocumentElement());
>         
>         Document document2 = (Document) 
DOMUtilities.parseXML(documentString,null,null,null,null,f);

    Can I suggest, you use the following instead:

         Document document2 = (Document) 
DOMUtilities.parseXML(documentString,null,
    jfc.getSelectedFile().toURI().toString(),null,null,f);

    This will ensure the document as a 'base URI' associated with it
in case it needs to resolve relative URL's.

> java.lang.NullPointerException
>     at org.apache.batik.bridge.BridgeContext.
> getInterpreter(BridgeContext.java:566)

   Can you send what your version of the Batik Source has at 
BridgeContext.java line 566?

 

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Posted by Mathieu Pedrero <ma...@gmail.com>.
Hi Everybody!

I created a new project on my IDE, only to make some test about this
problem, and i think I was right when I tought the DOMUtilities to be at the
roots of my problem.

To begin with, I guarante you that all the jar's of the dependency graph of
batik are included to the classpath of my new project:

#############################################
Begining of the code:
Here is the Constructor of a class (extending JFrame), called by the main
method in the Main class of my project. Nothig else is done
#############################################

    public Molasson() {
// This method (created by my IDE) creates and adds jpanel1 and jPanel2 to
the JFrame.
// I dont reprt it's source code, it's not important
        initComponents();

        this.setVisible(true);

        JFileChooser jfc = new JFileChooser();
        jfc.showOpenDialog(this);

//I create my two  test canvas

        JSVGCanvas canvas = new JSVGCanvas(), canvas2 = new JSVGCanvas();

//I set them dynamic

        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas2.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

// I create the document I had to the first canvas

        Document document=null;

        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);

        try {
            document =
f.createDocument(jfc.getSelectedFile().toURI().toString());
        } catch (IOException ex) {
            ex.printStackTrace();
        }

// I add this document to the canvas, and the canvas to the panel.
        canvas.setDocument(document);

        jPanel1.add(canvas);

        JOptionPane jop = new JOptionPane();

// This confirm dialog show itself, and no exception is thrown by my canvas!

        int n = jop.showConfirmDialog(this,"Premier affichage","Stop premier
affichage",jop.INFORMATION_MESSAGE);

// I try to "serialize" an "deserialize" my document (the same) with the
help of the DOMUtilities methods

        String documentString =
DOMUtilities.getXML(document.getDocumentElement());

        Document document2 = (Document)
DOMUtilities.parseXML(documentString,null,null,null,null,f);

//I set the new document to my canvas, and this canvas to the panel!

        canvas2.setDocument(document2);

        jPanel2.add(canvas2);

// The exception (I presented you in my precedent messages) is thrown :(


    }

########################################################"
End of my code
########################################################

When I try to make my document react, on the first canvas, the javascript is
executed. On the second canvas, the following exception is thrown:

########################################################
Exception stack trace
########################################################

java.lang.NullPointerException
    at
org.apache.batik.bridge.BridgeContext.getInterpreter(BridgeContext.java:566)
    at
org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScriptingEnvironment.java:320)
    at
org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(ScriptingEnvironment.java:391)
    at
org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEvent(ScriptingEnvironment.java:1440)
    at
org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:324)
    at
org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:366)
    at
org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:266)
    at
org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1014)
    at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(BridgeEventSupport.java:403)
    at
org.apache.batik.bridge.BridgeEventSupport$Listener.mouseExited(BridgeEventSupport.java:279)
    at
org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(AWTEventDispatcher.java:628)
    at
org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(AWTEventDispatcher.java:518)
    at
org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(AWTEventDispatcher.java:399)
    at
org.apache.batik.gvt.event.AWTEventDispatcher.mouseMoved(AWTEventDispatcher.java:211)
    at
org.apache.batik.swing.svg.JSVGComponent$SVGListener$1MouseMovedRunnable.run(JSVGComponent.java:2261)
    at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:240)
    at java.lang.Thread.run(Thread.java:636)

###########################################################
End of the stack trace
###########################################################

Waiting for your advice, i'll continue tosearch bout this problem on my
side!

thanks a lot!

--
Mathieu Pedrero

Re: Unknown language: text/ecmascript [Precisions inside: problem with DOMUtilities]

Posted by Helder Magalhães <he...@gmail.com>.
Hi Mathieu,


> I'll try to write you a little script in order to show precisely the problem
> (whithout any assuptions).

Great. Being able to easily reproduce always helps a lot.


> But, waiting for it, can you help me, please,
> whith the DOMUtilities.parseXML method? I'm not very comfortable using this
> method (and the correct parameters to feed it), and the Batik Javadoc
> doesn't help me very much.

Maybe the ECMAScript version documentation [1] will help...?

Have you tried crawling through the Batik source code [2] and/or Web
for sample usages of the method? ;-)


> Thanks a lot!

Hope this helps,
 Helder


[1] http://xmlgraphics.apache.org/batik/status.html#ecmascript
[2] http://xmlgraphics.apache.org/batik/download.cgi#Subversion+repository

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