Unknown language: text/ecmascript

View: New views
8 Messages — Rating Filter:   Alert me  

Unknown language: text/ecmascript

by Dale Ellis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unknown language: text/ecmascript

I'm new to using Batik, and have been playing around with it today but I'm struggling now and about 3 hours of Googling has not proved fruitful.

I have an SVG file which renders a Gantt chart, this Gantt chart has various JavaScript functions applied to various events hooked to various elements in the SVG document. The SVG is fine I would say, it's used on a project I work on and it renders and behaves fine in Mozilla, Firefox, IE with ASV, Renesis and Chrome frame so I would hope the SVG is not the problem.

So I have reason to create this Gantt chart as a Applet now. Batik seems like it might do the job, so taking the basic example that comes with batik-1.7 I modified the code and came up with this...

package com.btwholesale.wfmt.handlers.gantt;

import java.io.Reader;
import java.io.StringReader;

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.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * A applet demonstrating the JSVGCanvas.
 *
 * @version $Id$
 */
public class BatixGanttApplet extends JApplet {

    protected JSVGCanvas canvas;

    protected Document doc;

    protected Element svg;

    public void init() {
        // Set Applet size
        setSize(ChartData.WIDTH, ChartData.HEIGHT);
       
        // 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);
                       
            GanttSVGXMLHandler gantthandler = new GanttSVGXMLHandler("5YKPG", "HE3");
            Reader reader = new StringReader(gantthandler.returnXML());
           
            doc = f.createDocument("", reader);

            svg = doc.getDocumentElement();
            svg.setAttributeNS(null, "width", String.valueOf(ChartData.WIDTH));
            svg.setAttributeNS(null, "height", String.valueOf(ChartData.HEIGHT));
           
            // Make the text look nice.
            svg.setAttributeNS(null, "text-rendering", "geometricPrecision");
        } catch (Exception ex) {
        }
    }

    public void start() {
        // Display the document.
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.setDocument(doc);
    }

    public void stop() {
        // Remove the document.
        canvas.setDocument(null);
    }

    public void destroy() {
        canvas.dispose();
    }
}

Gantthandler.returnXML is a method that goes off to the database and creates the SVG xml. However, when I run this applet (using Eclipse, all jar files that comes under lib in the batik-1.7 folder) it gives an error instantly, which would appear to be the onload event in my SVG file...

java.lang.Exception: Unknown language: text/ecmascript
        at org.apache.batik.bridge.BridgeContext.getInterpreter(BridgeContext.java:575)
        at org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScriptingEnvironment.java:289)
        at org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScriptingEnvironment.java:285)
        at org.apache.batik.bridge.BaseScriptingEnvironment.dispatchSVGLoad(BaseScriptingEnvironment.java:590)
        at org.apache.batik.bridge.BaseScriptingEnvironment.dispatchSVGLoadEvent(BaseScriptingEnvironment.java:550)
        at org.apache.batik.bridge.UpdateManager.dispatchSVGLoadEvent(UpdateManager.java:239)
        at org.apache.batik.bridge.UpdateManager.dispatchSVGLoadEvent(UpdateManager.java:220)
        at org.apache.batik.swing.svg.SVGLoadEventDispatcher.run(SVGLoadEventDispatcher.java:100)

All other onmouseovers moves etc give similar errors. Now as I mentioned, I am totally new to Batik and I have good J2SE is quite good but I have never work with applets or any swing components either, so im struggling :o(, so some questions...

FYI, im running on SDK 1.5 and the SVG image in the applet renders , it looks spot on.

1) Batik can handle emcascript in SVG and setup events hooked into elements? I guess it can, seems to be firing events in the right places, just fails.

2) Why is it failing? "Unknown language" surely doesn't mean that, the js.jar is on the classpath.
3) Is this even a valid approach I should I be looking to strip out the JavaScript out of the svg xml and then add event listeners in the applet code? Id rather not do this, be nice to be able to use the same SVG code to embed straight into a webpage or use in a Applet without having to tinker with it.

Any help much appreciated as I am a complete novice with Batik.

Thanks,
Dale



Re: Unknown language: text/ecmascript

by Dale Ellis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Expanding this, to simplify the problem, I have reduded code to this...

package com.btwholesale.wfmt.handlers.gantt;

import java.io.Reader;
import java.io.StringReader;

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.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * A applet demonstrating the JSVGCanvas.
 *
 * @version $Id$
 */
public class BatixGanttApplet extends JApplet {

    protected JSVGCanvas canvas;

    protected Document doc;

    protected Element svg;

    public void init() {
    // Set Applet size
    setSize(ChartData.WIDTH, ChartData.HEIGHT);
   
    // 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);
                       
            GanttSVGXMLHandler gantthandler = new GanttSVGXMLHandler("5YKPG", "HE3");
            //Reader reader = new StringReader(gantthandler.returnXML());
            Reader reader = new StringReader("<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n<svg width='100%' height='100%'><rect x='20' y='20' width='300' height='100' style='fill:#DD3000;' onclick='alert(123456789);' /></svg>");
           
            doc = f.createDocument("", reader);

            svg = doc.getDocumentElement();

            // Make the text look nice.
            svg.setAttributeNS(null, "text-rendering", "geometricPrecision");
        } catch (Exception ex) {
        }
    }

    public void start() {
        // Display the document.
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.setDocument(doc);
    }

    public void stop() {
        // Remove the document.
        canvas.setDocument(null);
    }

    public void destroy() {
        canvas.dispose();
    }
   
    public void loadvars() {
    System.out.println("Loading vars...");
    }
}

When I click on the rectangle, I got an error, tried drilling into the stack trace, but didn't get far
 please help

Stack trace...

java.lang.Exception: Unknown language: text/ecmascript
        at org.apache.batik.bridge.BridgeContext.getInterpreter(BridgeContext.java:575)
        at org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScriptingEnvironment.java:289)
        at org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(ScriptingEnvironment.java:385)
        at org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEvent(ScriptingEnvironment.java:1325)
        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:405)
        at org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(BridgeEventSupport.java:341)
        at org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(BridgeEventSupport.java:249)
        at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.processMouseEvent(AbstractAWTEventDispatcher.java:602)
        at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchMouseEvent(AbstractAWTEventDispatcher.java:545)
        at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchEvent(AbstractAWTEventDispatcher.java:387)
        at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.mouseClicked(AbstractAWTEventDispatcher.java:201)
        at org.apache.batik.swing.svg.AbstractJSVGComponent$17.run(AbstractJSVGComponent.java:2107)
        at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:237)
        at java.lang.Thread.run(Unknown Source)


Re: Unknown language: text/ecmascript

by thomas.deweese :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dale,

Dale Ellis <dale.ellis@...> wrote on 10/20/2009 06:50:18 AM:

> Expanding this, to simplify the problem, I have reduded code to this...

     Did you include the resources directory?  In particular the
resources/META-INF/services/org.apache.batik.script.InterpreterFactory
is important for finding the ECMA Script interpreter.


Re: Unknown language: text/ecmascript

by Dale Ellis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thomas.deweese wrote:
Did you include the resources directory?  In particular the
resources/META-INF/services/org.apache.batik.script.InterpreterFactory
is important for finding the ECMA Script interpreter.
Thanks for the reply, I thought no body had replied to this as I never received an email maybe it was blocked, anyway not important.

That file existed in a few JAR files that are on the classpath but that file was not in a resources folder itself. So I have extracted the file from one of the jars. I have a folder called resources already which is on the build path in eclipse and put the file "org.apache.batik.script.InterpreterFactory" in there, that didn't work. So under resources I tried adding directories "META-INF/services" and putting it under there, that also didn't work. Both same error "Unknown language: text/emcascript".

Any ideas? I did mention that the file you mention was in a few of the JAR files, maybe they are causing a conflict with each other, I just added all the jars onto classpath (listed at bottom), maybe I need to remove some? Also how is that file picked up in the Batix code? just a resource bundle? If I knew I could check my code can reference the file.

TIA,
Dale

batik-rasterizer.jar
batik-slideshow.jar
batik-squiggle.jar
batik-svgpp.jar
batik-ttf2svg.jar
batik.jar
batik-rasterizer-ext.jar
batik-squiggle-ext.jar
batik-anim.jar
batik-awt-util.jar
batik-bridge.jar
batik-codec.jar
batik-css.jar
batik-dom.jar
batik-ext.jar
batik-extension.jar
batik-gui-util.jar
batik-gvt.jar
batik-parser.jar
batik-script.jar
batik-svg-dom.jar
batik-svggen.jar
batik-swing.jar
batik-transcoder.jar
batik-util.jar
batik-xml.jar
js.jar
pdf-transcoder.jar
xalan-2.6.0.jar
xerces_2_5_0.jar
xml-apis-ext.jar
xml-apis.jar

Re: Unknown language: text/ecmascript

by thomas.deweese :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dale,

> thomas.deweese wrote:

> > Did you include the resources directory?  In particular the
> > resources/META-INF/services/org.apache.batik.script.InterpreterFactory
> > is important for finding the ECMA Script interpreter.

Dale Ellis <dale.ellis@...> wrote on 11/03/2009 06:18:52 AM:

> Any ideas? I did mention that the file you mention was in a few of the JAR
> files, maybe they are causing a conflict with each other, I just added all
> the jars onto classpath (listed at bottom), maybe I need to remove some?

    I doubt it.

> Also how is that file picked up in the Batik code? just a resource bundle?
> If I knew I could check my code can reference the file.

    The code for Batik to locate the Service Provider is located in
batik.util.Service:
http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/util/Service.java?view=log

    Your best bet would be to add code either in that class or
in batik.script.InterpreterPool to see where things are going wrong.


Re: Unknown language: text/ecmascript

by Dale Ellis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for help Thomas,

I have narrowed it down to this in the Interpreter Pool and its because svgDoc.getDocumentURI() is blank...

    public Interpreter createInterpreter(Document document, String language) {
        InterpreterFactory factory = (InterpreterFactory)factories.get(language);
        if (factory == null) return null;

        Interpreter interpreter = null;
        SVGOMDocument svgDoc = (SVGOMDocument) document;
        try {
            URL url = new URL(svgDoc.getDocumentURI());
            interpreter = factory.createInterpreter(url, svgDoc.isSVG12());
        } catch (MalformedURLException e) {
        }

        if (interpreter == null) return null;

        if (document != null)
            interpreter.bindObject(BIND_NAME_DOCUMENT, document);

        return interpreter;
    }


So why this needed?

If I go back to my code...

        try {
            // Parse the barChart.svg file into a Document.
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
                       
            GanttSVGXMLHandler gantthandler = new GanttSVGXMLHandler("5YKPG", "HE3");
            //Reader reader = new StringReader(gantthandler.returnXML());
            Reader reader = new StringReader("<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n<svg width='100%' height='100%'><rect x='20' y='20' width='300' height='100' style='fill:#DD3000;' onclick='alert(123456789);' /></svg>");
           
            doc = f.createDocument("", reader);

            svg = doc.getDocumentElement();

            // Make the text look nice.
            svg.setAttributeNS(null, "text-rendering", "geometricPrecision");
        } catch (Exception ex) {
        }


I assumed thats picked up from        doc = f.createDocument("", reader);
and it as as if I enter somehting in there, when stepping the code in debug svgDoc.getDocumentURI() has the calue I enter.

What am I supposed to set the URI to when the SVG document is not a physical document on the file system??

Parent Message unknown Re: Unknown language: text/ecmascript

by thomas.deweese :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dale,

Dale Ellis <dale.ellis@...> wrote on 11/05/2009 01:23:31 PM:

> I have narrowed it down to this in the Interpreter Pool and its because
> svgDoc.getDocumentURI() is blank...
>
>             URL url = new URL(svgDoc.getDocumentURI());
>             interpreter = factory.createInterpreter(url, svgDoc.isSVG12());
>
> So why this needed?

    The URL is used to construct the Rhino class loader, and I think
is used for script restrictions.  We should probably support simply
passing null for the URL, but mucking with the security stuff makes me
nervous.

> If I go back to my code...
>             doc = f.createDocument("", reader);

    batik.dom.svg.SVGOMDocument has methods:

    public void setURLObject(URL url);
    public void setParsedURL(ParsedURL url);

   That you can use to set the URL it will use.

> What am I supposed to set the URI to when the SVG document is not a physical
> document on the file system??

     Anything you want to.

Re: Unknown language: text/ecmascript

by Dale Ellis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Thomas for you time,

I have had a little play around with it, I got it working pointing at a dummy svg file I added. However my Gantt chart svg which has alot of script in it didn't like alot of the function calls.

I think I might have to create this dummy SVG with all the script I need in it and maybe that will work, anyway lets of playing around with the code to be done.

Thanks,
Dale