[Htmlparser-cvs] htmlparser/src/org/htmlparser/util NodeList.java,1.51,1.52
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-12-31 02:50:54
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1:/tmp/cvs-serv23579/src/org/htmlparser/util Modified Files: NodeList.java Log Message: Add filter support to NodeList. Rework LinkExtractor and remove MailRipper and Robot example programs. Clean out docs directory. Index: NodeList.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeList.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** NodeList.java 20 Dec 2003 23:47:55 -0000 1.51 --- NodeList.java 31 Dec 2003 02:50:50 -0000 1.52 *************** *** 33,36 **** --- 33,38 ---- import org.htmlparser.Node; + import org.htmlparser.NodeFilter; + import org.htmlparser.filters.NodeClassFilter; public class NodeList implements Serializable { *************** *** 183,200 **** /** ! * Search for nodes of the given type non-recursively. ! * @param classType The class to search for. */ ! public NodeList searchFor (Class classType) { ! return (searchFor (classType, false)); } /** ! * Search for nodes of the given type recursively. ! * @param classType The class to search for. * @param recursive If <code>true<code> digs into the children recursively. */ ! public NodeList searchFor (Class classType, boolean recursive) { String name; --- 185,202 ---- /** ! * Filter the list with the given filter non-recursively. ! * @param filter The filter to use. */ ! public NodeList extractAllNodesThatMatch (NodeFilter filter) { ! return (extractAllNodesThatMatch (filter, false)); } /** ! * Filter the list with the given filter. ! * @param filter The filter to use. * @param recursive If <code>true<code> digs into the children recursively. */ ! public NodeList extractAllNodesThatMatch (NodeFilter filter, boolean recursive) { String name; *************** *** 204,212 **** ret = new NodeList (); - name = classType.getName (); for (int i = 0; i < size; i++) { node = nodeData[i]; ! if (node.getClass ().getName ().equals (name)) ret.add (node); if (recursive) --- 206,213 ---- ret = new NodeList (); for (int i = 0; i < size; i++) { node = nodeData[i]; ! if (filter.accept (node)) ret.add (node); if (recursive) *************** *** 214,222 **** children = node.getChildren (); if (null != children) ! ret.add (children.searchFor (classType, recursive)); } } return (ret); } } --- 215,242 ---- children = node.getChildren (); if (null != children) ! ret.add (children.extractAllNodesThatMatch (filter, recursive)); } } return (ret); + } + + /** + * Convenience method to search for nodes of the given type non-recursively. + * @param classType The class to search for. + */ + public NodeList searchFor (Class classType) + { + return (searchFor (classType, false)); + } + + /** + * Convenience method to search for nodes of the given type. + * @param classType The class to search for. + * @param recursive If <code>true<code> digs into the children recursively. + */ + public NodeList searchFor (Class classType, boolean recursive) + { + return (extractAllNodesThatMatch (new NodeClassFilter (classType), recursive)); } } |