1 53 54 106 107 package com.Yasna.forum.filter; 108 109 import java.util.*; 110 111 import com.Yasna.forum.*; 112 113 117 public class FilterSmileyFace extends ForumMessageFilter { 118 119 122 private Properties props; 123 124 127 private Properties propDescriptions; 128 129 134 public FilterSmileyFace() { 135 super(); 136 props = new Properties(); 137 propDescriptions = new Properties(); 138 initializeProperties(); 139 } 140 141 149 public FilterSmileyFace(ForumMessage message, Properties props, 150 Properties propDescriptions) 151 { 152 super(message); 153 this.props = new Properties(props); 154 this.propDescriptions = new Properties(propDescriptions); 155 } 156 157 163 public ForumMessageFilter clone(ForumMessage message){ 164 return new FilterSmileyFace(message, props, propDescriptions); 165 } 166 167 170 public String getName() { 171 return "ASCII Face Converter"; 172 } 173 174 177 public String getDescription() { 178 return "Converts ASCII faces to images. The faces currently " + 179 "handled are :) , :( , and 8)"; 180 } 181 182 185 public String getAuthor() { 186 return "CoolServlets.com"; 187 } 188 189 192 public int getMajorVersion() { 193 return 1; 194 } 195 196 199 public int getMinorVersion() { 200 return 0; 201 } 202 203 209 public String getFilterProperty(String name) { 210 return props.getProperty(name); 211 } 212 213 219 public String getFilterPropertyDescription(String name) { 220 return propDescriptions.getProperty(name); 221 } 222 223 226 public Enumeration filterPropertyNames() { 227 return props.propertyNames(); 228 } 229 230 240 public void setFilterProperty(String name, String value) 241 throws IllegalArgumentException 242 { 243 if (props.getProperty(name) == null) { 244 throw new IllegalArgumentException (); 245 } 246 props.put(name, value); 247 } 248 249 253 public String getSubject() { 254 return addSmileyFace(message.getSubject()); 255 } 256 257 261 public String getBody() { 262 return addSmileyFace(message.getBody()); 263 } 264 265 268 private void initializeProperties() { 269 props.put("happyURL",""); 270 props.put("sadURL",""); 271 props.put("coolURL",""); 272 273 propDescriptions.put("happyURL","URL of the desired :) image"); 274 propDescriptions.put("sadURL","URL of the desired :( image"); 275 propDescriptions.put("coolURL","URL of the desired 8) image"); 276 } 277 278 286 private String addSmileyFace( String input ) { 287 String happy = props.getProperty("happyURL"); 288 String sad = props.getProperty("sadURL"); 289 String cool = props.getProperty("coolURL"); 290 291 if( input == null || input.length() == 0 ) { 293 return input; 294 } 295 StringBuffer buf = new StringBuffer (); 297 char ch = ' ', ch2 = ' '; 298 int index; 299 for(index = 0; index<input.length()-1; index++ ) { 300 ch = input.charAt(index); ch2 = input.charAt(index+1); 301 if (happy != null && happy.length() > 0 && ch == ':' && ch2 == ')') { 302 buf.append("<img SRC=\"").append(happy).append("\">"); 303 index++; } 305 else if (sad != null && sad.length() > 0 && ch == ':' && ch2 == '(') { 306 buf.append("<img SRC=\"").append(sad).append("\">"); 307 index++; } 309 else if (cool != null && cool.length() > 0 && ch == '8' && ch2 == ')') { 310 buf.append("<img SRC=\"").append(cool).append("\">"); 311 index++; } 313 else { 314 buf.append( ch ); 315 } 316 } 317 if (index != input.length()) { 319 buf.append(input.charAt(input.length()-1)); 320 } 321 return buf.toString(); 322 } 323 } 324 | Popular Tags |