Hi Snapper,

snapper <[EMAIL PROTECTED]> wrote on 01/04/2007 12:20:29 PM:

> How do you run javascript from a jar in SVG?

   The simple answer is use the 'jar:' protocol:
        jar:file:/path/to/the/jar.jar!/path/to/js/in/jar/file.js

   The problem is that you don't know what the 'file:/path/to/the/jar'
(doesn't actually have to be file, but in your case you want it to be)
should be on the client machine.

> I have 300KB of javascript that takes too long (60 sec) to load over SSL 
and
> does not cache so it must reload each time.

   So a couple of suggestions that might help here.  First, have you
tried gzipping the javascript files?  Also if the 300KB is split
across a lot of files it might be faster to put them all in one
large file.  Going completely the other way, you can add 'script' 
elements to the DOM at run time, which might let you modularize
the loading of your 'application'.

> I see that Rhino has a Javascript compiler that is included inside the
> js.jar distributed with Batik. This will compile JS into Java classes. I
> made class files using this command file:
> java -cp js.jar;batik-script.jar;batik-util.jar;batik-bridge.jar
> org.mozilla.javascript.tools.jsc.Main -extends
> org.apache.batik.script.rhino.RhinoInterpreter %1
> I can then make the class files into a Jar and then put the jar into the
> build path for my java app. But I am unable to get the JS to run so far. 
I
> even tried the Packages command in my js. Perhaps this is not the 
correct
> solution.

   Sorry, I don't know.  My guess is that you could add code to your
custom Swing App that would attach the compiled JavaScript to the
document, but to be honest I don't know how to do that.  This would
probably be a nice win for performance as well though, so I would
probably investigate this further.

> I also tried to zip the JS directly into a jar (no compile to class 
files)
> and then tried to reference the jar in the SVG with:
> <script xlink:href="myjs.jar" type="application/java-archive"/> 

  This will only look for 'myjs.jar' at the same location the document
was loaded from (probably not what you want).

> Does anybody out there have a suggestion? Should I be looking at how to
> patch into the Batik source code?

   I think you will need to patch into the Batik source at least a little.
It might be something as simple as writing a Java onload event handler 
that
constructs a script element with an appropriate 'jar:' url (using 
something like: Class.getResource("foo.js") ).

Reply via email to