xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x.zupf...@web.de
Subject unable to add property to JavaScript node object
Date Mon, 02 Nov 2009 13:22:04 GMT
Hi all,

I asked the following question on the SVG-developers list, but I guess you guys can help me
better:  Why is it impossible to add a property to a DOM node with Batik?  I have the following
test SVG:


<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" onload="init()">
  <script type="text/javascript">
    init = function(){
      testnode = document.getElementById("testnode")
      testnode.myProperty = "test"
      alert(testnode.myProperty)
    }
  </script>
  <rect id="testnode" width="100" height="100" x="150" y="150"/>
</svg>


It works perfectly in Firefox, Opera, IE+ASV and Safari, but Squiggle (Batik 1.8pre+r801641)
gives me the following Java error message:

Java class "org.apache.batik.dom.svg.SVGOMRectElement" has no public instance field or method
named "myProperty". (Inline <script> file:/E:/programmieren/svg/js/js_attribute_to_node_object_4.svg:6#4)

Of course I can't dynamically add a property to a Java object, but this is JavaScript, so
I guess I should be able to add my custom properties.  I initially thought this could be Rhino's
fault, but I threw the exact same script into an HTML document and tested it with Lobo (AFAIK
it uses Rhino as well).  This works as expected:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <script type="text/javascript">
      init = function(){
        testnode = document.getElementById("testnode")
        testnode.myProperty = "test"
        alert(testnode.myProperty)
      }
    </script>
  </head>
  <body onload="init()">
    <p id="testnode">testnode</p>
  </body>
</html>


Why aren't the Java DOM node objects properly wrapped as JavaScript objects?  Is this by purpose
or just a missing feature?

By the way, java -version on Windows XP gives me the following:
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode)

Any info is greatly appreciated
Thomas Weber
________________________________________________________________
DSL-Preisknaller: DSL-Komplettpakete schon für 16,99 Euro/mtl.!*
http://produkte.web.de/go/02/


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


Mime
View raw message