1 27 package org.htmlparser.filters; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.NodeFilter; 31 import org.htmlparser.Tag; 32 import org.htmlparser.util.NodeList; 33 34 38 public class HasSiblingFilter 39 implements 40 NodeFilter 41 { 42 45 public NodeFilter mSiblingFilter; 46 47 52 public HasSiblingFilter () 53 { 54 this (null); 55 } 56 57 61 public HasSiblingFilter (NodeFilter filter) 62 { 63 setSiblingFilter (filter); 64 } 65 66 70 public NodeFilter getSiblingFilter () 71 { 72 return (mSiblingFilter); 73 } 74 75 79 public void setSiblingFilter (NodeFilter filter) 80 { 81 mSiblingFilter = filter; 82 } 83 84 88 public boolean accept (Node node) 89 { 90 Node parent; 91 NodeList siblings; 92 int count; 93 boolean ret; 94 95 ret = false; 96 if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) 97 { 98 parent = node.getParent (); 99 if (null != parent) 100 { 101 siblings = parent.getChildren (); 102 if (null != siblings) 103 { 104 count = siblings.size (); 105 for (int i = 0; !ret && (i < count); i++) 106 if (getSiblingFilter ().accept (siblings.elementAt (i))) 107 ret = true; 108 } 109 else 110 System.out.println("gotcha"); 111 } 112 } 113 114 return (ret); 115 } 116 } 117 | Popular Tags |