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 2004/06/29 23:15:46 UTC

cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath JXPathContext.java

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 <code>getPointer(xpath).getNode()</code>. Note, that this method
  +	 * produces the same result as <code>getValue()</code> 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