Author: natalia
Date: Thu Feb 28 18:13:21 2008
New Revision: 632207

URL: http://svn.apache.org/viewvc?rev=632207&view=rev
Log:
Add URI for implicitly declared namespace prefix "xml"

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java
    xml/xindice/trunk/status.xml

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java?rev=632207&r1=632206&r2=632207&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java Thu Feb 
28 18:13:21 2008
@@ -51,6 +51,7 @@
     private static final Log log = LogFactory.getLog(NodeImpl.class);
 
     public static final String XMLNS_PREFIX = "xmlns";
+    public static final String XML_PREFIX = "xml";
 
     public static final String OBJECT_NS   = 
"http://xml.apache.org/xindice/XMLObject";;
     public static final String OBJECT_HREF = "href";
@@ -63,6 +64,8 @@
 
 
     public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";;
+    public static final String XML_URI = 
"http://www.w3.org/XML/1998/namespace";;
+
     // Static Exception Instances
     public static final DOMException EX_NO_MODIFICATION_ALLOWED =
             new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "This 
Node Is Read-Only");
@@ -733,7 +736,7 @@
     }
 
     /**
-     *  The  namespace URI of this node, or <code>null</code> if it is
+     * The namespace URI of this node, or <code>null</code> if it is
      * unspecified.
      * <br> This is not a computed value that is the result of a namespace
      * lookup based on an examination of the namespace declarations in scope.
@@ -751,10 +754,14 @@
     public final String getNamespaceURI() {
 
         short nodeType = getNodeType();
-        if ((nodeType == Node.ATTRIBUTE_NODE)
-                && (nodeName.equals(XMLNS_PREFIX) || 
nodeName.startsWith(XMLNS_PREFIX + ":"))) {
-
-            return XMLNS_URI;
+        if (nodeType == Node.ATTRIBUTE_NODE) {
+            if (nodeName.equals(XMLNS_PREFIX) || 
nodeName.startsWith(XMLNS_PREFIX + ":")) {
+                // defined by specification, must not be declared
+                return XMLNS_URI;
+            } else if (nodeName.startsWith(XML_PREFIX + ":")) {
+                // defined by specification, does not need to be declared
+                return XML_URI;
+            }
         }
         if (nsURI != null) {
             return nsURI;

Modified: 
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java?rev=632207&r1=632206&r2=632207&view=diff
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java 
(original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java 
Thu Feb 28 18:13:21 2008
@@ -19,6 +19,7 @@
 
 package org.apache.xindice.xml.dom;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.UserDataHandler;
@@ -181,6 +182,21 @@
 
         ((DocumentImpl) node1.getOwnerDocument()).renameNode(node1, 
"http://newURI";, "test:bar");
         assertEquals(getExpectedResult(UserDataHandler.NODE_RENAMED, "key", 
"data", node1), handler.getResult());
+    }
+
+    /*
+     * Test checks if node correctly identifies xml namespace prefix bound to
+     * http://www.w3.org/XML/1998/namespace URI, even if it was not explicitly
+     * declared.
+     */
+    public void testStandardDefinedNamespaces() throws Exception {
+        Document doc = DOMParser.toDocument("<root 
xmlns:xml='http://www.w3.org/XML/1998/namespace' xml:lang='en'/>");
+        Node n = doc.getDocumentElement().getAttributeNode("xml:lang");
+        assertEquals("Incorrect URI for explicitly declared xml prefix", 
NodeImpl.XML_URI, n.getNamespaceURI());
+
+        doc = DOMParser.toDocument("<root xml:lang='en'/>");
+        n = doc.getDocumentElement().getAttributeNode("xml:lang");
+        assertEquals("Incorrect URI for implicitly declared xml prefix", 
NodeImpl.XML_URI, n.getNamespaceURI());
     }
 
     private String getExpectedResult(short op, String key, Object data, Node 
src) {

Modified: xml/xindice/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?rev=632207&r1=632206&r2=632207&view=diff
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Thu Feb 28 18:13:21 2008
@@ -114,6 +114,9 @@
 
   <changes>
     <release version="1.2-dev" date="unreleased">
+      <action dev="NS" type="fix">
+        Fix implicitly declared namespace prefix "xml" in DOM implementation. 
+      </action>
       <action dev="NS" type="add">
         Change IndexPattern format to allow to specify path to 
         element/attribute.


Reply via email to