1 27 package org.htmlparser.parserapplications.filterbuilder.wrappers; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.NodeFilter; 31 import org.htmlparser.Parser; 32 import org.htmlparser.filters.NotFilter; 33 import org.htmlparser.parserapplications.filterbuilder.Filter; 34 import org.htmlparser.parserapplications.filterbuilder.SubFilterList; 35 36 39 public class NotFilterWrapper 40 extends 41 Filter 42 { 43 46 protected SubFilterList mContainer; 47 48 51 protected NotFilter mFilter; 52 53 56 public NotFilterWrapper () 57 { 58 mFilter = new NotFilter (); 59 60 mContainer = new SubFilterList (this, "Predicate", 1); 62 add (mContainer); 63 } 64 65 69 public String getDescription () 70 { 71 return ("Not"); 72 } 73 74 public String getIconSpec () 75 { 76 return ("images/NotFilter.gif"); 77 } 78 79 public NodeFilter getNodeFilter () 80 { 81 NodeFilter predicate; 82 NotFilter ret; 83 84 ret = new NotFilter (); 85 86 predicate = mFilter.getPredicate (); 87 if (null != predicate) 88 ret.setPredicate (((Filter)predicate).getNodeFilter ()); 89 90 return (ret); 91 } 92 93 public void setNodeFilter (NodeFilter filter, Parser context) 94 { 95 mFilter = (NotFilter)filter; 96 } 97 98 public NodeFilter[] getSubNodeFilters () 99 { 100 NodeFilter predicate; 101 NodeFilter[] ret; 102 103 predicate = mFilter.getPredicate (); 104 if (null != predicate) 105 ret = new NodeFilter[] { predicate }; 106 else 107 ret = new NodeFilter[0]; 108 109 return (ret); 110 } 111 112 public void setSubNodeFilters (NodeFilter[] filters) 113 { 114 if (0 != filters.length) 115 mFilter.setPredicate (filters[0]); 116 else 117 mFilter.setPredicate (null); 118 } 119 120 public String toJavaCode (StringBuffer out, int[] context) 121 { 122 String name; 123 String ret; 124 125 if (null != mFilter.getPredicate ()) 126 name = ((Filter)mFilter.getPredicate ()).toJavaCode (out, context); 127 else 128 name = null; 129 ret = "filter" + context[1]++; 130 spaces (out, context[0]); 131 out.append ("NotFilter "); 132 out.append (ret); 133 out.append (" = new NotFilter ();"); 134 newline (out); 135 if (null != name) 136 { 137 spaces (out, context[0]); 138 out.append (ret); 139 out.append (".setPredicate ("); 140 out.append (name); 141 out.append (");"); 142 newline (out); 143 } 144 145 return (ret); 146 } 147 148 152 public boolean accept (Node node) 153 { 154 return (mFilter.accept (node)); 155 } 156 } 157 | Popular Tags |