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 Praveen Nayak <ko...@yahoo.com> on 2007/06/30 09:31:45 UTC

SVG Javascript and HTML DOM

I have the Batik JSVGCanvas loaded inside an applet. This applet is hosted in an html page
  I have a js file that is referenced inside the svg file that the canvas has loaded. Now, I am interested in accessing the HTML DOM inside the SVG Javascript.
  I have read a previous post started by Gang Su "SVG Scripting beyond SVG itself" and I would like to validate my understanding in this forum
  Accessing the Html DOM inside the SVG Javascript is not possible by any direct means. Am I correct here?
  I then tried accessing the HTML document object in the SVG Javascript by writing this method in the applet
  
public Object getDocument(){
 return JSObject.getWindow(this).getMember("document");
}
  After registering the applet with the Rhino engine with the name 'myApplet', I am able to access this document object in the SVG JS. But then, 
  myApplet.getDocument().all
  evaluates to null.
  So, even if I am able to acces the HTML document object, I cannot its properties or call methods on it. Is this understanding right?
  
So, I have now thought of a workaround for this:
  
1. I create a method in the applet called 
  public Object executeMethod(String methodName, Object[] args){
 return JSObject.getWindow(this).call(methodName, args);
}
  2. I register the applet with the RhinoScript engine in one of them JGVTTreeBuilder... methods so that the svg Javascript can access the applet and call the above method.
  3. In the HTML file that contains the applet, I write a method with the above method name that would work on the HTML DOM and return the appropriate value back to the applet, which returns it back to the SVG JavaScript.
  
I am hoping this approach will work, and then I keep writing methods in the HTML javascript to return back exact values I need from the HTML to the SVG Javascript.
  Or is there a better way of doing this?
  Thanks,
Praveen

       
---------------------------------
Got a little couch potato? 
Check out fun summer activities for kids.

Re: SVG Javascript and HTML DOM

Posted by KevinJC <co...@inl.gov>.
I believe I am trying to do the same think you are.  Please let me explain.

I have an html page.  With in the HTML page I have a Object tag that loads
up the SVGViewerApplet.class.  One of the parameters that is passed in to
the object is the svg source file.  When a user clicks on one of the svg
objects as defined in the svg file, say a rectangle, I want to change the
rectangle's fill color.  How do I do that?


-- 
View this message in context: http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a12415122
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: SVG Javascript and HTML DOM

Posted by henrygillam <he...@comcast.net>.
Nevermind - I wasn't aware the HTMLDocument class didn't implement the
Scriptable interface.  I'm going to go ahead and use your method and see
what happens.

Thanks again!
Henry



henrygillam wrote:
> 
> 
> Praveen Nayak-2 wrote:
>> 
>> Hi Henry,
>> 
>> Here is the sort of code that should serve your need.
>> 
>> The areas of interest for you should be:
>> 
>> 1. gvtBuildCompleted function where the registering the applet with the
>> Rhino engine takes place (see the interface you need to implement).
>> 
>> 2. executeMethod which can call methods on the HTML DOM.
>> 
>> So, a sample call to executeMethod from inside the SVG Javascript would
>> be:
>> 
>> applet.executeMethod("getWindow",
>> null).getMember("parent").getMember("location").getMember("protocol")
>> 
>> which would have been parent.location.protocol in the regular HTML Js
>> call.
>> 
>> See if this helps...
>> 
>> Thanks,
>> Praveen
>> 
>> -----Original Message-----
>> From: henrygillam [mailto:henrygillam@comcast.net] 
>> Sent: Friday, August 10, 2007 10:15 PM
>> To: batik-users@xmlgraphics.apache.org
>> Subject: Re: SVG Javascript and HTML DOM
>> 
>> 
>> 
>> 
>> Praveen Nayak-3 wrote:
>>> 
>>> I have the Batik JSVGCanvas loaded inside an applet. This applet is
>> hosted
>>> in an html page
>>>   I have a js file that is referenced inside the svg file that the
>> canvas
>>> has loaded. Now, I am interested in accessing the HTML DOM inside the
>> SVG
>>> Javascript.
>>>   I have read a previous post started by Gang Su "SVG Scripting beyond
>> SVG
>>> itself" and I would like to validate my understanding in this forum
>>>   Accessing the Html DOM inside the SVG Javascript is not possible by
>> any
>>> direct means. Am I correct here?
>>>   I then tried accessing the HTML document object in the SVG
>> Javascript by
>>> writing this method in the applet
>>>   
>>> public Object getDocument(){
>>>  return JSObject.getWindow(this).getMember("document");
>>> }
>>>   After registering the applet with the Rhino engine with the name
>>> 'myApplet', I am able to access this document object in the SVG JS.
>> But
>>> then, 
>>>   myApplet.getDocument().all
>>>   evaluates to null.
>>>   So, even if I am able to acces the HTML document object, I cannot
>> its
>>> properties or call methods on it. Is this understanding right?
>>>   
>>> So, I have now thought of a workaround for this:
>>>   
>>> 1. I create a method in the applet called 
>>>   public Object executeMethod(String methodName, Object[] args){
>>>  return JSObject.getWindow(this).call(methodName, args);
>>> }
>>>   2. I register the applet with the RhinoScript engine in one of them
>>> JGVTTreeBuilder... methods so that the svg Javascript can access the
>>> applet and call the above method.
>>>   3. In the HTML file that contains the applet, I write a method with
>> the
>>> above method name that would work on the HTML DOM and return the
>>> appropriate value back to the applet, which returns it back to the SVG
>>> JavaScript.
>>>   
>>> I am hoping this approach will work, and then I keep writing methods
>> in
>>> the HTML javascript to return back exact values I need from the HTML
>> to
>>> the SVG Javascript.
>>>   Or is there a better way of doing this?
>>>   Thanks,
>>> Praveen
>>> 
>>>        
>>> ---------------------------------
>>> Got a little couch potato? 
>>> Check out fun summer activities for kids.
>>> 
>> 
>> Hi,
>> I'm planning on doing roughly the same thing.  I just started working
>> with
>> Batik and Rhino.  I'm interested as to how you "registered" your applet
>> object so that it is accessible from the javascript within the SVG
>> document
>> the applet, itself, contains.  In other words, I want to know how to
>> pass
>> either the applet object or any object in the applet that was
>> instantiated
>> in the applet so that it is accessible in the javascript of the SVG
>> document.  I've only been able to find people accessing the applet
>> object
>> from javascript when the applet is embedded within the HTML DOM, which,
>> of
>> course, is not the case for me.  
>> 
>> Can anyone help me by giving a detailed explanation of what they used to
>> pass either the applet object or    another object initialized in the
>> applet
>> to the SVG document's ecmascripts?  Specifically, I'm trying to access
>> the
>> HTML DOM through the org.w3c.dom.html.HTMLDocument object grabbed by the
>> applet.  I want the SVG's ecmascripts to take this htmldocument object
>> and
>> manipulate it.  Right now, I can't get a reference to it in the
>> javascript.
>> 
>> Any help would be much appreciated!  I've been working on this way too
>> long. 
>> Thanks so much!
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a120949
>> 60
>> Sent from the Batik - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org 
>> --------------------------------------------------------------------------------
>> Telelogic Lifecycle Solutions: 
>> Helping You Define, Design & Deliver Advanced Systems & Software
>> Learn More at www.telelogic.com 
>> 
>> Praveen Nayak
>> Technical Leader
>> Telelogic India Pvt Ltd
>> #58, 1- 4 HM Towers,
>> Brigade Road,
>> 560 025 Bangalore
>> India
>> 
>> Phone: +91 (80) 419 95800 Ext 327
>> Fax: 
>> Mobile phone: 
>> Praveen.Nayak@telelogic.com
>> http://www.telelogic.com
>> 
>> Telelogic - Requirements-Driven Innovation!
>> -------------------------------------------------------------
>> 
>> 
>> 
>> The information contained in this e-mail, including any attachment or
>> enclosure, is intended only for the person or entity to which it is
>> addressed and may contain confidential material. Any unauthorized use,
>> review, retransmissions, dissemination, copying or other use of this
>> information by persons or entities other than the intended recipient is
>> prohibited.
>> 
>>  
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>> 
> 
> Hi Praveen,
> Thanks for your quick response.  As I said, I'm new at working with batik
> and rhino and am a bit confused as to what I am supposed to do with the
> gvtBuildCompleted method you pointed me to.  Also, I am more interested in
> part number 1 than part number 2 (manipulating the HTML DOM).  I think
> once I get the HTML document object, I won't have much difficulty.  If you
> could further explain the first part, however.
> 
> I don't need a reference to the applet object.  I only need to gain access
> to an object initialized in the java (the HTMLDocument object).  Isn't
> there some container in Rhino in which I can place my object and retrieve
> it from the SVG's javascript?  I know you can create new objects and
> manipulate them in javascript with Rhino, but how do you access and
> manipulate an already existing object?
> 
> I'd really like to avoid changing the source code of batik/rhino and was
> hoping there would already be a method or class that can handle what I'm
> trying to do.
> 
> Thanks again for your help,
> Henry    
> 

-- 
View this message in context: http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a12127515
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: SVG Javascript and HTML DOM

Posted by henrygillam <he...@comcast.net>.

Praveen Nayak-2 wrote:
> 
> Hi Henry,
> 
> Here is the sort of code that should serve your need.
> 
> The areas of interest for you should be:
> 
> 1. gvtBuildCompleted function where the registering the applet with the
> Rhino engine takes place (see the interface you need to implement).
> 
> 2. executeMethod which can call methods on the HTML DOM.
> 
> So, a sample call to executeMethod from inside the SVG Javascript would
> be:
> 
> applet.executeMethod("getWindow",
> null).getMember("parent").getMember("location").getMember("protocol")
> 
> which would have been parent.location.protocol in the regular HTML Js
> call.
> 
> See if this helps...
> 
> Thanks,
> Praveen
> 
> -----Original Message-----
> From: henrygillam [mailto:henrygillam@comcast.net] 
> Sent: Friday, August 10, 2007 10:15 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: Re: SVG Javascript and HTML DOM
> 
> 
> 
> 
> Praveen Nayak-3 wrote:
>> 
>> I have the Batik JSVGCanvas loaded inside an applet. This applet is
> hosted
>> in an html page
>>   I have a js file that is referenced inside the svg file that the
> canvas
>> has loaded. Now, I am interested in accessing the HTML DOM inside the
> SVG
>> Javascript.
>>   I have read a previous post started by Gang Su "SVG Scripting beyond
> SVG
>> itself" and I would like to validate my understanding in this forum
>>   Accessing the Html DOM inside the SVG Javascript is not possible by
> any
>> direct means. Am I correct here?
>>   I then tried accessing the HTML document object in the SVG
> Javascript by
>> writing this method in the applet
>>   
>> public Object getDocument(){
>>  return JSObject.getWindow(this).getMember("document");
>> }
>>   After registering the applet with the Rhino engine with the name
>> 'myApplet', I am able to access this document object in the SVG JS.
> But
>> then, 
>>   myApplet.getDocument().all
>>   evaluates to null.
>>   So, even if I am able to acces the HTML document object, I cannot
> its
>> properties or call methods on it. Is this understanding right?
>>   
>> So, I have now thought of a workaround for this:
>>   
>> 1. I create a method in the applet called 
>>   public Object executeMethod(String methodName, Object[] args){
>>  return JSObject.getWindow(this).call(methodName, args);
>> }
>>   2. I register the applet with the RhinoScript engine in one of them
>> JGVTTreeBuilder... methods so that the svg Javascript can access the
>> applet and call the above method.
>>   3. In the HTML file that contains the applet, I write a method with
> the
>> above method name that would work on the HTML DOM and return the
>> appropriate value back to the applet, which returns it back to the SVG
>> JavaScript.
>>   
>> I am hoping this approach will work, and then I keep writing methods
> in
>> the HTML javascript to return back exact values I need from the HTML
> to
>> the SVG Javascript.
>>   Or is there a better way of doing this?
>>   Thanks,
>> Praveen
>> 
>>        
>> ---------------------------------
>> Got a little couch potato? 
>> Check out fun summer activities for kids.
>> 
> 
> Hi,
> I'm planning on doing roughly the same thing.  I just started working
> with
> Batik and Rhino.  I'm interested as to how you "registered" your applet
> object so that it is accessible from the javascript within the SVG
> document
> the applet, itself, contains.  In other words, I want to know how to
> pass
> either the applet object or any object in the applet that was
> instantiated
> in the applet so that it is accessible in the javascript of the SVG
> document.  I've only been able to find people accessing the applet
> object
> from javascript when the applet is embedded within the HTML DOM, which,
> of
> course, is not the case for me.  
> 
> Can anyone help me by giving a detailed explanation of what they used to
> pass either the applet object or    another object initialized in the
> applet
> to the SVG document's ecmascripts?  Specifically, I'm trying to access
> the
> HTML DOM through the org.w3c.dom.html.HTMLDocument object grabbed by the
> applet.  I want the SVG's ecmascripts to take this htmldocument object
> and
> manipulate it.  Right now, I can't get a reference to it in the
> javascript.
> 
> Any help would be much appreciated!  I've been working on this way too
> long. 
> Thanks so much!
> 
> -- 
> View this message in context:
> http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a120949
> 60
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org 
> --------------------------------------------------------------------------------
> Telelogic Lifecycle Solutions: 
> Helping You Define, Design & Deliver Advanced Systems & Software
> Learn More at www.telelogic.com 
> 
> Praveen Nayak
> Technical Leader
> Telelogic India Pvt Ltd
> #58, 1- 4 HM Towers,
> Brigade Road,
> 560 025 Bangalore
> India
> 
> Phone: +91 (80) 419 95800 Ext 327
> Fax: 
> Mobile phone: 
> Praveen.Nayak@telelogic.com
> http://www.telelogic.com
> 
> Telelogic - Requirements-Driven Innovation!
> -------------------------------------------------------------
> 
> 
> 
> The information contained in this e-mail, including any attachment or
> enclosure, is intended only for the person or entity to which it is
> addressed and may contain confidential material. Any unauthorized use,
> review, retransmissions, dissemination, copying or other use of this
> information by persons or entities other than the intended recipient is
> prohibited.
> 
>  
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 

Hi Praveen,
Thanks for your quick response.  As I said, I'm new at working with batik
and rhino and am a bit confused as to what I am supposed to do with the
gvtBuildCompleted method you pointed me to.  Also, I am more interested in
part number 1 than part number 2 (manipulating the HTML DOM).  I think once
I get the HTML document object, I won't have much difficulty.  If you could
further explain the first part, however.

I don't need a reference to the applet object.  I only need to gain access
to an object initialized in the java (the HTMLDocument object).  Isn't there
some container in Rhino in which I can place my object and retrieve it from
the SVG's javascript?  I know you can create new objects and manipulate them
in javascript with Rhino, but how do you access and manipulate an already
existing object?

I'd really like to avoid changing the source code of batik/rhino and was
hoping there would already be a method or class that can handle what I'm
trying to do.

Thanks again for your help,
Henry    
-- 
View this message in context: http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a12096063
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: SVG Javascript and HTML DOM

Posted by Praveen Nayak <Pr...@telelogic.com>.
Hi Henry,

Here is the sort of code that should serve your need.

The areas of interest for you should be:

1. gvtBuildCompleted function where the registering the applet with the
Rhino engine takes place (see the interface you need to implement).

2. executeMethod which can call methods on the HTML DOM.

So, a sample call to executeMethod from inside the SVG Javascript would
be:

applet.executeMethod("getWindow",
null).getMember("parent").getMember("location").getMember("protocol")

which would have been parent.location.protocol in the regular HTML Js
call.

See if this helps...

Thanks,
Praveen

-----Original Message-----
From: henrygillam [mailto:henrygillam@comcast.net] 
Sent: Friday, August 10, 2007 10:15 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: SVG Javascript and HTML DOM




Praveen Nayak-3 wrote:
> 
> I have the Batik JSVGCanvas loaded inside an applet. This applet is
hosted
> in an html page
>   I have a js file that is referenced inside the svg file that the
canvas
> has loaded. Now, I am interested in accessing the HTML DOM inside the
SVG
> Javascript.
>   I have read a previous post started by Gang Su "SVG Scripting beyond
SVG
> itself" and I would like to validate my understanding in this forum
>   Accessing the Html DOM inside the SVG Javascript is not possible by
any
> direct means. Am I correct here?
>   I then tried accessing the HTML document object in the SVG
Javascript by
> writing this method in the applet
>   
> public Object getDocument(){
>  return JSObject.getWindow(this).getMember("document");
> }
>   After registering the applet with the Rhino engine with the name
> 'myApplet', I am able to access this document object in the SVG JS.
But
> then, 
>   myApplet.getDocument().all
>   evaluates to null.
>   So, even if I am able to acces the HTML document object, I cannot
its
> properties or call methods on it. Is this understanding right?
>   
> So, I have now thought of a workaround for this:
>   
> 1. I create a method in the applet called 
>   public Object executeMethod(String methodName, Object[] args){
>  return JSObject.getWindow(this).call(methodName, args);
> }
>   2. I register the applet with the RhinoScript engine in one of them
> JGVTTreeBuilder... methods so that the svg Javascript can access the
> applet and call the above method.
>   3. In the HTML file that contains the applet, I write a method with
the
> above method name that would work on the HTML DOM and return the
> appropriate value back to the applet, which returns it back to the SVG
> JavaScript.
>   
> I am hoping this approach will work, and then I keep writing methods
in
> the HTML javascript to return back exact values I need from the HTML
to
> the SVG Javascript.
>   Or is there a better way of doing this?
>   Thanks,
> Praveen
> 
>        
> ---------------------------------
> Got a little couch potato? 
> Check out fun summer activities for kids.
> 

Hi,
I'm planning on doing roughly the same thing.  I just started working
with
Batik and Rhino.  I'm interested as to how you "registered" your applet
object so that it is accessible from the javascript within the SVG
document
the applet, itself, contains.  In other words, I want to know how to
pass
either the applet object or any object in the applet that was
instantiated
in the applet so that it is accessible in the javascript of the SVG
document.  I've only been able to find people accessing the applet
object
from javascript when the applet is embedded within the HTML DOM, which,
of
course, is not the case for me.  

Can anyone help me by giving a detailed explanation of what they used to
pass either the applet object or    another object initialized in the
applet
to the SVG document's ecmascripts?  Specifically, I'm trying to access
the
HTML DOM through the org.w3c.dom.html.HTMLDocument object grabbed by the
applet.  I want the SVG's ecmascripts to take this htmldocument object
and
manipulate it.  Right now, I can't get a reference to it in the
javascript.

Any help would be much appreciated!  I've been working on this way too
long. 
Thanks so much!

-- 
View this message in context:
http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a120949
60
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org 
--------------------------------------------------------------------------------
Telelogic Lifecycle Solutions: 
Helping You Define, Design & Deliver Advanced Systems & Software
Learn More at www.telelogic.com 

Praveen Nayak
Technical Leader
Telelogic India Pvt Ltd
#58, 1- 4 HM Towers,
Brigade Road,
560 025 Bangalore
India

Phone: +91 (80) 419 95800 Ext 327
Fax: 
Mobile phone: 
Praveen.Nayak@telelogic.com
http://www.telelogic.com

Telelogic - Requirements-Driven Innovation!
-------------------------------------------------------------



The information contained in this e-mail, including any attachment or enclosure, is intended only for the person or entity to which it is addressed and may contain confidential material. Any unauthorized use, review, retransmissions, dissemination, copying or other use of this information by persons or entities other than the intended recipient is prohibited.

Re: SVG Javascript and HTML DOM

Posted by henrygillam <he...@comcast.net>.


Praveen Nayak-3 wrote:
> 
> I have the Batik JSVGCanvas loaded inside an applet. This applet is hosted
> in an html page
>   I have a js file that is referenced inside the svg file that the canvas
> has loaded. Now, I am interested in accessing the HTML DOM inside the SVG
> Javascript.
>   I have read a previous post started by Gang Su "SVG Scripting beyond SVG
> itself" and I would like to validate my understanding in this forum
>   Accessing the Html DOM inside the SVG Javascript is not possible by any
> direct means. Am I correct here?
>   I then tried accessing the HTML document object in the SVG Javascript by
> writing this method in the applet
>   
> public Object getDocument(){
>  return JSObject.getWindow(this).getMember("document");
> }
>   After registering the applet with the Rhino engine with the name
> 'myApplet', I am able to access this document object in the SVG JS. But
> then, 
>   myApplet.getDocument().all
>   evaluates to null.
>   So, even if I am able to acces the HTML document object, I cannot its
> properties or call methods on it. Is this understanding right?
>   
> So, I have now thought of a workaround for this:
>   
> 1. I create a method in the applet called 
>   public Object executeMethod(String methodName, Object[] args){
>  return JSObject.getWindow(this).call(methodName, args);
> }
>   2. I register the applet with the RhinoScript engine in one of them
> JGVTTreeBuilder... methods so that the svg Javascript can access the
> applet and call the above method.
>   3. In the HTML file that contains the applet, I write a method with the
> above method name that would work on the HTML DOM and return the
> appropriate value back to the applet, which returns it back to the SVG
> JavaScript.
>   
> I am hoping this approach will work, and then I keep writing methods in
> the HTML javascript to return back exact values I need from the HTML to
> the SVG Javascript.
>   Or is there a better way of doing this?
>   Thanks,
> Praveen
> 
>        
> ---------------------------------
> Got a little couch potato? 
> Check out fun summer activities for kids.
> 

Hi,
I'm planning on doing roughly the same thing.  I just started working with
Batik and Rhino.  I'm interested as to how you "registered" your applet
object so that it is accessible from the javascript within the SVG document
the applet, itself, contains.  In other words, I want to know how to pass
either the applet object or any object in the applet that was instantiated
in the applet so that it is accessible in the javascript of the SVG
document.  I've only been able to find people accessing the applet object
from javascript when the applet is embedded within the HTML DOM, which, of
course, is not the case for me.  

Can anyone help me by giving a detailed explanation of what they used to
pass either the applet object or    another object initialized in the applet
to the SVG document's ecmascripts?  Specifically, I'm trying to access the
HTML DOM through the org.w3c.dom.html.HTMLDocument object grabbed by the
applet.  I want the SVG's ecmascripts to take this htmldocument object and
manipulate it.  Right now, I can't get a reference to it in the javascript.

Any help would be much appreciated!  I've been working on this way too long. 
Thanks so much!

-- 
View this message in context: http://www.nabble.com/SVG-Javascript-and-HTML-DOM-tf4003995.html#a12094960
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: SVG Javascript and HTML DOM

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Praveen.

Praveen Nayak:
> I have the Batik JSVGCanvas loaded inside an applet. This applet is
> hosted in an html page
>
>   I have a js file that is referenced inside the svg file that the
> canvas has loaded. Now, I am interested in accessing the HTML DOM
> inside the SVG Javascript.

OK.

>   I have read a previous post started by Gang Su "SVG Scripting beyond
> SVG itself" and I would like to validate my understanding in this forum
>
>   Accessing the Html DOM inside the SVG Javascript is not possible by
> any direct means. Am I correct here?

Not without a bit of work on the Java side.

>   I then tried accessing the HTML document object in the SVG
> Javascript by writing this method in the applet
>
> public Object getDocument(){
>  return JSObject.getWindow(this).getMember("document");
> }

>   After registering the applet with the Rhino engine with the name
> 'myApplet', I am able to access this document object in the SVG JS.

Cool.

> But then,
>
>   myApplet.getDocument().all
>   evaluates to null.
>
>   So, even if I am able to acces the HTML document object, I cannot
> its properties or call methods on it. Is this understanding right?

The problem is that the object returned by JSObject.getMember(String) is
another JSObject, and Batik’s use of Rhino doesn’t wrap this object to
provide “normal” JS property access to the object.  Instead, you need to
use the JSObject methods (such as getMember).

> So, I have now thought of a workaround for this:
>   
> 1. I create a method in the applet called 
>   public Object executeMethod(String methodName, Object[] args){
>  return JSObject.getWindow(this).call(methodName, args);
> }
>
> 2. I register the applet with the RhinoScript engine in one of them
> JGVTTreeBuilder... methods so that the svg Javascript can access the
> applet and call the above method.
>
> 3. In the HTML file that contains the applet, I write a method with
> the above method name that would work on the HTML DOM and return the
> appropriate value back to the applet, which returns it back to the SVG
> JavaScript.

That should also work.  But you can work with the JSObject methods from
your SVG’s script, too.

I might look into writing a Rhino wrapper for JSObjects so that access
properties in the normal fashion will work.

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org