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 Thomas DeWeese <Th...@Kodak.com> on 2004/02/02 00:51:52 UTC

Re: Problems Running Java Code from Script Elements

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? 

   Well I must wonder if you don't have your stack trace and example
a little confused - I would have expected you to get a 
'initializeEventListeners' not found error or some such.

   The basic thing is that when you reference a jar file from the
'script' tag the initializeEventListeners method should be called
at 'onload' time.  This method must then use 'addEventListener'
to register objects to receive DOM Events.  You can't use
'event attributes' with Java as there is no 'interpreter'.

    I suspect that the reason your initializeEventListerers method
isn't getting called on load is because the manifest entry must
have the fully qualified class name.  So unless your class is in
the default package 'SvgInteractor' is not fully qualified,
and if it is in the default package - you should try changing
that :)


> ----------------------------------------------------------
>  
> 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