[Htmlparser-cvs] htmlparser/src/org/htmlparser/beans FilterBean.java,1.3,1.4
Brought to you by:
derrickoswald
|
From: Derrick O. <der...@us...> - 2005-09-18 23:40:53
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/beans In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32615/src/org/htmlparser/beans Modified Files: FilterBean.java Log Message: Add recursive property on FilterBean suggested by Martin Hudson. Index: FilterBean.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/beans/FilterBean.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FilterBean.java 15 May 2005 11:49:03 -0000 1.3 --- FilterBean.java 18 Sep 2005 23:40:44 -0000 1.4 *************** *** 93,96 **** --- 93,103 ---- protected NodeList mNodes; + /** + * The recursion behaviour for elements of the filter array. + * If <code>true</code> the filters are applied recursively. + * @see org.htmlparser.util.NodeList#extractAllNodesThatMatch(NodeFilter, boolean). + */ + protected boolean mRecursive; + /** * Create a FilterBean object. *************** *** 102,105 **** --- 109,113 ---- mFilters = null; mNodes = null; + mRecursive = true; } *************** *** 144,150 **** /** * Apply each of the filters. ! * The first filter is applied to the parser. * Subsequent filters are applied to the output of the prior filter. * @return A list of nodes passed through all filters. * @throws ParserException If an encoding change occurs * or there is some other problem. --- 152,159 ---- /** * Apply each of the filters. ! * The first filter is applied to the output of the parser. * Subsequent filters are applied to the output of the prior filter. * @return A list of nodes passed through all filters. + * If there are no filters, returns the entire page. * @throws ParserException If an encoding change occurs * or there is some other problem. *************** *** 154,167 **** ParserException { NodeList ret; ! ret = new NodeList (); ! ! if (null != getFilters ()) ! for (int i = 0; i < getFilters ().length; i++) ! if (0 == i) ! ret = mParser.parse (getFilters ()[0]); ! else ! ret = ret.extractAllNodesThatMatch (getFilters ()[i]); return (ret); --- 163,174 ---- ParserException { + NodeFilter[] filters; NodeList ret; ! ret = mParser.parse (null); ! filters = getFilters (); ! if (null != filters) ! for (int i = 0; i < filters.length; i++) ! ret = ret.extractAllNodesThatMatch (filters[i], mRecursive); return (ret); *************** *** 409,412 **** --- 416,440 ---- /** + * Get the current recursion behaviour. + * @return The recursion (applies to children, children's children, etc) + * behavior currently being used. + */ + public boolean getRecursive () + { + return (mRecursive); + } + + /** + * Set the recursion behaviour. + * @param recursive If <code>true</code> the + * <code>extractAllNodesThatMatch()</code> call is performed recursively. + * @see org.htmlparser.util.NodeList#extractAllNodesThatMatch(NodeFilter, boolean). + */ + public void setRecursive (boolean recursive) + { + mRecursive = recursive; + } + + /** * Unit test. * @param args Pass arg[0] as the URL to process, |