You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/07/21 19:19:12 UTC
svn commit: r1149274 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/xpath/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
axiom-impl/src/main/java/o...
Author: veithen
Date: Thu Jul 21 17:19:10 2011
New Revision: 1149274
URL: http://svn.apache.org/viewvc?rev=1149274&view=rev
Log:
AXIOM-372: Added OMElement#undeclarePrefix(String).
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.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/xpath/AXIOMXPath.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.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=1149274&r1=1149273&r2=1149274&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 Thu Jul 21 17:19:10 2011
@@ -139,6 +139,26 @@ public interface OMElement extends OMNod
OMNamespace declareNamespace(OMNamespace namespace);
/**
+ * Add a namespace declaration that undeclares a given prefix. Prefix undeclaring is supported
+ * in XML 1.1, but forbidden in XML 1.0. If an object model on which this method has been used
+ * is later serialized to an XML 1.0 document, an error will occur. When serialized to an XML
+ * 1.1 document, a namespace declaration in the form <tt>xmlns:p=""</tt> will be produced.
+ * <p>
+ * A namespace declaration with empty namespace name will be added even if no existing namespace
+ * declaration for the given prefix is in scope in the context of the current element. If a
+ * namespace declaration for the given prefix is already defined on this element, it will be
+ * replaced.
+ * <p>
+ * The namespace declaration created by this method will be returned by
+ * {@link #getAllDeclaredNamespaces()}. It is represented as an {@link OMNamespace} object for
+ * which {@link OMNamespace#getNamespaceURI()} returns an empty string.
+ *
+ * @param prefix
+ * the prefix to undeclare
+ */
+ void undeclarePrefix(String prefix);
+
+ /**
* Finds a namespace with the given uri and prefix, in the scope of the hierarchy.
* <p/>
* <p>Searches from the current element and goes up the hiararchy until a match is found. If no
@@ -163,6 +183,9 @@ public interface OMElement extends OMNod
*
* @param prefix
*/
+ // TODO: specify if null is a valid argument
+ // TODO: specify the return value if prefix is the empty string and there is no default namespace
+ // (should we return null or an OMNamespace instance with namespaceURI and prefix set to ""?)
OMNamespace findNamespaceURI(String prefix);
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java?rev=1149274&r1=1149273&r2=1149274&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java Thu Jul 21 17:19:10 2011
@@ -118,6 +118,7 @@ public class AXIOMXPath extends BaseXPat
* @param element the element to retrieve the namespace context from
* @throws JaxenException if an error occurred when adding the namespace declarations
*/
+ // TODO: need to take prefix undeclaring into account here; probably we should add a method to OMElement that returns all namespaces in scope
public void addNamespaces(OMElement element) throws JaxenException {
OMElement current = element;
// An element can redeclare a namespace prefix that has already been declared
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1149274&r1=1149273&r2=1149274&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Thu Jul 21 17:19:10 2011
@@ -28,6 +28,7 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMNamespaceImpl;
import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
import org.apache.axiom.om.impl.traverse.OMDescendantsIterator;
@@ -749,6 +750,13 @@ public class ElementImpl extends ParentN
return namespace;
}
+ public void undeclarePrefix(String prefix) {
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ namespaces.put(prefix, new OMNamespaceImpl("", prefix));
+ }
+
/**
* Allows overriding an existing declaration if the same prefix was used.
*
@@ -827,11 +835,19 @@ public class ElementImpl extends ParentN
null :
(OMNamespace) this.namespaces.get(prefix);
- if (ns == null && this.parentNode instanceof OMElement) {
- // try with the parent
- ns = ((OMElement) this.parentNode).findNamespaceURI(prefix);
+ if (ns == null) {
+ if (this.parentNode instanceof OMElement) {
+ // try with the parent
+ return ((OMElement) this.parentNode).findNamespaceURI(prefix);
+ } else {
+ return null;
+ }
+ } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length() == 0) {
+ // Prefix undeclaring case (XML 1.1 only)
+ return null;
+ } else {
+ return ns;
}
- return ns;
}
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1149274&r1=1149273&r2=1149274&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Thu Jul 21 17:19:10 2011
@@ -423,6 +423,13 @@ public class OMElementImpl extends OMNod
return namespace;
}
+ public void undeclarePrefix(String prefix) {
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ namespaces.put(prefix, new OMNamespaceImpl("", prefix));
+ }
+
/**
* Finds a namespace with the given uri and prefix, in the scope of the document. Starts to find
* from the current element and goes up in the hiararchy until one is found. If none is found,
@@ -454,11 +461,19 @@ public class OMElementImpl extends OMNod
null :
(OMNamespace) this.namespaces.get(prefix);
- if (ns == null && this.parent instanceof OMElement) {
- // try with the parent
- ns = ((OMElement) this.parent).findNamespaceURI(prefix);
+ if (ns == null) {
+ if (this.parent instanceof OMElement) {
+ // try with the parent
+ return ((OMElement) this.parent).findNamespaceURI(prefix);
+ } else {
+ return null;
+ }
+ } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length() == 0) {
+ // Prefix undeclaring case (XML 1.1 only)
+ return null;
+ } else {
+ return ns;
}
- return ns;
}
// Constant
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1149274&r1=1149273&r2=1149274&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Thu Jul 21 17:19:10 2011
@@ -373,6 +373,11 @@ public class OMSourcedElementImpl extend
return super.declareNamespace(namespace);
}
+ public void undeclarePrefix(String prefix) {
+ forceExpand();
+ super.undeclarePrefix(prefix);
+ }
+
/* (non-Javadoc)
* @see org.apache.axiom.om.OMElement#findNamespace(java.lang.String, java.lang.String)
*/
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=1149274&r1=1149273&r2=1149274&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 Thu Jul 21 17:19:10 2011
@@ -88,6 +88,7 @@ public class OMTestSuiteBuilder extends
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.TestFindNamespaceURIWithPrefixUndeclaring(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes2(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespaces(metaFactory));
@@ -154,6 +155,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestSetNamespaceWithMatchingBindingInScope(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSetText(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestUndeclarePrefix(metaFactory));
for (int i=0; i<OMElementCreator.INSTANCES.length; i++) {
OMElementCreator creator = OMElementCreator.INSTANCES[i];
if (creator.isSupportsDefaultNamespace()) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java?rev=1149274&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java Thu Jul 21 17:19:10 2011
@@ -0,0 +1,41 @@
+/*
+ * 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 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.ts.AxiomTestCase;
+
+public class TestFindNamespaceURIWithPrefixUndeclaring extends AxiomTestCase {
+ public TestFindNamespaceURIWithPrefixUndeclaring(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement parent = factory.createOMElement("parent", null);
+ OMElement child = factory.createOMElement("child", null, parent);
+ OMNamespace ns = parent.declareNamespace("urn:test", "p");
+ child.undeclarePrefix("p");
+ assertEquals(ns, parent.findNamespaceURI("p"));
+ assertNull(child.findNamespaceURI("p"));
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestFindNamespaceURIWithPrefixUndeclaring.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.java?rev=1149274&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.java Thu Jul 21 17:19:10 2011
@@ -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.om.element;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestUndeclarePrefix extends AxiomTestCase {
+ public TestUndeclarePrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
+ element.undeclarePrefix("p");
+ Iterator it = element.getAllDeclaredNamespaces();
+ assertTrue(it.hasNext());
+ OMNamespace ns = (OMNamespace)it.next();
+ assertEquals("", ns.getNamespaceURI());
+ assertEquals("p", ns.getPrefix());
+ assertFalse(it.hasNext());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUndeclarePrefix.java
------------------------------------------------------------------------------
svn:eol-style = native