1 25 package org.nemesis.forum.filter; 26 27 import java.io.Serializable ; 28 import java.util.Enumeration ; 29 import java.util.Map ; 30 import java.util.Properties ; 31 32 import org.nemesis.forum.Message; 33 import org.nemesis.forum.MessageFilter; 34 35 38 public class FilterHackerSpeak extends MessageFilter implements Serializable { 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 FilterHackerSpeak() { 62 super(); 63 props = new Properties (); 64 propDescriptions = new Properties (); 65 } 66 67 75 public FilterHackerSpeak(Message message, Properties props, Properties propDescriptions) { 76 super(message); 77 this.props = new Properties (props); 78 this.propDescriptions = new Properties (propDescriptions); 79 } 80 81 87 public MessageFilter clone(Message message) { 88 return new FilterHackerSpeak(message, props, propDescriptions); 89 } 90 91 94 public String getName() { 95 return "Hacker Speak"; 96 } 97 98 101 public String getDescription() { 102 return "Translates normal text into 'Hacker Speak'."; 103 } 104 105 108 public String getAuthor() { 109 return "CoolServlets.com"; 110 } 111 112 115 public int getMajorVersion() { 116 return 1; 117 } 118 119 122 public int getMinorVersion() { 123 return 0; 124 } 125 126 132 public String getFilterProperty(String name) { 133 return props.getProperty(name); 134 } 135 136 142 public String getFilterPropertyDescription(String name) { 143 return propDescriptions.getProperty(name); 144 } 145 146 149 public Enumeration getFilterPropertyNames() { 150 return null; 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 makeHacker(message.getSubject()); 177 } 178 179 183 public String getBody() { 184 return makeHacker(message.getBody()); 185 } 186 187 196 private String makeHacker(String input) { 197 if (input == null || input.length() == 0) { 200 return input; 201 } 202 StringBuffer buf = new StringBuffer (input.length()); 205 char ch = ' '; 206 for (int i = 0; i < input.length(); i++) { 207 ch = input.charAt(i); 208 if (Math.random() < .20) { 209 if (ch == 'a') { 210 buf.append("@"); 211 } else if (ch == 'e') { 212 buf.append("3"); 213 } else if (ch == 'g') { 214 buf.append("6"); 215 } else if (ch == 'i') { 216 buf.append("1"); 217 } else if (ch == 'o') { 218 buf.append("0"); 219 } else if (ch == 't') { 220 buf.append("7"); 221 } else if (ch == 's') { 222 buf.append("$"); 223 } else { 224 buf.append(ch); 225 } 226 } else { 227 buf.append(ch); 228 } 229 } 230 return buf.toString(); 231 } 232 } 233 | Popular Tags |