1 27 package org.htmlparser.filters; 28 29 import java.util.Locale ; 30 31 import org.htmlparser.Node; 32 import org.htmlparser.NodeFilter; 33 import org.htmlparser.Text; 34 35 41 public class StringFilter 42 implements 43 NodeFilter 44 { 45 48 protected String mPattern; 49 50 53 protected String mUpperPattern; 54 55 59 protected boolean mCaseSensitive; 60 61 64 protected Locale mLocale; 65 66 69 public StringFilter () 70 { 71 this ("", false); 72 } 73 74 79 public StringFilter (String pattern) 80 { 81 this (pattern, false); 82 } 83 84 90 public StringFilter (String pattern, boolean case_sensitive) 91 { 92 this (pattern, case_sensitive, null); 93 } 94 95 103 public StringFilter (String pattern, boolean case_sensitive, Locale locale) 104 { 105 mPattern = pattern; 106 mCaseSensitive = case_sensitive; 107 mLocale = (null == locale) ? Locale.getDefault () : locale; 108 setUpperPattern (); 109 } 110 111 115 118 protected void setUpperPattern () 119 { 120 if (getCaseSensitive ()) 121 mUpperPattern = getPattern (); 122 else 123 mUpperPattern = getPattern ().toUpperCase (getLocale ()); 124 } 125 126 130 public boolean getCaseSensitive () 131 { 132 return (mCaseSensitive); 133 } 134 135 140 public void setCaseSensitive (boolean sensitive) 141 { 142 mCaseSensitive = sensitive; 143 setUpperPattern (); 144 } 145 146 150 public Locale getLocale () 151 { 152 return (mLocale); 153 } 154 155 159 public void setLocale (Locale locale) 160 { 161 mLocale = locale; 162 setUpperPattern (); 163 } 164 165 169 public String getPattern () 170 { 171 return (mPattern); 172 } 173 174 178 public void setPattern (String pattern) 179 { 180 mPattern = pattern; 181 setUpperPattern (); 182 } 183 184 188 194 public boolean accept (Node node) 195 { 196 String string; 197 boolean ret; 198 199 ret = false; 200 if (node instanceof Text) 201 { 202 string = ((Text)node).getText (); 203 if (!getCaseSensitive ()) 204 string = string.toUpperCase (getLocale ()); 205 ret = (-1 != string.indexOf (mUpperPattern)); 206 } 207 208 return (ret); 209 } 210 } 211 | Popular Tags |