FileDocCategorySizeDatePackage
HTMLFilter.javaAPI DocGlassfish v2 API3348Fri May 04 22:34:14 BST 2007util

HTMLFilter

public final class HTMLFilter extends Object
HTML filter utility.
author
Craig R. McClanahan
author
Tim Tye
version
$Revision: 1.3 $ $Date: 2007/05/05 05:34:14 $

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.Stringfilter(java.lang.String message)
Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.

param
message The message string to be filtered


        if (message == null)
            return (null);

        char content[] = new char[message.length()];
        message.getChars(0, message.length(), content, 0);
        StringBuffer result = new StringBuffer(content.length + 50);
        for (int i = 0; i < content.length; i++) {
            switch (content[i]) {
            case '<":
                result.append("<");
                break;
            case '>":
                result.append(">");
                break;
            case '&":
                result.append("&");
                break;
            case '"":
                result.append(""");
                break;
            default:
                result.append(content[i]);
            }
        }
        return (result.toString());