diff options
Diffstat (limited to 'libjava/classpath/gnu/xml/xpath')
-rw-r--r-- | libjava/classpath/gnu/xml/xpath/LangFunction.java | 12 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/xpath/NodeTypeTest.java | 1 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/xpath/Selector.java | 41 |
3 files changed, 35 insertions, 19 deletions
diff --git a/libjava/classpath/gnu/xml/xpath/LangFunction.java b/libjava/classpath/gnu/xml/xpath/LangFunction.java index 2c2506d..584787e 100644 --- a/libjava/classpath/gnu/xml/xpath/LangFunction.java +++ b/libjava/classpath/gnu/xml/xpath/LangFunction.java @@ -1,5 +1,5 @@ /* LangFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004,2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -91,9 +91,15 @@ final class LangFunction String getLang(Node node) { - if (node.getNodeType() == Node.ELEMENT_NODE) + while (node != null) { - return ((Element) node).getAttribute("xml:lang"); + if (node.getNodeType() == Node.ELEMENT_NODE) + { + String lang = ((Element) node).getAttribute("xml:lang"); + if (lang != null) + return lang; + } + node = node.getParentNode(); } return null; } diff --git a/libjava/classpath/gnu/xml/xpath/NodeTypeTest.java b/libjava/classpath/gnu/xml/xpath/NodeTypeTest.java index 09e92d0..4fe1646 100644 --- a/libjava/classpath/gnu/xml/xpath/NodeTypeTest.java +++ b/libjava/classpath/gnu/xml/xpath/NodeTypeTest.java @@ -84,6 +84,7 @@ public final class NodeTypeTest case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.COMMENT_NODE: + case Node.DOCUMENT_NODE: if (type > 0) { if (nodeType != type) diff --git a/libjava/classpath/gnu/xml/xpath/Selector.java b/libjava/classpath/gnu/xml/xpath/Selector.java index 93408e4..c7abb33 100644 --- a/libjava/classpath/gnu/xml/xpath/Selector.java +++ b/libjava/classpath/gnu/xml/xpath/Selector.java @@ -90,7 +90,7 @@ public final class Selector if (len > 0) tests.toArray(this.tests); else - this.tests[0] = new NameTest(null, true, true); + this.tests[0] = new NodeTypeTest((short) 0); if (axis == NAMESPACE && this.tests[0] instanceof NameTest) { NameTest nt = (NameTest) this.tests[0]; @@ -108,6 +108,14 @@ public final class Selector public boolean matches(Node context) { + // If called directly, selector is the top level of the path + return matches(context, + getContextPosition(context), + getContextSize(context)); + } + + boolean matches(Node context, int pos, int len) + { short nodeType = context.getNodeType(); switch (axis) { @@ -125,19 +133,11 @@ public final class Selector default: return false; } - int tlen = tests.length; - if (tlen > 0) + for (int j = 0; j < tests.length && len > 0; j++) { - int pos = getContextPosition(context); - int len = getContextSize(context); - if (len == 0) - System.err.println("WARNING: context size is 0"); - for (int j = 0; j < tlen && len > 0; j++) - { - Test test = tests[j]; - if (!test.matches(context, pos, len)) - return false; - } + Test test = tests[j]; + if (!test.matches(context, pos, len)) + return false; } return true; } @@ -147,7 +147,10 @@ public final class Selector int pos = 1; for (ctx = ctx.getPreviousSibling(); ctx != null; ctx = ctx.getPreviousSibling()) - pos++; + { + if (tests[0].matches(ctx, 1, 1)) + pos++; + } return pos; } @@ -161,10 +164,16 @@ public final class Selector int count = 1; Node sib = ctx.getPreviousSibling(); for (; sib != null; sib = sib.getPreviousSibling()) - count++; + { + if (tests[0].matches(ctx, 1, 1)) + count++; + } sib = ctx.getNextSibling(); for (; sib != null; sib = sib.getNextSibling()) - count++; + { + if (tests[0].matches(ctx, 1, 1)) + count++; + } return count; } |