1 53 54 106 107 package com.Yasna.forum.filter; 108 109 import java.util.*; 110 import java.io.*; 111 112 import com.Yasna.forum.*; 113 import com.Yasna.codeviewer.*; 114 115 119 public class FilterHtml extends ForumMessageFilter implements Serializable { 120 121 124 private Properties props; 125 126 129 private Properties propDescriptions; 130 131 136 public FilterHtml() { 137 super(); 138 props = new Properties(); 139 propDescriptions = new Properties(); 140 } 141 142 150 public FilterHtml(ForumMessage message, Properties props, 151 Properties propDescriptions) 152 { 153 super(message); 154 this.props = new Properties(props); 155 this.propDescriptions = new Properties(propDescriptions); 156 } 157 158 164 public ForumMessageFilter clone(ForumMessage message){ 165 return new FilterHtml(message,props,propDescriptions); 166 } 167 168 171 public String getName() { 172 return "HTML Filter"; 173 } 174 175 178 public String getDescription() { 179 return "Escapes HTML tags by converting < and > characters " + 180 "into HTML esacpe sequences."; 181 } 182 183 186 public String getAuthor() { 187 return "CoolServlets.com"; 188 } 189 190 193 public int getMajorVersion() { 194 return 1; 195 } 196 197 200 public int getMinorVersion() { 201 return 0; 202 } 203 204 210 public String getFilterProperty(String name) { 211 return props.getProperty(name); 212 } 213 214 220 public String getFilterPropertyDescription(String name) { 221 return propDescriptions.getProperty(name); 222 } 223 224 227 public Enumeration filterPropertyNames() { 228 return null; 230 } 231 232 242 public void setFilterProperty(String name, String value) 243 throws IllegalArgumentException 244 { 245 if (props.getProperty(name) == null) { 246 throw new IllegalArgumentException (); 247 } 248 props.put(name, value); 249 } 250 251 255 public String getSubject() { 256 return escapeHTMLTags(message.getSubject()); 257 } 258 259 263 public String getBody() { 264 return escapeHTMLTags(message.getBody()); 265 } 266 267 276 private String escapeHTMLTags( String input ) { 277 if( input == null || input.length() == 0 ) { 280 return input; 281 } 282 StringBuffer buf = new StringBuffer (input.length()+6); 285 char ch = ' '; 286 for( int i=0; i<input.length(); i++ ) { 287 ch = input.charAt(i); 288 if( ch == '<' ) { 289 buf.append( "<" ); 290 } 291 else if( ch == '>' ) { 292 buf.append( ">" ); 293 } 294 else { 295 buf.append( ch ); 296 } 297 } 298 return buf.toString(); 299 } 300 } 301 | Popular Tags |