Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util
In directory sc8-pr-cvs1:/tmp/cvs-serv24025/util
Modified Files:
NodeList.java
Log Message:
First pass at the wiki capturer.
Added useful extensions to the HasAttributeFilter, SiteCapturer and NodeList
Index: NodeList.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeList.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** NodeList.java 2 Jan 2004 16:24:58 -0000 1.53
--- NodeList.java 10 Jan 2004 00:06:03 -0000 1.54
***************
*** 185,188 ****
--- 185,191 ----
* Filter the list with the given filter non-recursively.
* @param filter The filter to use.
+ * @return A new node array containing the nodes accepted by the filter.
+ * This is a linear list and preserves the nested structure of the returned
+ * nodes only.
*/
public NodeList extractAllNodesThatMatch (NodeFilter filter)
***************
*** 195,198 ****
--- 198,204 ----
* @param filter The filter to use.
* @param recursive If <code>true<code> digs into the children recursively.
+ * @return A new node array containing the nodes accepted by the filter.
+ * This is a linear list and preserves the nested structure of the returned
+ * nodes only.
*/
public NodeList extractAllNodesThatMatch (NodeFilter filter, boolean recursive)
***************
*** 218,221 ****
--- 224,266 ----
return (ret);
+ }
+
+ /**
+ * Remove nodes not matching the given filter non-recursively.
+ * @param filter The filter to use.
+ */
+ public void keepAllNodesThatMatch (NodeFilter filter)
+ {
+ keepAllNodesThatMatch (filter, false);
+ }
+
+ /**
+ * Remove nodes not matching the given filter.
+ * @param filter The filter to use.
+ * @param recursive If <code>true<code> digs into the children recursively.
+ */
+ public void keepAllNodesThatMatch (NodeFilter filter, boolean recursive)
+ {
+ String name;
+ Node node;
+ NodeList children;
+ NodeList ret;
+
+ for (int i = 0; i < size; )
+ {
+ node = nodeData[i];
+ if (!filter.accept (node))
+ remove (i);
+ else
+ {
+ if (recursive)
+ {
+ children = node.getChildren ();
+ if (null != children)
+ children.keepAllNodesThatMatch (filter, recursive);
+ }
+ i++;
+ }
+ }
}
|