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(BaseScri
ptingEnvironment.java:289)
        at
org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScri
ptingEnvironment.java:285)
        at
org.apache.batik.bridge.BaseScriptingEnvironment.dispatchSVGLoad(BaseScr
iptingEnvironment.java:590)
        at
org.apache.batik.bridge.BaseScriptingEnvironment.dispatchSVGLoadEvent(Ba
seScriptingEnvironment.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(SVGLoadEventDispat
cher.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


Reply via email to