diff options
| author | Chris Burdess <dog@bluezoo.org> | 2006-09-09 12:12:47 +0000 |
|---|---|---|
| committer | Chris Burdess <dog@bluezoo.org> | 2006-09-09 12:12:47 +0000 |
| commit | 2d232dfa1745cde43da4085e536f138efaa65b32 (patch) | |
| tree | 723ddd0c7fd6162f7a54ecce623bc7a1d39941fc /gnu/xml/xpath/Expr.java | |
| parent | 5e419144c965f56036fbe83f1c8d640ada47a38a (diff) | |
| download | classpath-2d232dfa1745cde43da4085e536f138efaa65b32.tar.gz | |
2006-09-09 Chris Burdess <dog@gnu.org>
* gnu/xml/xpath/Expr.java: Ensure that node-set evaluation returns
an instance of org.w3c.dom.NodeList.
Diffstat (limited to 'gnu/xml/xpath/Expr.java')
| -rw-r--r-- | gnu/xml/xpath/Expr.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gnu/xml/xpath/Expr.java b/gnu/xml/xpath/Expr.java index 76fd49eef..cafc83b0d 100644 --- a/gnu/xml/xpath/Expr.java +++ b/gnu/xml/xpath/Expr.java @@ -59,6 +59,7 @@ import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -80,6 +81,38 @@ public abstract class Expr ".####################################################", new DecimalFormatSymbols(Locale.US)); + static class ExprNodeSet implements NodeList + { + + private ArrayList list; + + ExprNodeSet(Collection collection) + { + if (collection instanceof ArrayList) + list = (ArrayList) collection; + else + list = new ArrayList(collection); + } + + public int getLength() + { + return list.size(); + } + + public Node item(int index) + { + try + { + return (Node) list.get(index); + } + catch (ArrayIndexOutOfBoundsException e) + { + return null; + } + } + + } + public Object evaluate(Object item, QName returnType) throws XPathExpressionException { @@ -132,6 +165,8 @@ public abstract class Expr { throw new XPathExpressionException("return value is not a node-set"); } + if (ret != null) + ret = new ExprNodeSet((Collection) ret); } } return ret; |
