1 27 package org.htmlparser.filters; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.NodeFilter; 31 import org.htmlparser.tags.CompositeTag; 32 import org.htmlparser.util.NodeList; 33 34 37 public class HasChildFilter 38 implements 39 NodeFilter 40 { 41 44 protected NodeFilter mChildFilter; 45 46 49 public boolean mRecursive; 50 51 56 public HasChildFilter () 57 { 58 this (null); 59 } 60 61 65 public HasChildFilter (NodeFilter filter) 66 { 67 this (filter, false); 68 } 69 70 80 public HasChildFilter (NodeFilter filter, boolean recursive) 81 { 82 setChildFilter (filter); 83 setRecursive (recursive); } 84 85 89 public NodeFilter getChildFilter () 90 { 91 return (mChildFilter); 92 } 93 94 98 public void setChildFilter (NodeFilter filter) 99 { 100 mChildFilter = filter; 101 } 102 103 108 public boolean getRecursive () 109 { 110 return mRecursive; 111 } 112 113 117 public void setRecursive (boolean recursive) 118 { 119 mRecursive = recursive; 120 } 121 122 126 public boolean accept (Node node) 127 { 128 CompositeTag tag; 129 NodeList children; 130 boolean ret; 131 132 ret = false; 133 if (node instanceof CompositeTag) 134 { 135 tag = (CompositeTag)node; 136 children = tag.getChildren (); 137 if (null != children) 138 { 139 for (int i = 0; !ret && i < children.size (); i++) 140 if (getChildFilter ().accept (children.elementAt (i))) 141 ret = true; 142 if (!ret && getRecursive ()) 144 for (int i = 0; !ret && i < children.size (); i++) 145 if (accept (children.elementAt (i))) 146 ret = true; 147 } 148 } 149 150 return (ret); 151 } 152 } 153 | Popular Tags |