css check
public final class CssCheck{
//hex values for 'dangerous' chars
public static final String kLESS_THEN = "3C";
public static final String kGT_THEN = "3E";
public static final String kLEFT_PREN = "28";
public static final String kRIGHT_PREN = "29";
public static final String kPOUND = "23";
public static final String kAMPERSAND = "26";
public static final String kPERCENT = "25";
public static final String kFOWARD_SLASH = "2F";
public static String filter(String ascii) {
if (ascii==null)
return (null);
StringBuffer result = new StringBuffer(ascii.length());
for (int i = 0; i < ascii.length(); i++) {
boolean ok = true;
if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kLESS_THEN))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kGT_THEN))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kLEFT_PREN))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kRIGHT_PREN))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kPOUND))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kAMPERSAND))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kPERCENT))
ok=false;
else if(Integer.toHexString(ascii.charAt(i)).equalsIgnoreCase(kFOWARD_SLASH))
ok=false;
if(ok)
result.append(ascii.charAt(i));
}
return (result.toString().trim());
}
}
Here is the above java class.
CssCheck.java
MAIN