Author: veithen
Date: Sun Jun 29 08:51:09 2014
New Revision: 1606444

URL: http://svn.apache.org/r1606444
Log:
AXIOM-460: Implement DOM's lookupPrefix method.

Added:
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java
   (with props)
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java
   (with props)
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java
   (with props)
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java
   (with props)
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java
   (with props)
Modified:
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
    
webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
    
webservices/axiom/trunk/testsuites/dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
 Sun Jun 29 08:51:09 2014
@@ -519,4 +519,9 @@ public class AttrImpl extends RootNode i
         Element ownerElement = getOwnerElement();
         return ownerElement == null ? null : 
ownerElement.lookupNamespaceURI(specifiedPrefix);
     }
+
+    public final String lookupPrefix(String namespaceURI) {
+        Element ownerElement = getOwnerElement();
+        return ownerElement == null ? null : 
ownerElement.lookupPrefix(namespaceURI);
+    }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
 Sun Jun 29 08:51:09 2014
@@ -120,4 +120,9 @@ public abstract class ChildNode extends 
         // references fully, we only check for elements.
         return parent instanceof Element ? 
parent.lookupNamespaceURI(specifiedPrefix) : null;
     }
+    
+    public final String lookupPrefix(String namespaceURI) {
+        ParentNode parent = parentNode();
+        return parent instanceof Element ? parent.lookupPrefix(namespaceURI) : 
null;
+    }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
 Sun Jun 29 08:51:09 2014
@@ -129,6 +129,10 @@ public class DocumentFragmentImpl extend
         return null;
     }
 
+    public String lookupPrefix(String namespaceURI) {
+        return null;
+    }
+
     public final void checkChild(OMNode child) {
     }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
 Sun Jun 29 08:51:09 2014
@@ -55,6 +55,7 @@ import org.w3c.dom.Text;
 
 import javax.xml.XMLConstants;
 import javax.xml.stream.XMLStreamException;
+
 import java.io.OutputStream;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -632,6 +633,12 @@ public class DocumentImpl extends RootNo
                 : documentElement.lookupNamespaceURI(specifiedPrefix);
     }
     
+    public final String lookupPrefix(String namespaceURI) {
+        Element documentElement = getDocumentElement();
+        return documentElement == null ? null
+                : getDocumentElement().lookupPrefix(namespaceURI);
+    }
+
     public final void checkChild(OMNode child) {
         if (child instanceof OMElement) {
             if (getOMDocumentElement() != null) {

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
 Sun Jun 29 08:51:09 2014
@@ -46,7 +46,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -1172,7 +1171,40 @@ public class ElementImpl extends ParentN
         }
         // looking in ancestor
         ParentNode parent = parentNode();
-        return parent == null || parent instanceof Document ? null : 
parent.lookupNamespaceURI(specifiedPrefix);
+        return parent instanceof Element ? 
parent.lookupNamespaceURI(specifiedPrefix) : null;
+    }
+
+    public final String lookupPrefix(String namespaceURI) {
+        return lookupPrefix(namespaceURI, this);
+    }
+    
+    final String lookupPrefix(String namespaceURI, Element originalElement) {
+        if (namespaceURI == null || namespaceURI.length() == 0) {
+            return null;
+        }
+        if (namespaceURI.equals(getNamespaceURI())) {
+            String prefix = getPrefix();
+            if 
(namespaceURI.equals(originalElement.lookupNamespaceURI(prefix))) {
+                return prefix;
+            }
+        }
+        if (this.hasAttributes()) {
+            NamedNodeMap map = this.getAttributes();
+            int length = map.getLength();
+            for (int i = 0; i < length; i++) {
+                Node attr = map.item(i);
+                String attrPrefix = attr.getPrefix();
+                if (attrPrefix != null && 
attrPrefix.equals(XMLConstants.XMLNS_ATTRIBUTE)
+                        && attr.getNodeValue().equals(namespaceURI)) {
+                    String prefix = attr.getLocalName();
+                    if 
(namespaceURI.equals(originalElement.lookupNamespaceURI(prefix))) {
+                        return prefix;
+                    }
+                }
+            }
+        }
+        ParentNode parent = parentNode();
+        return parent instanceof Element ? 
((ElementImpl)parent).lookupPrefix(namespaceURI, originalElement) : null;
     }
 
     public final void checkChild(OMNode child) {

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
 Sun Jun 29 08:51:09 2014
@@ -203,11 +203,6 @@ public abstract class NodeImpl implement
         return this == node;
     }
 
-    public String lookupPrefix(String namespaceURI) {
-        // TODO TODO
-        throw new UnsupportedOperationException("TODO");
-    }
-
     public boolean isDefaultNamespace(String namespaceURI) {
         // TODO TODO
         throw new UnsupportedOperationException("TODO");

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
 Sun Jun 29 08:51:09 2014
@@ -426,25 +426,7 @@ public class DOMImplementationTest exten
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode14)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode19)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode22)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix01)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix02)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix03)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix05)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix06)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix07)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix08)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix09)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix10)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix11)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix12)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix13)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix14)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix15)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix16)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix17)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix18)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix19)");
-        builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix20)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/noderemovechild19)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild13)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild20)");

Modified: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
 (original)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
 Sun Jun 29 08:51:09 2014
@@ -106,6 +106,7 @@ public final class DOMTestSuiteBuilder e
         addTest(new 
org.apache.axiom.ts.dom.document.TestGetOwnerDocument(dbf));
         addTest(new 
org.apache.axiom.ts.dom.document.TestLookupNamespaceURI(dbf));
         addTest(new 
org.apache.axiom.ts.dom.document.TestLookupNamespaceURIWithEmptyDocument(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.document.TestLookupPrefixWithEmptyDocument(dbf));
         addTest(new 
org.apache.axiom.ts.dom.document.TestNormalizeDocumentNamespace(dbf));
         for (int i=0; i<XSLTImplementation.INSTANCES.length; i++) {
             XSLTImplementation xsltImplementation = 
XSLTImplementation.INSTANCES[i];
@@ -116,6 +117,7 @@ public final class DOMTestSuiteBuilder e
         addTest(new 
org.apache.axiom.ts.dom.documentfragment.TestCloneNodeDeep(dbf));
         addTest(new 
org.apache.axiom.ts.dom.documentfragment.TestCloneNodeShallow(dbf));
         addTest(new 
org.apache.axiom.ts.dom.documentfragment.TestLookupNamespaceURI(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.documentfragment.TestLookupPrefix(dbf));
         addTest(new org.apache.axiom.ts.dom.documenttype.TestWithParser1(dbf));
         addTest(new org.apache.axiom.ts.dom.documenttype.TestWithParser2(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAppendChild(dbf));
@@ -142,6 +144,9 @@ public final class DOMTestSuiteBuilder e
         addTest(new 
org.apache.axiom.ts.dom.element.TestInsertBeforeWithDocumentFragment(dbf));
         addTest(new 
org.apache.axiom.ts.dom.element.TestLookupNamespaceURIExplicit(dbf));
         addTest(new 
org.apache.axiom.ts.dom.element.TestLookupNamespaceURIImplicit(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.element.TestLookupPrefixEmptyNamespace(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.element.TestLookupPrefixExplicitMasked(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.element.TestLookupPrefixImplicitMasked(dbf));
         addTest(new 
org.apache.axiom.ts.dom.element.TestRemoveAttributeNotOwner(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));

Added: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java?rev=1606444&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java
 (added)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java
 Sun Jun 29 08:51:09 2014
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Tests the behavior of {@link Node#lookupPrefix(String)} on an empty {@link 
Document}.
+ */
+public class TestLookupPrefixWithEmptyDocument extends DOMTestCase {
+    public TestLookupPrefixWithEmptyDocument(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        assertNull(document.lookupPrefix("urn:test"));
+    }
+}

Propchange: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestLookupPrefixWithEmptyDocument.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java?rev=1606444&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java
 (added)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java
 Sun Jun 29 08:51:09 2014
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.documentfragment;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that a call to {@link Node#lookupPrefix(String)} on a {@link 
DocumentFragment} always
+ * returns <code>null</code> (in contrast to {@link Document}), even if one of 
its children has a
+ * matching namespace declaration.
+ */
+public class TestLookupPrefix extends DOMTestCase {
+    public TestLookupPrefix(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        DocumentFragment fragment = document.createDocumentFragment();
+        Element element = document.createElementNS("urn:test", "ns:root");
+        element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, 
"xmlns:ns", "urn:test");
+        fragment.appendChild(element);
+        assertNull(fragment.lookupPrefix("urn:test"));
+    }
+}

Propchange: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/documentfragment/TestLookupPrefix.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java?rev=1606444&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java
 (added)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java
 Sun Jun 29 08:51:09 2014
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Tests that {@link Node#lookupPrefix(String)} always returns 
<code>null</code> if the given
+ * namespace URI is the empty string.
+ */
+public class TestLookupPrefixEmptyNamespace extends DOMTestCase {
+    public TestLookupPrefixEmptyNamespace(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().parse(new InputSource(new 
StringReader(
+                "<a xmlns='urn:test'><b xmlns=''/></a>")));
+        
assertNull(document.getDocumentElement().getFirstChild().lookupPrefix(""));
+    }
+}

Propchange: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixEmptyNamespace.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java?rev=1606444&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java
 (added)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java
 Sun Jun 29 08:51:09 2014
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Tests that {@link Node#lookupPrefix(String)} returns <code>null</code> if 
the matching namespace
+ * declaration is masked by another namespace declaration, i.e. if the 
corresponding prefix is
+ * redeclared.
+ */
+public class TestLookupPrefixExplicitMasked extends DOMTestCase {
+    public TestLookupPrefixExplicitMasked(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().parse(new InputSource(new 
StringReader(
+                "<root xmlns:p='urn:ns1'><child xmlns:p='urn:ns2'/></root>")));
+        
assertNull(document.getDocumentElement().getFirstChild().lookupPrefix("urn:ns1"));
+    }
+}

Propchange: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixExplicitMasked.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java?rev=1606444&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java
 (added)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java
 Sun Jun 29 08:51:09 2014
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#lookupPrefix(String)} returns <code>null</code> if 
the matching prefix is
+ * masked by a child element (of the element that has the matching prefix).
+ */
+public class TestLookupPrefixImplicitMasked extends DOMTestCase {
+    public TestLookupPrefixImplicitMasked(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Element root = document.createElementNS("urn:ns1", "p:root");
+        Element child = document.createElementNS("urn:ns2", "p:child");
+        root.appendChild(child);
+        assertNull(child.lookupPrefix("urn:ns1"));
+    }
+}

Propchange: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupPrefixImplicitMasked.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/axiom/trunk/testsuites/dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java?rev=1606444&r1=1606443&r2=1606444&view=diff
==============================================================================
--- 
webservices/axiom/trunk/testsuites/dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java
 (original)
+++ 
webservices/axiom/trunk/testsuites/dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java
 Sun Jun 29 08:51:09 2014
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import 
org.apache.axiom.ts.dom.document.TestLookupNamespaceURIWithEmptyDocument;
+import org.apache.axiom.ts.dom.document.TestLookupPrefixWithEmptyDocument;
 import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
 
 public class XercesTest extends TestCase {
@@ -36,6 +37,7 @@ public class XercesTest extends TestCase
         
         // XERCESJ-1582
         builder.exclude(TestLookupNamespaceURIWithEmptyDocument.class);
+        builder.exclude(TestLookupPrefixWithEmptyDocument.class);
         
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrgetvalue2)");
         builder.exclude(W3CTestCase.class, 
"(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/createAttributeNS06)");


Reply via email to