The whole purpose of doing it in this "roundabout" way is to avoid any
dependence on any particular SVG implementation.  Of course, tweaking a
specific SVG implementation would work, but relying on such a tweak would
tend to tie you to that specific SVG implementation, and may force you to
maintain that tweak across all future versions of that implementation.  On
the other hand, if you can find a completely standards-based approach that
is reasonably straightforward, then your code and XML can work on any SVG
implementation that supports the required standardized modules and language
bindings, and would not require any tweaks or maintenance of those tweaks.

You may still have to come up with an ECMAScript and Java framework for
helping to handle messaging in this way, but if it only depends on the
standard DOM and SVG DOM API, it will also be portable.

Having said all that, I'll just say that instead of using this approach
myself, I am now planning to use XForms with SVG (since my time horizon is
long enough).  I expect SVG 1.2 to standardize the way that XForms and SVG
will work together, and I expect that Batik will be incorporated into
X-SMILES shortly (it already has XForms support, and currently uses the
CSIRO SVG engine).  This way, I don't even have to use my own
ECMAScript/Java messaging framework, and I will be able to rely on third
party tools in the future to author my SVG pages (hopefully with no
scripting involved at all).  I can go on about this, but I encourage people
to start looking into how SVG and XForms together might make things easier
for them (for a non-normative look at possibly what such a document would
look like, see
http://www.w3.org/TR/2002/CR-xforms-20021112/sliceG.html#id2642184).  The
SVG working group is preparing its second working draft of SVG 1.2, and one
WG member has told me that he will try to put in that draft more details
about the integration of XForms (and XML Events) into SVG 1.2.

Samuel C. Yang
Echelon Corp. <http://www.echelon.com>

email: <mailto:[EMAIL PROTECTED]>
phone: 408-938-5314
fax: 408-790-3430

> -----Original Message-----
> From: Thomas E Deweese [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, February 12, 2003 6:17 AM
> To: Batik Users
> Cc: [EMAIL PROTECTED]
> Subject: RE: FW: Can I call Javascript function from Batik Java code?
> 
> 
> 
> Hi all,
> 
> Just as an FYI, I'm sure you can call Javascript functions 
> more directly by tracking down the script engine and looking 
> up the function etc.  But I don't have any details on this.  
> Your method is simplier to implement but a bit round about :)
> 
> >>>>> "s" == syang  <[EMAIL PROTECTED]> writes:
> 
> s> Scanning your code, there are two obvious errors.  If you haven't 
> s> already, you should reference the specification for the ECMAScript 
> s> binding to the DOM Level 2 Events API: 
> s> http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html.
> 
> s> The first problem is that you are listening for 
> "MutationEvent" when 
> s> you should be listening for "DOMCharacterDataModified".  The DOM 
> s> Level 2 Events spec is very confusing about which values 
> to use and 
> s> when, so I'm not surprised at this mistake.  Ideally, you 
> should test 
> s> that the current DOM implementation supports the Mutation event 
> s> module before bothering to use my technique, since the 
> listeners will 
> s> otherwise never be called.  For instance:
> 
> s>    if (!document.implementation.hasFeature("MutationEvents",
> s> "2.0")) alert("You need an SVG implementation that supports
> s> MutationEvents!")  else { ... };
> 
> s> The second problem is that you are using the wrong syntax when 
> s> registering you listener.  In ECMAScript, an EventListener 
> is simply 
> s> a reference to a function that has parameter of Event 
> type. So, when 
> s> calling addEventListener(), you need to pass a "reference" 
> to such a 
> s> function.  This is different than when specifying the 
> value of one of 
> s> the onxxx event attributes, in which case you provide the 
> actual code 
> s> to use as the attribute value.  For instance, if you have 
> a function 
> s> called Scroll2 that has just a single parameter of Event 
> type, then 
> s> your last line in item 3. would look like:
> 
> s>   myTextNode.addEventListener("DOMCharacterDataModified", Scroll2, 
> s> false);
> 
> s> Your actual listener function, Scroll, needs the value of 
> the "elt" 
> s> variable, but the definition of EventListener gives you no way to 
> s> pass in that value?  One (bad) way to work around this would be to 
> s> make "elt" a global variable.  Another (more elegant) way 
> would be to 
> s> create a new listener function that calls Scroll, like the
> s> following:
> 
> s>   var Scroll2 = function(e){Scroll(e, elt);};
> 
> s> Or, you can change Scroll() itself to just take an Event parameter.
> 
> s> Samuel C. Yang Echelon Corp. <http://www.echelon.com>
> 
> s> email: <mailto:[EMAIL PROTECTED]> phone: 408-938-5314 fax: 
> s> 408-790-3430
> 
> 
> s> -----Original Message----- From: William Huang 
> s> [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 11, 
> 2003 10:24 
> s> AM To: Batik Users Subject: Re: Can I call Javascript 
> function from 
> s> Batik Java code?
> 
> 
> s> Hi Mr. Yang,
> 
> s> Thank you very much for your suggestion. I tried but can't make it 
> s> work.  Maybe I am wrong somewhere: 1. I created a text 
> node in Batik 
> s> Java SVGOMTextElement text = (SVGOMTextElement) 
> s> doc.createElementNS(svgNs, "text"); text.setAttribute("id", 
> s> "MyTextNode"); text.setAttribute("x", "0"); text.setAttribute("y", 
> s> "0"); text.setAttribute("visibility", "hidden"); 
> s> svgRoot.appendChild(text); 2. When I need to call the Javascript 
> s> function, I fired the following event Element textElement = 
> s> svgDocument.getElementById("MyTextNode"); DocumentEvent de =
> s> (DocumentEvent) svgDocument; MutationEvent ev = 
> s> (MutationEvent)de.createEvent("MutationEvents");
> s> ev.initMutationEvent("DOMCharacterDataModified", true, // 
> s> canBubbleArg false, // cancelableArg null, // 
> relatedNodeArg null, // 
> s> prevValueArg null, // newValueArg null, // attrNameArg 
> ev.ADDITION); 
> s> EventTarget t = (EventTarget) textElement; 
> t.dispatchEvent(ev); 3. In 
> s> Javascript, my code is as follows: var myTextNode = 
> s> document.getElementById("MyTextNode");
> s> myTextNode.addEventListener("MutationEvent", Scroll(evt, elt),
> s> false) Where Scroll(evt, elt) is my Javascript function.
> 
> s> It seems that the code does not work. Could you tell me 
> what is wrong 
> s> with my code?
> 
> s> With best regards, William
> 
> 
> s> ----- Original Message ----- From: <[EMAIL PROTECTED]> To: 
> s> <[EMAIL PROTECTED]> Sent: Monday, February 10, 
> 2003 3:58 PM 
> s> Subject: RE: Can I call Javascript function from Batik Java code?
> 
> 
> >> Here's a method based on the standard (but optional) DOM Event
> >> type, MutationEvents.  It took me a little while to come up with
> >> it, but I'll
> s> give
> >> it to you for free :-).
> >> 
> >> If your SVG processor supports the MutationEvents feature (you
> >> should test for this, especially if you intend to also run on
> >> non-Batik SVG engines), and has the right language bindings to the
> >> DOM (like Batik does) then you can use a <text> element (probably
> >> with visibility="hidden", and width and height="0") to which you
> >> dispatch mutation events from Java, and to which you can attach an
> >> ECMAScript listener.  The new text content specified in the event
> >> data can be used to carry any kind of message you want.  You can
> >> use the same technique to go from ECMAScript to Java, too.
> >> 
> >> Note that:
> >> 
> >> (1) Using dispatchEvent() is more efficient that actually changing
> >> the content of the <text> element.  (2) The <text> element should
> >> not have display="none", since then it is
> s> not
> >> supposed to receive any events.  [However, Batik currently does
> >> allow the dispatchEvent() method to send events to a <text> element
> >> having the display="none" attribute.  I believe this is a bug.
> >> Also, I noticed that
> s> in
> >> Batik when you use the dispatchEvent() method to send a mutation
> >> event for
> s> a
> >> <text> element, the text element does not change its actual
> >> content,
> s> meaning
> >> that the dispatched event is lying about the new (and possibly also
> >> the
> s> old)
> >> content of the element.  This is probably acceptable behavior,
> >> since the spec doesn't seem to say this can't happen, and it is
> >> more efficient.
> s> Just
> >> be sure that you don't accidentally treat the event data for such
> >> <text> elements as being real text event data.]
> >> 
> >> Samuel C. Yang Echelon Corp. <http://www.echelon.com>
> >> 
> >> email: <mailto:[EMAIL PROTECTED]> phone: 408-938-5314 fax:
> >> 408-790-3430
> >> 
> >> > -----Original Message----- > From: William Huang
> >> [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 10, 2003
> >> 11:44 AM > To: Batik Users > Subject: Can I call Javascript
> >> function from Batik Java code?
> >> >
> >> >
> >> > I changed the SVGImageElementBridge program to make the <a>
> >> element > work as my application needs. However, I need to call one
> >> large > Javascript function of mine at the end of my >
> >> createSVGImageNode() method call. I can rewrite the Javascript >
> >> function into Java, but that costs too much efforts. Is there a way
> >> > to call Javascript function from Batik Java implementation?
> >> Thanks a > lot.
> >> >
> >> > William
> >> >
> >> >
> >> > 
> --------------------------------------------------------------------
> >> > -
> >> > To unsubscribe, e-mail: [EMAIL PROTECTED] >
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >> >
> >> 
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED] For
> >> additional commands, e-mail: [EMAIL PROTECTED]
> >> 
> >> 
> 
> 
> s> 
> ---------------------------------------------------------------------
> s> To unsubscribe, e-mail: [EMAIL PROTECTED] For
> s> additional commands, e-mail: [EMAIL PROTECTED]
> 
> s> 
> ---------------------------------------------------------------------
> s> To unsubscribe, e-mail: [EMAIL PROTECTED] For
> s> additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to