Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 69399 invoked from network); 29 Jun 2004 21:15:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 29 Jun 2004 21:15:56 -0000 Received: (qmail 97405 invoked by uid 500); 29 Jun 2004 21:16:07 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 97319 invoked by uid 500); 29 Jun 2004 21:16:05 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 97275 invoked by uid 500); 29 Jun 2004 21:16:05 -0000 Received: (qmail 97253 invoked by uid 99); 29 Jun 2004 21:16:04 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 29 Jun 2004 14:16:04 -0700 Received: (qmail 69317 invoked by uid 1328); 29 Jun 2004 21:15:46 -0000 Date: 29 Jun 2004 21:15:46 -0000 Message-ID: <20040629211546.69316.qmail@minotaur.apache.org> From: dmitri@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath JXPathContext.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N dmitri 2004/06/29 14:15:46 Modified: jxpath/src/java/org/apache/commons/jxpath JXPathContext.java Log: Added selectNodes and selectSingleNode methods Revision Changes Path 1.25 +37 -1 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java Index: JXPathContext.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- JXPathContext.java 4 Apr 2004 23:16:23 -0000 1.24 +++ JXPathContext.java 29 Jun 2004 21:15:46 -0000 1.25 @@ -16,8 +16,10 @@ package org.apache.commons.jxpath; import java.text.DecimalFormatSymbols; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Locale; /** @@ -623,6 +625,40 @@ */ protected abstract CompiledExpression compilePath(String xpath); + /** + * Finds the first object that matches the specified XPath. It is equivalent + * to getPointer(xpath).getNode(). Note, that this method + * produces the same result as getValue() on object models + * like JavaBeans, but a different result for DOM/JDOM etc., because it + * returns the Node itself, rather than its textual contents. + * + * @param xpath the xpath to be evaluated + * @return the found object + */ + public Object selectSingleNode(String xpath) { + Pointer pointer = getPointer(xpath); + if (pointer == null) { + return null; + } + return pointer.getNode(); + } + + /** + * Finds all nodes that match the specified XPath. + * + * @param xpath the xpath to be evaluated + * @return a list of found objects + */ + public List selectNodes(String xpath) { + ArrayList list = new ArrayList(); + Iterator iterator = iteratePointers(xpath); + while (iterator.hasNext()) { + Pointer pointer = (Pointer) iterator.next(); + list.add(pointer.getNode()); + } + return list; + } + /** * Evaluates the xpath and returns the resulting object. Primitive * types are wrapped into objects. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org