You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/04/25 15:08:23 UTC
svn commit: r937794 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/om/impl/
main/java/org/apache/axiom/om/impl/builder/
main/java/org/apache/axiom/om/impl/serialize/
main/java/org/apache/axiom/util/stax/...
Author: veithen
Date: Sun Apr 25 13:08:23 2010
New Revision: 937794
URL: http://svn.apache.org/viewvc?rev=937794&view=rev
Log:
WSCOMMONS-535: Fixed multiple issues that arise when an XML document contains attributes with the 'xml' prefix.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderComparator.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java?rev=937794&r1=937793&r2=937794&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java Sun Apr 25 13:08:23 2010
@@ -463,13 +463,17 @@ class SwitchingWrapper extends AbstractX
namespaceCount = 0;
for (Iterator it = ((OMElement)lastNode).getAllDeclaredNamespaces(); it.hasNext(); ) {
OMNamespace ns = (OMNamespace)it.next();
- if (namespaceCount == namespaces.length) {
- OMNamespace[] newNamespaces = new OMNamespace[namespaces.length*2];
- System.arraycopy(namespaces, 0, newNamespaces, 0, namespaces.length);
- namespaces = newNamespaces;
+ // Axiom internally creates an OMNamespace instance for the "xml" prefix, even
+ // if it is not declared explicitly. Filter this instance out.
+ if (!"xml".equals(ns.getPrefix())) {
+ if (namespaceCount == namespaces.length) {
+ OMNamespace[] newNamespaces = new OMNamespace[namespaces.length*2];
+ System.arraycopy(namespaces, 0, newNamespaces, 0, namespaces.length);
+ namespaces = newNamespaces;
+ }
+ namespaces[namespaceCount] = ns;
+ namespaceCount++;
}
- namespaces[namespaceCount] = ns;
- namespaceCount++;
}
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=937794&r1=937793&r2=937794&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Sun Apr 25 13:08:23 2010
@@ -26,6 +26,7 @@ import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.impl.OMContainerEx;
import org.apache.axiom.om.impl.OMNodeEx;
@@ -38,6 +39,8 @@ import org.xml.sax.helpers.DefaultHandle
import java.util.ArrayList;
import java.util.List;
+import javax.xml.XMLConstants;
+
public class SAXOMBuilder extends DefaultHandler implements LexicalHandler {
private OMDocument document;
@@ -159,9 +162,23 @@ public class SAXOMBuilder extends Defaul
// See http://forum.springframework.org/showthread.php?t=43958 for a discussion.
// If this test causes problems with other parsers, don't hesitate to remove it.
if (!atts.getQName(i).startsWith("xmlns")) {
- OMAttribute attr = nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i),
- nextElem.findNamespace(atts.getURI(i), null));
-
+ String attrNamespaceURI = atts.getURI(i);
+ OMNamespace ns;
+ if (attrNamespaceURI.length() > 0) {
+ ns = nextElem.findNamespace(atts.getURI(i), null);
+ if (ns == null) {
+ // The "xml" prefix is not necessarily declared explicitly; in this case,
+ // create a new OMNamespace instance.
+ if (attrNamespaceURI.equals(XMLConstants.XML_NS_URI)) {
+ ns = factory.createOMNamespace(XMLConstants.XML_NS_URI, XMLConstants.XML_NS_PREFIX);
+ } else {
+ throw new SAXException("Unbound namespace " + attrNamespaceURI);
+ }
+ }
+ } else {
+ ns = null;
+ }
+ OMAttribute attr = nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i), ns);
attr.setAttributeType(atts.getType(i));
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=937794&r1=937793&r2=937794&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java Sun Apr 25 13:08:23 2010
@@ -431,7 +431,7 @@ public class StreamingOMSerializer imple
}
}
}
- } else if (namespace != null) {
+ } else if (namespace != null && !prefix.equals("xml")) {
// Use the writer's prefix if it is different, but if the writers
// prefix is empty then do not replace because attributes do not
// default to the default namespace like elements do.
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?rev=937794&r1=937793&r2=937794&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java Sun Apr 25 13:08:23 2010
@@ -19,9 +19,13 @@
package org.apache.axiom.util.stax.dialect;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.apache.axiom.util.namespace.AbstractNamespaceContext;
import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
class BEAStreamReaderWrapper extends XMLStreamReaderWrapper {
@@ -134,4 +138,24 @@ class BEAStreamReaderWrapper extends XML
return super.getText();
}
}
+
+ public NamespaceContext getNamespaceContext() {
+ // The NamespaceContext returned by the reference doesn't handle the
+ // implicit namespace bindings (for the "xml" and "xmlns" prefixes)
+ // correctly
+ final NamespaceContext parent = super.getNamespaceContext();
+ return new AbstractNamespaceContext() {
+ protected String doGetNamespaceURI(String prefix) {
+ return parent.getNamespaceURI(prefix);
+ }
+
+ protected String doGetPrefix(String namespaceURI) {
+ return parent.getPrefix(namespaceURI);
+ }
+
+ protected Iterator doGetPrefixes(String namespaceURI) {
+ return parent.getPrefixes(namespaceURI);
+ }
+ };
+ }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderComparator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderComparator.java?rev=937794&r1=937793&r2=937794&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderComparator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderComparator.java Sun Apr 25 13:08:23 2010
@@ -284,7 +284,9 @@ public class XMLStreamReaderComparator e
eventType == XMLStreamReader.END_ELEMENT) {
for (Iterator it = prefixes.iterator(); it.hasNext(); ) {
String prefix = (String)it.next();
- if (prefix != null) {
+ // The StAX specs are not clear about the expected result of getNamespaceURI
+ // when called with prefix "xml" (which doesn't require an explicit declaration)
+ if (prefix != null && !prefix.equals("xml")) {
assertSameResult("getNamespaceURI",
new Class[] { String.class }, new Object[] { prefix });
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml?rev=937794&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml Sun Apr 25 13:08:23 2010
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<root>
+ <text xml:lang="en">Some text</text>
+</root>
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/xml-prefix.xml
------------------------------------------------------------------------------
svn:eol-style = native