Author: veithen
Date: Sat Jan 7 11:46:38 2012
New Revision: 1228598
URL: http://svn.apache.org/viewvc?rev=1228598&view=rev
Log:
AXIOM-408: Fixed an issue in the namespace repairing logic in the builder (that
occurs when a namespace declaration of the form xmlns="" is missing).
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java?rev=1228598&r1=1228597&r2=1228598&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
Sat Jan 7 11:46:38 2012
@@ -26,22 +26,26 @@ class BuilderUtil {
private BuilderUtil() {}
static void setNamespace(OMElement element, String namespaceURI, String
prefix, boolean namespaceURIInterning) {
- if (namespaceURI != null && namespaceURI.length() > 0) {
- // Check if there is an existing namespace declaration. This has
two purposes:
- // * Avoid creating a new OMNamespace instance for each OMElement
- // * Perform namespace repairing
- OMNamespace namespace = element.findNamespaceURI(prefix == null ?
"" : prefix);
- if (namespace == null ||
!namespace.getNamespaceURI().equals(namespaceURI)) {
- if (namespaceURIInterning) {
- namespaceURI = namespaceURI.intern();
- }
- if (prefix == null) {
- prefix = "";
- }
- // This is actually the place where we perform namespace
repairing as specified
- // in the contract of OMXMLBuilderFactory#createStAXOMBuilder:
- namespace =
((OMElementEx)element).addNamespaceDeclaration(namespaceURI, prefix);
+ if (prefix == null) {
+ prefix = "";
+ }
+ if (namespaceURI == null) {
+ namespaceURI = "";
+ }
+ // Check if there is an existing namespace declaration. This has two
purposes:
+ // * Avoid creating a new OMNamespace instance for each OMElement
+ // * Perform namespace repairing
+ OMNamespace namespace = element.findNamespaceURI(prefix);
+ if (namespace == null && namespaceURI.length() > 0
+ || namespace != null &&
!namespace.getNamespaceURI().equals(namespaceURI)) {
+ if (namespaceURIInterning) {
+ namespaceURI = namespaceURI.intern();
}
+ // This is actually the place where we perform namespace repairing
as specified
+ // in the contract of OMXMLBuilderFactory#createStAXOMBuilder:
+ namespace =
((OMElementEx)element).addNamespaceDeclaration(namespaceURI, prefix);
+ }
+ if (namespace != null && namespaceURI.length() > 0) {
element.setNamespaceWithNoFindInCurrentScope(namespace);
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1228598&r1=1228597&r2=1228598&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Sat Jan 7 11:46:38 2012
@@ -69,6 +69,7 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderFromFragment(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderIncorrectState(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing2(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElementWithIllFormedDocument(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java?rev=1228598&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java
Sat Jan 7 11:46:38 2012
@@ -0,0 +1,65 @@
+/*
+ * 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.om.builder;
+
+import java.io.StringReader;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMMetaFactory#createStAXOMBuilder(OMFactory,
XMLStreamReader)} correctly
+ * performs namespace repairing in cases where a namespace declaration of the
form <tt>xmlns=""</tt>
+ * is required. This is a regression test for <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-408">AXIOM-408</a>.
+ */
+public class TestCreateStAXOMBuilderNamespaceRepairing2 extends AxiomTestCase {
+ public TestCreateStAXOMBuilderNamespaceRepairing2(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ XMLStreamReader reader = StAXUtils.createXMLStreamReader(new
StringReader(
+ "<test xmlns='urn:test'><arg0
xmlns=''>dGVzdA==</arg0></test>"));
+ OMElement element =
metaFactory.createStAXOMBuilder(metaFactory.getOMFactory(),
+ new NamespaceDeclarationFilter(reader)).getDocumentElement();
+
+ Iterator it = element.getAllDeclaredNamespaces();
+ assertTrue(it.hasNext());
+ OMNamespace ns = (OMNamespace)it.next();
+ assertEquals("", ns.getPrefix());
+ assertEquals("urn:test", ns.getNamespaceURI());
+ assertFalse(it.hasNext());
+
+ OMElement child = element.getFirstElement();
+ it = child.getAllDeclaredNamespaces();
+ assertTrue(it.hasNext());
+ ns = (OMNamespace)it.next();
+ assertEquals("", ns.getPrefix());
+ assertEquals("", ns.getNamespaceURI());
+ assertFalse(it.hasNext());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing2.java
------------------------------------------------------------------------------
svn:eol-style = native