Author: mbenson
Date: Fri Jan 20 17:58:11 2012
New Revision: 1234036
URL: http://svn.apache.org/viewvc?rev=1234036&view=rev
Log:
[JXPATH-154] handling of inner empty/default ns in DOM XML model
Added:
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml
(with props)
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java
(with props)
Modified:
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
Modified:
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
URL:
http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java?rev=1234036&r1=1234035&r2=1234036&view=diff
==============================================================================
---
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
(original)
+++
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
Fri Jan 20 17:58:11 2012
@@ -677,24 +677,23 @@ public class DOMNodePointer extends Node
Element element = (Element) node;
String uri = element.getNamespaceURI();
- if (uri != null) {
- return uri;
- }
-
- String prefix = getPrefix(node);
- String qname = prefix == null ? "xmlns" : "xmlns:" + prefix;
-
- Node aNode = node;
- while (aNode != null) {
- if (aNode.getNodeType() == Node.ELEMENT_NODE) {
- Attr attr = ((Element) aNode).getAttributeNode(qname);
- if (attr != null) {
- return attr.getValue();
+ if (uri == null) {
+ String prefix = getPrefix(node);
+ String qname = prefix == null ? "xmlns" : "xmlns:" + prefix;
+
+ Node aNode = node;
+ while (aNode != null) {
+ if (aNode.getNodeType() == Node.ELEMENT_NODE) {
+ Attr attr = ((Element) aNode).getAttributeNode(qname);
+ if (attr != null) {
+ uri = attr.getValue();
+ break;
+ }
}
+ aNode = aNode.getParentNode();
}
- aNode = aNode.getParentNode();
}
- return null;
+ return "".equals(uri) ? null : uri;
}
public Object getValue() {
Added:
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml?rev=1234036&view=auto
==============================================================================
---
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml
(added)
+++
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml
Fri Jan 20 17:58:11 2012
@@ -0,0 +1,22 @@
+<?xml version="1.0" ?>
+<!--
+ 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.
+-->
+
+<b:foo xmlns:b="bla" xmlns="test111">
+ <b:bar>a</b:bar>
+ <test xmlns=""></test>
+</b:foo>
Propchange:
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/InnerEmptyNamespace.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java
URL:
http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java?rev=1234036&view=auto
==============================================================================
---
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java
(added)
+++
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java
Fri Jan 20 17:58:11 2012
@@ -0,0 +1,27 @@
+package org.apache.commons.jxpath.ri.model;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathTestCase;
+import org.apache.commons.jxpath.xml.DocumentContainer;
+
+public class JXPath154Test extends JXPathTestCase {
+
+ protected JXPathContext context;
+
+ protected DocumentContainer createDocumentContainer(String model) {
+ return new
DocumentContainer(JXPathTestCase.class.getResource("InnerEmptyNamespace.xml"),
model);
+ }
+
+ protected void doTest(String path, String model, String expectedValue) {
+ JXPathContext context =
JXPathContext.newContext(createDocumentContainer(model));
+ assertEquals(expectedValue, context.getPointer(path).asPath());
+ }
+
+ public void testInnerEmptyNamespaceDOM() {
+ doTest("b:foo/test", DocumentContainer.MODEL_DOM, "/b:foo[1]/test[1]");
+ }
+
+ public void testInnerEmptyNamespaceJDOM() {
+ doTest("b:foo/test", DocumentContainer.MODEL_JDOM,
"/b:foo[1]/test[1]");
+ }
+}
Propchange:
commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/JXPath154Test.java
------------------------------------------------------------------------------
svn:eol-style = native