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 Ken Larson <ke...@mindspring.com> on 2004/02/01 21:59:40 UTC
Calling Java Code from Script Elements - slightly different q
I have a similar, but slightly different question -
In my case, I'm using the JSVGCanvas in a swing applet, so I don't want
to call an external .jar file, I want to call a method/class that is in
my swing applet (which is of course currently being used to display the
SVG). There must be a way to do this, any pointers?
Ken
mo wrote:
> Hi,
>
> As a newcomer to Batik/SVG development I am having some trouble with
> the following:
>
> How do you call Java code from a SVG document using Batik as opposed
> to using "embedded" Scripting Elements?
>
> ----------------------------------------------------------
>
> My dev. enviroment is as follows:(batik 1.5)
>
> 1) I have a basic SVG which is rendered by *BATIK* in a *JSVGCanvas.*
>
> *<?xml version="1.0"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
> "**http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd**">
> <svg width="500" height="500">*
> **
> *<script type="application/java-archive" xlink:href="svgg.jar"> </script>*
> * *
> *<rect x="109" y="159" width="224" height="95"
> onclick="initializeEventListeners"
> style="fill:rgb(192,192,192);stroke:rgb(0,0,0);stroke-width:1"/>
> *
> *</svg>
> *
>
>
> 2) I have a JAVA class named *SvgInteractor* which *implements*
> *org.w3c.dom.svg.EventListenerInitializer*
> **
> *It has one method *
>
> *initializeEventListeners(SVGDocument doc)*
>
> (It makes a system.out.print() line)
>
> 3) I have created a jar file called *svgg.jar containing
> SvgInteractor.Class file.*
> **
> The manifest of the Jar file contains the following:
>
> *Manifest-Version: 1.0
> SVG-Handler-Class: SvgInteractor*
> **
> *-------------------------------------------------*
>
> When I click on the *rectangle* I get the following *Error*:
>
>
> ReferenceError: "SvgInteractor" is not defined. (<SVG>; line 1)at
> org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597) at
> org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557) at
> org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1076)at
> org.mozilla.javascript.gen.c1.call(<SVG>:1)
>
> at org.mozilla.javascript.gen.c1.exec(<SVG>)
>
> at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown
> Source) at
> org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(Unknown
> Source)
>
> at
> org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEvent(Unknown
> Source)
>
> at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown
> Source)
>
> at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
>
> at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
>
> at
> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unknown
> Source)
>
> at
> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unknown
> Source)
>
> at
> org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(Unknown
> Source)
>
> at
> org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
> Source)
>
> at
> org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
> Source)
>
> at
> org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown
> Source)
>
> at org.apache.batik.gvt.event.AWTEventDispatcher.mouseClicked(Unknown
> Source)
>
> at org.apache.batik.swing.svg.JSVGComponent$22.run(Unknown Source)
>
> at org.apache.batik.util.RunnableQueue.run(Unknown Source)
>
> at java.lang.Thread.run(Unknown Source)
>
> *--------------------------------------------------------------------------------------------*
>
>
> *What is the correct way to call the SvgInteractor Class?*
>
> *how to pass the correct parameters from an SVG document?*
>
> *Any help or Ideas would be greatly appreciated!*
> **
> **
> **
> **
> **
>
>
>
>
>
>
>
> ____________________________________________________
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> /IncrediMail/
> - *Email has finally evolved* - *_Click Here_*
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>
Re: batik applet and security - why?
Posted by Thomas DeWeese <Th...@Kodak.com>.
Ken Larson wrote:
> I am using JSVGCanvas in a swing applet. The URL of my SVG file is in
> the same location as the applet. So therefore in theory, my applet
> should need no special privileges to run, since it can get the SVG file
> using an URL based on the applet's codebase URL. However, I still get a
> security exception. I think the XML processor is trying to read my home
> directory from the system properties or something.
This is correct Xerces asks for your home directory and doesn't
catch the Security exception so it dies. I don't know why Xerces is
looking for your home directory. The good news is that Batik can use
just about any SAX2 XML parser. So the most common solution is to
use crimson, I've also tried picollo (sp?). One of the last versions
of crimson had some namespace issues. Also if you are using JDK 1.4
on your clients it has (a working) crimson built in so you can use
that (also crimson/picollo are a bit faster). Check the archives for
how this can be done.
> Anybody have any suggestions as to how to make a batik applet not
> require special privileges? I can get it to work of course by granting
> my applet special privileges, but this is cumbersome for distribution
> and as far as I know, it should be completely unneccessary.
If you are using Scripting you also need to slightly modify the
JS jar to remove the optimization package (requires class loader).
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
batik applet and security - why?
Posted by Ken Larson <ke...@mindspring.com>.
I am using JSVGCanvas in a swing applet. The URL of my SVG file is in
the same location as the applet. So therefore in theory, my applet
should need no special privileges to run, since it can get the SVG file
using an URL based on the applet's codebase URL. However, I still get a
security exception. I think the XML processor is trying to read my home
directory from the system properties or something.
Anybody have any suggestions as to how to make a batik applet not
require special privileges? I can get it to work of course by granting
my applet special privileges, but this is cumbersome for distribution
and as far as I know, it should be completely unneccessary.
Ken
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: proper way to shut down JSVGCanvas
Posted by ECS Engineering <en...@energycontrolsystems.com>.
Here what my stop() method does:
public void stop()
{
// stop animation timer
// interrupt animation thread
// interrupt status display thread
if (svgCanvas != null)
svgCanvas.stopProcessing();
updateManager = null;
}
then destroy() calls stop().
Stan Dickerson
----- Original Message -----
From: "Ken Larson" <ke...@mindspring.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Monday, February 02, 2004 4:49 AM
Subject: proper way to shut down JSVGCanvas
> I am using JSVGCanvas within a swing applet. I am wondering what is the
> proper way to shut down the svg canvas when my applet stops. While I am
> testing, and constantly restarting my applet, I always get a threaddeath
> exception - and I am pretty sure this is one of the batik threads that
> is getting rudely interrupted.
>
> Ken
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
proper way to shut down JSVGCanvas
Posted by Ken Larson <ke...@mindspring.com>.
I am using JSVGCanvas within a swing applet. I am wondering what is the
proper way to shut down the svg canvas when my applet stops. While I am
testing, and constantly restarting my applet, I always get a threaddeath
exception - and I am pretty sure this is one of the batik threads that
is getting rudely interrupted.
Ken
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: Calling Java Code from Script Elements - slightly different q
Posted by Ken Larson <ke...@mindspring.com>.
Right, but if I don't want this function to be an event listener tied to
a specific event? Basically I have an svg that I use in HTML via that
adobe plugin, and from the svg I can call global functions that are
defined in the HTML. They aren't all event handlers tied to button
clicks and such. So I want to be able to do the same with batik
(running batik in an applet).
Or can I somehow define an event handler, and then explicitly fire the
event from within the SVG script, rather than assigning it to onclick
for some object? This would accomplish the same thing.
Ken
Thomas DeWeese wrote:
> Ken Larson wrote:
>
>> I have a similar, but slightly different question -
>>
>> In my case, I'm using the JSVGCanvas in a swing applet, so I don't
>> want to call an external .jar file, I want to call a method/class
>> that is in my swing applet (which is of course currently being used
>> to display the SVG). There must be a way to do this, any pointers?
>
>
> Search this list for 'addEventListener'.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: Calling Java Code from Script Elements - slightly different q
Posted by Thomas DeWeese <Th...@Kodak.com>.
Ken Larson wrote:
> I have a similar, but slightly different question -
>
> In my case, I'm using the JSVGCanvas in a swing applet, so I don't want
> to call an external .jar file, I want to call a method/class that is in
> my swing applet (which is of course currently being used to display the
> SVG). There must be a way to do this, any pointers?
Search this list for 'addEventListener'.
>
> Ken
>
> mo wrote:
>
>> Hi,
>>
>> As a newcomer to Batik/SVG development I am having some trouble with
>> the following:
>>
>> How do you call Java code from a SVG document using Batik as opposed
>> to using "embedded" Scripting Elements?
>>
>> ----------------------------------------------------------
>>
>> My dev. enviroment is as follows:(batik 1.5)
>>
>> 1) I have a basic SVG which is rendered by *BATIK* in a *JSVGCanvas.*
>>
>> *<?xml version="1.0"?>
>> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
>> "**http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd**">
>> <svg width="500" height="500">*
>> **
>> *<script type="application/java-archive" xlink:href="svgg.jar">
>> </script>*
>> * *
>> *<rect x="109" y="159" width="224" height="95"
>> onclick="initializeEventListeners"
>> style="fill:rgb(192,192,192);stroke:rgb(0,0,0);stroke-width:1"/>
>> *
>> *</svg>
>> *
>>
>>
>> 2) I have a JAVA class named *SvgInteractor* which * implements *
>> *org.w3c.dom.svg.EventListenerInitializer*
>> **
>> *It has one method *
>>
>> * initializeEventListeners(SVGDocument doc) *
>>
>> (It makes a system.out.print() line)
>>
>> 3) I have created a jar file called *svgg.jar containing
>> SvgInteractor.Class file.*
>> **
>> The manifest of the Jar file contains the following:
>>
>> *Manifest-Version: 1.0
>> SVG-Handler-Class: SvgInteractor*
>> **
>> *-------------------------------------------------*
>>
>> When I click on the *rectangle* I get the following *Error*:
>>
>>
>> ReferenceError: "SvgInteractor" is not defined. (<SVG>; line 1)at
>> org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597) at
>> org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557) at
>> org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1076)at
>> org.mozilla.javascript.gen.c1.call(<SVG>:1)
>>
>> at org.mozilla.javascript.gen.c1.exec(<SVG>)
>>
>> at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown
>> Source) at
>> org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(Unknown
>> Source)
>>
>> at
>> org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEvent(Unknown
>> Source)
>>
>> at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown
>> Source)
>>
>> at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
>>
>> at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
>>
>> at
>> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unknown
>> Source)
>>
>> at
>> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unknown
>> Source)
>>
>> at
>> org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(Unknown
>> Source)
>>
>> at
>> org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
>> Source)
>>
>> at
>> org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
>> Source)
>>
>> at
>> org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown
>> Source)
>>
>> at org.apache.batik.gvt.event.AWTEventDispatcher.mouseClicked(Unknown
>> Source)
>>
>> at org.apache.batik.swing.svg.JSVGComponent$22.run(Unknown Source)
>>
>> at org.apache.batik.util.RunnableQueue.run(Unknown Source)
>>
>> at java.lang.Thread.run(Unknown Source)
>>
>> *--------------------------------------------------------------------------------------------*
>>
>>
>> *What is the correct way to call the SvgInteractor Class?*
>>
>> *how to pass the correct parameters from an SVG document?*
>>
>> *Any help or Ideas would be greatly appreciated!*
>> **
>> **
>> **
>> **
>> **
>>
>>
>>
>>
>>
>>
>>
>> ____________________________________________________
>> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> /IncrediMail/
>> - *Email has finally evolved* - * Click Here *
>> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org