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.OrFilter; 33 import org.htmlparser.parserapplications.filterbuilder.Filter; 34 import org.htmlparser.parserapplications.filterbuilder.SubFilterList; 35 36 39 public class OrFilterWrapper 40 extends 41 Filter 42 { 43 46 protected SubFilterList mContainer; 47 48 51 protected OrFilter mFilter; 52 53 56 public OrFilterWrapper () 57 { 58 mFilter = new OrFilter (); 59 60 mContainer = new SubFilterList (this, "Predicates", 0); 62 add (mContainer); 63 } 64 65 69 public String getDescription () 70 { 71 return ("Or"); 72 } 73 74 public String getIconSpec () 75 { 76 return ("images/OrFilter.gif"); 77 } 78 79 public NodeFilter getNodeFilter () 80 { 81 NodeFilter[] predicates; 82 NodeFilter[] temp; 83 OrFilter ret; 84 85 ret = new OrFilter (); 86 87 predicates = mFilter.getPredicates (); 88 temp = new NodeFilter[predicates.length]; 89 for (int i = 0; i < predicates.length; i++) 90 temp[i] = ((Filter)predicates[i]).getNodeFilter (); 91 ret.setPredicates (temp); 92 93 return (ret); 94 } 95 96 public void setNodeFilter (NodeFilter filter, Parser context) 97 { 98 mFilter = (OrFilter)filter; 99 } 100 101 public NodeFilter[] getSubNodeFilters () 102 { 103 return (mFilter.getPredicates ()); 104 } 105 106 public void setSubNodeFilters (NodeFilter[] filters) 107 { 108 mFilter.setPredicates (filters); 109 } 110 111 public String toJavaCode (StringBuffer out, int[] context) 112 { 113 String array; 114 NodeFilter[] predicates; 115 String [] names; 116 String ret; 117 118 predicates = mFilter.getPredicates (); 119 array = null; if (0 != predicates.length) 121 { 122 names = new String [predicates.length]; 123 for (int i = 0; i < predicates.length; i++) 124 { 125 names[i] = ((Filter)predicates[i]).toJavaCode (out, context); 126 } 127 array = "array" + context[2]++; 128 spaces (out, context[0]); 129 out.append ("NodeFilter[] "); 130 out.append (array); 131 out.append (" = new NodeFilter["); 132 out.append (predicates.length); 133 out.append ("];"); 134 newline (out); 135 for (int i = 0; i < predicates.length; i++) 136 { 137 spaces (out, context[0]); 138 out.append (array); 139 out.append ("["); 140 out.append (i); 141 out.append ("] = "); 142 out.append (names[i]); 143 out.append (";"); 144 newline (out); 145 } 146 } 147 ret = "filter" + context[1]++; 148 spaces (out, context[0]); 149 out.append ("OrFilter "); 150 out.append (ret); 151 out.append (" = new OrFilter ();"); 152 newline (out); 153 if (0 != predicates.length) 154 { 155 spaces (out, context[0]); 156 out.append (ret); 157 out.append (".setPredicates ("); 158 out.append (array); 159 out.append (");"); 160 newline (out); 161 } 162 163 return (ret); 164 } 165 166 170 public boolean accept (Node node) 171 { 172 return (mFilter.accept (node)); 173 } 174 } 175 | Popular Tags |