commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r617942 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/axes/AttributeContext.java test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
Date Sun, 03 Feb 2008 03:36:05 GMT
Author: mbenson
Date: Sat Feb  2 19:36:01 2008
New Revision: 617942

URL: http://svn.apache.org/viewvc?rev=617942&view=rev
Log:
[JXPATH-115] enable attribute::node()

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/AttributeContext.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/axes/AttributeContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java?rev=617942&r1=617941&r2=617942&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java
Sat Feb  2 19:36:01 2008
@@ -16,10 +16,12 @@
  */
 package org.apache.commons.jxpath.ri.axes;
 
+import org.apache.commons.jxpath.ri.Compiler;
 import org.apache.commons.jxpath.ri.EvalContext;
 import org.apache.commons.jxpath.ri.QName;
 import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
 import org.apache.commons.jxpath.ri.compiler.NodeTest;
+import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
 import org.apache.commons.jxpath.ri.model.NodeIterator;
 import org.apache.commons.jxpath.ri.model.NodePointer;
 
@@ -30,6 +32,8 @@
  * @version $Revision$ $Date$
  */
 public class AttributeContext extends EvalContext {
+    private static final NodeNameTest WILDCARD_TEST = new NodeNameTest(new QName(null, "*"));
+
     private NodeTest nodeTest;
     private boolean setStarted = false;
     private NodeIterator iterator;
@@ -71,14 +75,21 @@
         super.setPosition(getCurrentPosition() + 1);
         if (!setStarted) {
             setStarted = true;
-            if (!(nodeTest instanceof NodeNameTest)) {
+            NodeNameTest nodeNameTest = null;
+            if (nodeTest instanceof NodeTypeTest) {
+                if (((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE) {
+                    nodeNameTest = WILDCARD_TEST;
+                }
+            }
+            else if (nodeTest instanceof NodeNameTest) {
+                nodeNameTest = (NodeNameTest) nodeTest;
+            }
+            if (nodeNameTest == null) {
                 return false;
             }
-            QName name = ((NodeNameTest) nodeTest).getNodeName();
-            iterator =
-                parentContext.getCurrentNodePointer().attributeIterator(name);
+            iterator = parentContext.getCurrentNodePointer().attributeIterator(
+                    nodeNameTest.getNodeName());
         }
-
         if (iterator == null) {
             return false;
         }

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=617942&r1=617941&r2=617942&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 19:36:01 2008
@@ -558,6 +558,13 @@
                 //use a set because DOM returns attrs sorted by name, JDOM by occurrence
order:
                 set("10%", "20%"));
 
+        // attribute::node()
+        assertXPathValueIterator(
+                context,
+                "vendor/product/price:amount/attribute::node()",
+                //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,



Mime
View raw message