| 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 39 public class FilterHtml extends MessageFilter implements Serializable { 40 41 44 private Properties props; 45 public Map getFilterProperties(){ 47 return props; 48 } 49 52 private Properties propDescriptions; 53 public Map getFilterPropertiesDescription(){ 55 return propDescriptions; 56 } 57 62 public FilterHtml() { 63 super(); 64 props = new Properties (); 65 propDescriptions = new Properties (); 66 } 67 68 76 public FilterHtml(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 FilterHtml(message, props, propDescriptions); 90 } 91 92 95 public String getName() { 96 return "HTML Filter"; 97 } 98 99 102 public String getDescription() { 103 return "Escapes HTML tags by converting < and > characters " + "into HTML esacpe sequences."; 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 null; 153 } 154 155 165 public void setFilterProperty(String name, String value) throws IllegalArgumentException { 166 if (props.getProperty(name) == null) { 167 throw new IllegalArgumentException (); 168 } 169 props.put(name, value); 170 } 171 172 176 public String getSubject() { 177 return escapeHTMLTags(message.getSubject()); 178 } 179 180 184 public String getBody() { 185 return escapeHTMLTags(message.getBody()); 186 } 187 188 197 private String escapeHTMLTags(String input) { 198 if (input == null || input.length() == 0) { 201 return input; 202 } 203 StringBuffer buf = new StringBuffer (input.length() + 6); 206 char ch = ' '; 207 for (int i = 0; i < input.length(); i++) { 208 ch = input.charAt(i); 209 if (ch == '<') { 210 buf.append("<"); 211 } else if (ch == '>') { 212 buf.append(">"); 213 } else { 214 buf.append(ch); 215 } 216 } 217 return buf.toString(); 218 } 219 } 220 | Popular Tags |