commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r617940 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/model/dom/ java/org/apache/commons/jxpath/ri/model/jdom/ test/org/apache/commons/jxpath/ test/org/apache/commons/jxpath/ri/model/
Date Sun, 03 Feb 2008 02:14:00 GMT
Author: mbenson
Date: Sat Feb  2 18:13:59 2008
New Revision: 617940

URL: http://svn.apache.org/viewvc?rev=617940&view=rev
Log:
[JXPATH-109] attribute::* should select attrs regardless of whether they have a namespace

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestCase.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java?rev=617940&r1=617939&r2=617940&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java
Sat Feb  2 18:13:59 2008
@@ -57,7 +57,7 @@
                 int count = map.getLength();
                 for (int i = 0; i < count; i++) {
                     Attr attr = (Attr) map.item(i);
-                    if (testAttr(attr, name)) {
+                    if (testAttr(attr)) {
                         attributes.add(attr);
                     }
                 }
@@ -65,7 +65,7 @@
         }
     }
 
-    private boolean testAttr(Attr attr, QName testName) {
+    private boolean testAttr(Attr attr) {
         String nodePrefix = DOMNodePointer.getPrefix(attr);
         String nodeLocalName = DOMNodePointer.getLocalName(attr);
 
@@ -79,22 +79,16 @@
 
         String testLocalName = name.getName();
         if (testLocalName.equals("*") || testLocalName.equals(nodeLocalName)) {
-            String testPrefix = testName.getPrefix();
+            String testPrefix = name.getPrefix();
 
-            if (equalStrings(testPrefix, nodePrefix)) {
+            if (testPrefix == null || equalStrings(testPrefix, nodePrefix)) {
                 return true;
             }
-
-            String testNS = null;
-            if (testPrefix != null) {
-                testNS = parent.getNamespaceURI(testPrefix);
-            }
-
-            String nodeNS = null;
-            if (nodePrefix != null) {
-                nodeNS = parent.getNamespaceURI(nodePrefix);
+            if (nodePrefix == null) {
+                return false;
             }
-            return equalStrings(testNS, nodeNS);
+            return equalStrings(parent.getNamespaceURI(testPrefix), parent
+                    .getNamespaceURI(nodePrefix));
         }
         return false;
     }
@@ -123,7 +117,7 @@
             NamedNodeMap nnm = element.getAttributes();
             for (int i = 0; i < nnm.getLength(); i++) {
                 attr = (Attr) nnm.item(i);
-                if (testAttr(attr, name)) {
+                if (testAttr(attr)) {
                     return attr;
                 }
             }

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java?rev=617940&r1=617939&r2=617940&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java
Sat Feb  2 18:13:59 2008
@@ -67,11 +67,9 @@
             String lname = name.getName();
             if (!lname.equals("*")) {
                 attributes = new ArrayList();
-                if (ns != null) {
-                    Attribute attr = element.getAttribute(lname, ns);
-                    if (attr != null) {
-                        attributes.add(attr);
-                    }
+                Attribute attr = element.getAttribute(lname, ns);
+                if (attr != null) {
+                    attributes.add(attr);
                 }
             }
             else {
@@ -79,7 +77,8 @@
                 List allAttributes = element.getAttributes();
                 for (int i = 0; i < allAttributes.size(); i++) {
                     Attribute attr = (Attribute) allAttributes.get(i);
-                    if (attr.getNamespace().equals(ns)) {
+                    if (ns == Namespace.NO_NAMESPACE
+                            || attr.getNamespace().equals(ns)) {
                         attributes.add(attr);
                     }
                 }

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestCase.java?rev=617940&r1=617939&r2=617940&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestCase.java (original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestCase.java Sat
Feb  2 18:13:59 2008
@@ -250,6 +250,13 @@
         return list;
     }
 
+    protected static Set set(Object o1, Object o2) {
+        Set list = new HashSet();
+        list.add(o1);
+        list.add(o2);
+        return list;
+    }
+
     protected static Set set(Object o1, Object o2, Object o3) {
         Set list = new HashSet();
         list.add(o1);

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java?rev=617940&r1=617939&r2=617940&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
(original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
Sat Feb  2 18:13:59 2008
@@ -553,8 +553,15 @@
 
         // attribute:: with default namespace and wildcard
         assertXPathValueIterator(
+                context,
+                "vendor/product/price:amount/@*",
+                //use a set because DOM returns attrs sorted by name, JDOM by occurrence
order:
+                set("10%", "20%"));
+
+        // attribute:: select non-ns'd attributes only
+        assertXPathValueIterator(
             context,
-            "vendor/product/price:amount/@*",
+            "vendor/product/price:amount/@*[namespace-uri() = '']",
             list("20%"));
 
         // Empty attribute



Mime
View raw message