Author: veithen
Date: Sat Jul 16 19:07:11 2011
New Revision: 1147476
URL: http://svn.apache.org/viewvc?rev=1147476&view=rev
Log:
AXIOM-372: Report attempts to create illegal namespace declarations.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.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/OMElement.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1147476&r1=1147475&r2=1147476&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
Sat Jul 16 19:07:11 2011
@@ -88,6 +88,9 @@ public interface OMElement extends OMNod
/**
* Creates a namespace in the current element scope.
+ * <p>
+ * Note that this method allows to bind a prefix to the empty namespace
URI. However, this will
+ * result in an error if the element is serialized as XML 1.0.
*
* @param uri The namespace to declare in the current scope. The
caller is expected to
* ensure that the URI is a valid namespace name.
@@ -117,6 +120,9 @@ public interface OMElement extends OMNod
/**
* Declares a namespace with the element as its scope.
+ * <p>
+ * Note that this method allows to bind a prefix to the empty namespace
URI. However, this will
+ * result in an error if the element is serialized as XML 1.0.
*
* @param namespace
* The namespace to declare. If the prefix specified by the
{@link OMNamespace}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=1147476&r1=1147475&r2=1147476&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
Sat Jul 16 19:07:11 2011
@@ -22,6 +22,7 @@ package org.apache.axiom.om.impl.util;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMConstants;
@@ -711,11 +712,9 @@ public class OMSerializerUtil {
} else {
// UNQUALIFIED NAMESPACE
- // Cannot associate a prefix with an unqualifed name.
- // However sometimes axiom creates a fake prefix name if xmns=""
is not in effect.
- // So return true
+ // XML 1.0 doesn't allow to associate a prefix with an unqualified
name (see also AXIOM-372).
if (prefix.length() > 0) {
- return true;
+ throw new OMException("Invalid namespace declaration: Prefixed
namespace bindings may not be empty.");
}
// Get the namespace associated with the prefix.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java?rev=1147476&r1=1147475&r2=1147476&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java
Sat Jul 16 19:07:11 2011
@@ -43,10 +43,11 @@ public abstract class SOAPBuilderHelper
protected void processNamespaceData(OMElement node, boolean
checkSOAPNamespace) {
int namespaceCount = parser.getNamespaceCount();
for (int i = 0; i < namespaceCount; i++) {
- String namespaceURI = parser.getNamespaceURI(i);
- if (namespaceURI != null) {
- node.declareNamespace(parser.getNamespaceURI(i),
- parser.getNamespacePrefix(i));
+ String prefix = parser.getNamespacePrefix(i);
+ if (prefix == null || prefix.length() == 0) {
+ node.declareDefaultNamespace(parser.getNamespaceURI());
+ } else {
+ node.declareNamespace(parser.getNamespaceURI(i), prefix);
}
}
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=1147476&r1=1147475&r2=1147476&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 Jul 16 19:07:11 2011
@@ -83,6 +83,7 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace1(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace2(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestDeclareNamespace1(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix1(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix2(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetAllAttributes1(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java?rev=1147476&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
Sat Jul 16 19:07:11 2011
@@ -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.om.element;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests Axiom's behavior when {@link OMElement#declareNamespace(String,
String)} is used to add a
+ * namespace declaration that binds a prefix to an empty namespace URI. This
is forbidden by XML 1.0
+ * and should result in an error when serializing the document.
+ */
+public class TestDeclareNamespaceInvalid extends AxiomTestCase {
+ public TestDeclareNamespaceInvalid(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMElement element = metaFactory.getOMFactory().createOMElement(new
QName("test"));
+ element.declareNamespace("", "ns");
+ try {
+ element.toString();
+ fail("Expected OMException");
+ } catch (OMException ex) {
+ // Expected
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
------------------------------------------------------------------------------
svn:eol-style = native