You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dm...@apache.org on 2002/11/29 07:44:17 UTC
cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes DescendantContext.java
dmitri 2002/11/28 22:44:17
Modified: jxpath/src/test/org/apache/commons/jxpath/ri/model
XMLModelTestCase.java
jxpath/src/test/org/apache/commons/jxpath Vendor.xml
jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom
JDOMNodePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
DOMNodePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/axes
DescendantContext.java
Log:
Fixed the implementation of the "*" name test
Revision Changes Path
1.5 +24 -12 jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
Index: XMLModelTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLModelTestCase.java 26 Nov 2002 01:33:35 -0000 1.4
+++ XMLModelTestCase.java 29 Nov 2002 06:44:15 -0000 1.5
@@ -328,7 +328,7 @@
// child:: with the default namespace
assertXPathValue(context,
"count(vendor/product/*)",
- new Double(2));
+ new Double(4));
// child:: with a qualified name
assertXPathValue(context,
@@ -352,6 +352,22 @@
assertXPathValue(context,
"count(//price:*)",
new Double(2));
+
+ assertXPathValueIterator(context,
+ "vendor//saleEnds",
+ list("never"));
+
+ assertXPathValueIterator(context,
+ "vendor//promotion",
+ list(""));
+
+ assertXPathValueIterator(context,
+ "vendor//saleEnds[../@stores = 'all']",
+ list("never"));
+
+ assertXPathValueIterator(context,
+ "vendor//promotion[../@stores = 'all']",
+ list(""));
}
public void testAxisParent() {
@@ -484,16 +500,12 @@
"vendor/location[@id='101']//street",
"Tangerine Drive");
}
-
+
public void testAxisNamespace() {
// namespace::
- assertXPathValue(context,
- "vendor/product/prix/namespace::price",
- "priceNS");
-
- // namespace:: pointer
- assertXPathPointer(context,
+ assertXPathValueAndPointer(context,
"vendor/product/prix/namespace::price",
+ "priceNS",
"/vendor[1]/product[1]/prix[1]/namespace::price");
// namespace::*
1.6 +2 -1 jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/Vendor.xml
Index: Vendor.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/Vendor.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Vendor.xml 20 Oct 2002 03:48:21 -0000 1.5
+++ Vendor.xml 29 Nov 2002 06:44:16 -0000 1.6
@@ -39,8 +39,9 @@
<!-- We are not buying this product, ever -->
<price:amount price:discount="10%" discount="20%">45.95</price:amount>
<prix xml:lang="fr">934.99</prix>
- <price:sale>
+ <price:sale stores="all">
<saleEnds>never</saleEnds>
+ <promotion></promotion>
</price:sale>
<?security do not show anybody ?>
<?report average only ?>
1.6 +10 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
Index: JDOMNodePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JDOMNodePointer.java 26 Nov 2002 01:33:34 -0000 1.5
+++ JDOMNodePointer.java 29 Nov 2002 06:44:16 -0000 1.6
@@ -412,7 +412,12 @@
QName testName = ((NodeNameTest)test).getNodeName();
String testLocalName = testName.getName();
- if (testLocalName.equals("*") ||
+ boolean wildcard = testLocalName.equals("*");
+ if (wildcard && testName.getPrefix() == null){
+ return true;
+ }
+
+ if (wildcard ||
testLocalName.equals(
JDOMNodePointer.getLocalName((Element)node))){
String testPrefix = testName.getPrefix();
1.14 +15 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
Index: DOMNodePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DOMNodePointer.java 26 Nov 2002 01:33:34 -0000 1.13
+++ DOMNodePointer.java 29 Nov 2002 06:44:16 -0000 1.14
@@ -135,12 +135,18 @@
if (node.getNodeType() != Node.ELEMENT_NODE){
return false;
}
+// System.err.println("Testing: " + ((Element)node).getTagName());
QName testName = ((NodeNameTest)test).getNodeName();
String testLocalName = testName.getName();
- if (testLocalName.equals("*") ||
+ boolean wildcard = testLocalName.equals("*");
+ String testPrefix = testName.getPrefix();
+ if (wildcard && testPrefix == null){
+ return true;
+ }
+
+ if (wildcard ||
testLocalName.equals(DOMNodePointer.getLocalName(node))){
- String testPrefix = testName.getPrefix();
String nodePrefix = DOMNodePointer.getPrefix(node);
if (equalStrings(testPrefix, nodePrefix)){
return true;
@@ -318,6 +324,9 @@
}
public boolean isLeaf(){
+ if (node instanceof Element){
+// System.err.println("HAS CHILD NODES: " + ((Element)node).getTagName() + " " + !node.hasChildNodes());
+ }
return !node.hasChildNodes();
}
1.10 +34 -24 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java
Index: DescendantContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DescendantContext.java 20 Oct 2002 03:43:38 -0000 1.9
+++ DescendantContext.java 29 Nov 2002 06:44:16 -0000 1.10
@@ -63,10 +63,10 @@
import java.util.Stack;
+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;
@@ -84,9 +84,13 @@
private NodePointer currentNodePointer;
private boolean includeSelf;
private final static NodeTest elementNodeTest =
- new NodeNameTest(new QName(null, "*"));
+ new NodeTypeTest(Compiler.NODE_TYPE_NODE);
- public DescendantContext(EvalContext parentContext, boolean includeSelf, NodeTest nodeTest){
+ public DescendantContext(
+ EvalContext parentContext,
+ boolean includeSelf,
+ NodeTest nodeTest)
+ {
super(parentContext);
this.includeSelf = includeSelf;
this.nodeTest = nodeTest;
@@ -107,7 +111,6 @@
}
public boolean setPosition(int position){
-// System.err.println("POSITION: " + position + " this.position=" + this.position);
if (position < this.position){
reset();
}
@@ -121,17 +124,20 @@
}
public boolean nextNode(){
- if (!setStarted){
+ if (!setStarted) {
setStarted = true;
stack = new Stack();
currentNodePointer = parentContext.getCurrentNodePointer();
- if (currentNodePointer != null){
- if (!currentNodePointer.isLeaf()){
- stack.push(currentNodePointer.childIterator(
- elementNodeTest, false, null));
+ if (currentNodePointer != null) {
+ if (!currentNodePointer.isLeaf()) {
+ stack.push(
+ currentNodePointer.childIterator(
+ elementNodeTest,
+ false,
+ null));
}
- if (includeSelf){
- if (currentNodePointer.testNode(nodeTest)){
+ if (includeSelf) {
+ if (currentNodePointer.testNode(nodeTest)) {
position++;
return true;
}
@@ -139,21 +145,25 @@
}
}
- while (!stack.isEmpty()){
- NodeIterator it = (NodeIterator)stack.peek();
- if (it.setPosition(it.getPosition() + 1)){
+ while (!stack.isEmpty()) {
+ NodeIterator it = (NodeIterator) stack.peek();
+ if (it.setPosition(it.getPosition() + 1)) {
currentNodePointer = it.getNodePointer();
- if (!currentNodePointer.isLeaf()){
- stack.push(currentNodePointer.childIterator(
- elementNodeTest, false, null));
+ if (!currentNodePointer.isLeaf()) {
+ stack.push(
+ currentNodePointer.childIterator(
+ elementNodeTest,
+ false,
+ null));
}
- if (currentNodePointer.testNode(nodeTest)){
+ if (currentNodePointer.testNode(nodeTest)) {
position++;
return true;
}
}
else {
- // We get here only if the name test failed and the iterator ended
+ // We get here only if the name test failed
+ // and the iterator ended
stack.pop();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>