1 25 26 package util; 27 28 35 36 public final class HTMLFilter { 37 38 39 46 public static String filter(String message) { 47 48 if (message == null) 49 return (null); 50 51 char content[] = new char[message.length()]; 52 message.getChars(0, message.length(), content, 0); 53 StringBuffer result = new StringBuffer (content.length + 50); 54 for (int i = 0; i < content.length; i++) { 55 switch (content[i]) { 56 case '<': 57 result.append("<"); 58 break; 59 case '>': 60 result.append(">"); 61 break; 62 case '&': 63 result.append("&"); 64 break; 65 case '"': 66 result.append("""); 67 break; 68 default: 69 result.append(content[i]); 70 } 71 } 72 return (result.toString()); 73 74 } 75 76 77 } 78 79 | Popular Tags |