1 25 package org.nemesis.forum.filter; 26 27 import java.util.Enumeration ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 31 import org.nemesis.forum.Message; 32 import org.nemesis.forum.MessageFilter; 33 34 38 public class FilterSmileyFace extends MessageFilter { 39 40 43 private Properties props; 44 public Map getFilterProperties(){ 46 return props; 47 } 48 51 private Properties propDescriptions; 52 public Map getFilterPropertiesDescription(){ 54 return propDescriptions; 55 } 56 61 public FilterSmileyFace() { 62 super(); 63 props = new Properties (); 64 propDescriptions = new Properties (); 65 initializeProperties(); 66 } 67 68 76 public FilterSmileyFace(Message message, Properties props, Properties propDescriptions) { 77 super(message); 78 this.props = new Properties (props); 79 this.propDescriptions = new Properties (propDescriptions); 80 } 81 82 88 public MessageFilter clone(Message message) { 89 return new FilterSmileyFace(message, props, propDescriptions); 90 } 91 92 95 public String getName() { 96 return "ASCII Face Converter"; 97 } 98 99 102 public String getDescription() { 103 return "Converts ASCII faces to images. The faces currently " + "handled are :) , :( , and 8)"; 104 } 105 106 109 public String getAuthor() { 110 return "CoolServlets.com"; 111 } 112 113 116 public int getMajorVersion() { 117 return 1; 118 } 119 120 123 public int getMinorVersion() { 124 return 0; 125 } 126 127 133 public String getFilterProperty(String name) { 134 return props.getProperty(name); 135 } 136 137 143 public String getFilterPropertyDescription(String name) { 144 return propDescriptions.getProperty(name); 145 } 146 147 150 public Enumeration getFilterPropertyNames() { 151 return props.propertyNames(); 152 } 153 154 164 public void setFilterProperty(String name, String value) throws IllegalArgumentException { 165 if (props.getProperty(name) == null) { 166 throw new IllegalArgumentException (); 167 } 168 props.put(name, value); 169 } 170 171 175 public String getSubject() { 176 return addSmileyFace(message.getSubject()); 177 } 178 179 183 public String getBody() { 184 return addSmileyFace(message.getBody()); 185 } 186 187 190 private void initializeProperties() { 191 props.put("happyURL", ""); 192 props.put("sadURL", ""); 193 props.put("coolURL", ""); 194 195 propDescriptions.put("happyURL", "URL of the desired :) image"); 196 propDescriptions.put("sadURL", "URL of the desired :( image"); 197 propDescriptions.put("coolURL", "URL of the desired 8) image"); 198 } 199 200 208 private String addSmileyFace(String input) { 209 String happy = props.getProperty("happyURL"); 210 String sad = props.getProperty("sadURL"); 211 String cool = props.getProperty("coolURL"); 212 213 if (input == null || input.length() == 0) { 215 return input; 216 } 217 StringBuffer buf = new StringBuffer (); 219 char ch = ' ', ch2 = ' '; 220 int index; 221 for (index = 0; index < input.length() - 1; index++) { 222 ch = input.charAt(index); 223 ch2 = input.charAt(index + 1); 224 if (happy != null && happy.length() > 0 && ch == ':' && ch2 == ')') { 225 buf.append("<img SRC=\"").append(happy).append("\">"); 226 index++; } else if (sad != null && sad.length() > 0 && ch == ':' && ch2 == '(') { 228 buf.append("<img SRC=\"").append(sad).append("\">"); 229 index++; } else if (cool != null && cool.length() > 0 && ch == '8' && ch2 == ')') { 231 buf.append("<img SRC=\"").append(cool).append("\">"); 232 index++; } else { 234 buf.append(ch); 235 } 236 } 237 if (index != input.length()) { 239 buf.append(input.charAt(input.length() - 1)); 240 } 241 return buf.toString(); 242 } 243 } 244 | Popular Tags |