agreed 
 
with XMLHttpRequest be aware that your response is returned from XMLHttpRequest 
object thru JS function 
identified by onreadystatechange handler attribute e.g.
 
//this assumes you have a valid initialized XMLHttpRequest object called 
xmlHttpRequest and the send was successful
xmlHttpReq.onreadystatechange= function() { 
//check the status of the XMLHttpRequest for complete transfer 
if(xmlHttpRequest.readyState==4) 
{
//now that the reponse is complete check HTTP status
  if (xmlHttpRequest.status==200) 
  {  
  //do normal response stuff here including populating batik dom
  }
}
}
 
http://www.devx.com/webdev/Article/33024/1954

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.



 



To: [email protected]
CC: [email protected]
Subject: Re: Batik and XmlHttpRequest / accessing Batik objects from javascript 
in svg
From: [email protected]
Date: Wed, 29 Sep 2010 06:27:31 -0400

Hi Roland, 

<[email protected]> wrote on 09/17/2010 08:45:30 AM:

> However, I got 2 main problems in getting my existing SVGs run in an
> Applet with JSVGCanvas:
> 
> 1) The Adobe Plugin is currently embedded into an HTML page via the 
> embed-tag. This enables all scripts in the SVGs to access all Html-
> Elements/Javascripts  from the OUTER HTML page and vice versa. That 
> means I can define a Javascript object in a script block on the HTML
> and use it inside the Javascript of the SVG out of the box. Or for 
> example I can get hold of a DIV-Element from the outer HTML page by 
> calling something like
> 
> parent.document.getElementById(<divId>);
> 
> from within javscript inside SVG.
> 
> No discussion on whether this is a good design or concept – fact is,
> that the Javascript in the existing SVGs heavily relies on 
> Javascript blocks and Elements of the surrounding HTML page. My 
> question is: Is there a way to achieve the same effect when using an
> Applet with JSVGCanvas to display the SVGs? Probably not.

        Correct, I don't believe this is possible.  It's only possible in 
Adobe because they can actually run their scripts in the Browsers script 
engine such an option is not AFAIK available for Java. 

> However, I could surpass this by calling a method from my Applet 
> from inside the SVG's Javascript (as I can get hold of Elements of 
> the HTML page from my Applet). The question is: How to access The 
> JSVGCanvas or the Applet object from javascript within SVG? Is there
> a way, maybe via the Rhino engine?

        You will need to a little bit of setup in Java first.  Basically 
you need to bind the Applet and or JSVGCanvas object to a global in 
the JavaScript interpreter.  You can do this by calling 
'getInterpreter(String lang)' (lang should probably be "text/ecmascript") 
on the BridgeContext associated with the JSVGCanvas.  This will give 
you the Interpreter that is being used.  On that object you can call 
'bindObject(String name, Object obj)'. 

        That will bind 'obj' to 'name' as a global in the script environment. 
>From their Rhino does a decent job of exposing Java methods into JavaScript. 

> 2) A related problem is the current communication. Within the Adobe 
> plugin, I can access the browsers XmlHttpRequest object and use it 
> for ajax-like communication from within the SVG. This doesn't work 
> within the Applet with JSVGCanvas. Isn't there something like a 
> lightweight XmlHttpRequest object available in Batik? 

        Check 'getURL', and parseXML, they are generally a decent work 
alike (not quite as flexible). 

> If not, would it be possible to call some Java code from within the SVGs 
> Javascript to build some similar communication and how does this 
> work? Would security settings deny this (can't use signed Applets) 
> if I only would connect to the same server/codedbase? Ajax-like 
> communication within the svg is awesome, it makes the graph/
> workfloweditor quite fast with the Adobe Plugin - this would be a 
> point Batik could really benefit from when it comes to developer and
> customer acceptance!

        As I said above you can expose your own Java methods fairly 
easily.  You are bound by the Applet sandbox (as it Batik) so you 
are restricted in the servers you can connect to (of course you 
should have similar restrictions with XmlHttpRequest). 

Good luck.
                                          

Reply via email to