1 package com.Yasna.forum.filter; 2 3 import com.Yasna.forum.ForumMessageFilter; 4 import com.Yasna.forum.ForumMessage; 5 6 import java.io.Serializable ; 7 import java.util.Properties ; 8 import java.util.Enumeration ; 9 import java.util.regex.Pattern ; 10 11 63 64 public class FilterJavaScript extends ForumMessageFilter implements Serializable { 65 68 private Properties props; 69 70 73 private Properties propDescriptions; 74 75 80 public FilterJavaScript() { 81 super(); 82 props = new Properties (); 83 propDescriptions = new Properties (); 84 } 85 91 public FilterJavaScript(ForumMessage message, Properties props, 92 Properties propDescriptions) 93 { 94 super(message); 95 this.props = new Properties (props); 96 this.propDescriptions = new Properties (propDescriptions); 97 } 98 99 105 public ForumMessageFilter clone(ForumMessage message){ 106 return new FilterJavaScript(message,props,propDescriptions); 107 } 108 109 112 public String getName() { 113 return "JavaScript Filter"; 114 } 115 116 119 public String getDescription() { 120 return "Escapes Script tags by removing everything between <script.. > and <\\script> tags "; 121 } 122 123 126 public String getAuthor() { 127 return "www.yasna.com"; 128 } 129 130 133 public int getMajorVersion() { 134 return 1; 135 } 136 137 140 public int getMinorVersion() { 141 return 0; 142 } 143 144 149 public String getFilterProperty(String name) { 150 return props.getProperty(name); 151 } 152 153 159 public String getFilterPropertyDescription(String name) { 160 return propDescriptions.getProperty(name); 161 } 162 163 166 public Enumeration filterPropertyNames() { 167 return null; 169 } 170 171 181 public void setFilterProperty(String name, String value) 182 throws IllegalArgumentException 183 { 184 if (props.getProperty(name) == null) { 185 throw new IllegalArgumentException (); 186 } 187 props.put(name, value); 188 } 189 190 194 public String getSubject() { 195 return escapeScriptTags(message.getSubject()); 196 } 197 198 202 public String getBody() { 203 return escapeScriptTags(message.getBody()); 204 } 205 206 213 private String escapeScriptTags( String input ) { 214 if( input == null || input.length() == 0 || input.toLowerCase().indexOf("script")<0 || input.toLowerCase().indexOf("javascript")<0) { 217 return input; 218 } 219 return Pattern.compile("\\<(\\s*)(script)(\\s.*?)?\\>((\\s|.)*?)\\<\\/(\\s*)(script)(\\s.*?)?\\>",Pattern.CASE_INSENSITIVE).matcher(input).replaceAll(""); 220 } 221 222 } 223 | Popular Tags |