JDK-6824647 : Document.createElementNS() is not working with Plugin2
  • Type: Enhancement
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u13
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-04-01
  • Updated: 2011-02-16
  • Resolved: 2009-04-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u14 b05Fixed
Description
FULL PRODUCT VERSION :
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, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
using Firefox 3.0.8 as the browser with the next generation Java Plug-in enabled in the Java Control Panel

A DESCRIPTION OF THE PROBLEM :
The Document.createElementNS() method is not working with Plugin2.

The createElementNS method compiles with no errors, but fails when run as an Applet with the following error message:

sun.plugin.dom.exception.PluginNotSupportedException: Document.createElementNS() is not supported

When the createElementNS method is changed to the non-NameSpace version, that is createElement(), the applet runs with no errors, but when the Element is added to the DOM, the added XML element doesn't display in the browser because it does not have the proper namespace.

When dumping the DOM after using the createElement method without the NS suffix, the element that was added is reported to be an [object Element], whereas all the other elements in the DOM read in from the XML source file are reported as their correct object, such as [object SVGRectElement], [object SVGGElement], etc.

The createElementNS() method did not work in java version "1.6.0_12" either.

As a side note, the setAttributeNS() method with the NameSpace suffix used in this test program works correctly and adds the attributes to the element and can be verified when the DOM is dumped.

  Fixing the createElementNS() method in the plugin2 would be greatly appreciated.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
load the test XML file into the browser and display the java console to see the error messages.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
The following is the error messages produced by the Java Console.

Java Plug-in 1.6.0_13
Using JRE version 1.6.0_13 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Owner.PC_USER2
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
Clear classloader cache ... completed.
sun.plugin.dom.exception.PluginNotSupportedException: Document.createElementNS() is not supported
	at sun.plugin.dom.core.Document.createElementNS(Unknown Source)
	at MyTestApplet.start(MyTestApplet.java:34)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
*********  MyTestApplet.Java has aborted  **********


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Below are 2 source code files.  The first is the Applet test class, and the second is the XML file to activate the Applet.

***********************************************************************************
(1)  MyTestApplet.java:


import java.lang.reflect.*;
import org.w3c.dom.*;


public class MyTestApplet extends java.applet.Applet {

	/** Simple Applet test which shows that the createElementNS() is not
	    working with Plugin2.
	    
	    Dropping the NameSpace suffix, that is changing createElementNS() to createElement(),
	    does create an element, but when added to the DOM, the browser doesn't display
	    the added element because the element is not of the proper Namespace object.  **/
	    

	    public void start() {
	        try {
	        	
	            Class c = Class.forName("com.sun.java.browser.plugin2.DOM");
	            
	            Method m = c.getMethod("getDocument",
	                                   new Class[] { java.applet.Applet.class });
	            
	            // get access to the Document object
	            
	            Document doc = (Document) m.invoke(null, new Object[] { this });
	            
	            // get the root element of the document
	         
	            Element element = (Element) doc.getDocumentElement();
	           
	            // create a new element and append to the end of the root element
	            
	            Element circle = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
	            circle.setAttributeNS("http://www.w3.org/2000/svg", "cx", "200");
	            circle.setAttributeNS("http://www.w3.org/2000/svg", "cy", "250");
	            circle.setAttributeNS("http://www.w3.org/2000/svg", "r", "80");
	            circle.setAttributeNS("http://www.w3.org/2000/svg", "style", "fill:green");
	            
	            element.appendChild(circle);
	            
	        } catch (Exception e) {
	            e.printStackTrace();
	            System.out.println("*********  MyTestApplet.Java has aborted  **********");
	        }
	    }
	    
	}



***********************************************************************************
(2)  SVGtest.xml:


<?xml version="1.0" standalone="no"?>


			<svg width="100%" height="100%"
				version="1.1"
				baseProfile="full"
				xmlns="http://www.w3.org/2000/svg" >

				<rect x="0" y="0" width="200" height="200" style="fill:#5500CC" />

				<foreignObject x="0" y="0" width="1" height="1">

								<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
									<xhtml:body>
										<xhtml:applet code="MyTestApplet.class" width="1" height="1" />
									</xhtml:body>
								</xhtml:html>

				</foreignObject>

				<rect x="0" y="0" width="100%" height="20" style="fill:#DD33CC" />

			</svg>
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workaround found.

Release Regression From : 6.0
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION This is an RFE because the specification states that HTML-only DOM implementations do not need to implement that method. It is not a regression because this function has never worked in any previous Java Plug-In release. We need to see whether the browser's JavaScript DOM APIs support it, and if they do, it should be simple to map to it.
01-04-2009