1 27 package org.htmlparser.filters; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.NodeFilter; 31 import org.htmlparser.Tag; 32 33 39 public class HasParentFilter 40 implements 41 NodeFilter 42 { 43 46 public NodeFilter mParentFilter; 47 48 51 public boolean mRecursive; 52 53 58 public HasParentFilter () 59 { 60 this (null); 61 } 62 63 67 public HasParentFilter (NodeFilter filter) 68 { 69 this (filter, false); 70 } 71 72 80 public HasParentFilter (NodeFilter filter, boolean recursive) 81 { 82 setParentFilter (filter); 83 setRecursive (recursive); 84 } 85 86 90 public NodeFilter getParentFilter () 91 { 92 return (mParentFilter); 93 } 94 95 99 public void setParentFilter (NodeFilter filter) 100 { 101 mParentFilter = filter; 102 } 103 104 109 public boolean getRecursive () 110 { 111 return mRecursive; 112 } 113 114 118 public void setRecursive (boolean recursive) 119 { 120 mRecursive = recursive; 121 } 122 123 131 public boolean accept (Node node) 132 { 133 Node parent; 134 boolean ret; 135 136 ret = false; 137 if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) 138 { 139 parent = node.getParent (); 140 if ((null != parent) && (null != getParentFilter ())) 141 { 142 ret = getParentFilter ().accept (parent); 143 if (!ret && getRecursive ()) 144 ret = accept (parent); 145 } 146 } 147 148 return (ret); 149 } 150 } 151 | Popular Tags |