ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1717695 - in /webservices/axiom/branches/datatypes/datatypes/src: main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
Date Wed, 02 Dec 2015 23:39:16 GMT
Author: veithen
Date: Wed Dec  2 23:39:16 2015
New Revision: 1717695

URL: http://svn.apache.org/viewvc?rev=1717695&view=rev
Log:
Correctly support xs:QName values with prefixes xml and xmlns.

Modified:
    webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java

Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java?rev=1717695&r1=1717694&r2=1717695&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
Wed Dec  2 23:39:16 2015
@@ -20,6 +20,7 @@ package org.apache.axiom.datatype.xsd;
 
 import java.text.ParseException;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.datatype.ContextAccessor;
@@ -50,9 +51,16 @@ final class XSQNameTypeImpl implements X
             prefix = literal.substring(start, colonIndex);
             localPart = literal.substring(colonIndex+1, end);
         }
-        String namespaceURI = contextAccessor.lookupNamespaceURI(contextObject, options,
prefix);
-        if (namespaceURI == null) {
-            throw new ParseException("Unbound namespace prefix \"" + prefix + "\"", 0);
+        String namespaceURI;
+        if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+            namespaceURI = XMLConstants.XML_NS_URI;
+        } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+            namespaceURI = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+        } else {
+            namespaceURI = contextAccessor.lookupNamespaceURI(contextObject, options, prefix);
+            if (namespaceURI == null) {
+                throw new ParseException("Unbound namespace prefix \"" + prefix + "\"", 0);
+            }
         }
         return new QName(namespaceURI, localPart, prefix);
     }

Modified: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java?rev=1717695&r1=1717694&r2=1717695&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
Wed Dec  2 23:39:16 2015
@@ -22,6 +22,7 @@ import static com.google.common.truth.Tr
 
 import java.text.ParseException;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
@@ -64,4 +65,26 @@ public class DOMHelperTest {
         assertThat(qname.getLocalPart()).isEqualTo("value");
         assertThat(qname.getPrefix()).isEmpty();
     }
+    
+    @Test
+    public void testGetQNameFromElementXmlPrefix() throws Exception {
+        Document document = newDocument();
+        Element element = document.createElementNS(null, "test");
+        element.setTextContent("xml:value");
+        QName qname = DOMHelper.getValue(element, XSQNameType.INSTANCE);
+        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XML_NS_URI);
+        assertThat(qname.getLocalPart()).isEqualTo("value");
+        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XML_NS_PREFIX);
+    }
+    
+    @Test
+    public void testGetQNameFromElementXmlnsPrefix() throws Exception {
+        Document document = newDocument();
+        Element element = document.createElementNS(null, "test");
+        element.setTextContent("xmlns:value");
+        QName qname = DOMHelper.getValue(element, XSQNameType.INSTANCE);
+        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
+        assertThat(qname.getLocalPart()).isEqualTo("value");
+        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE);
+    }
 }



Mime
View raw message