Java HTML HTMLFilter(String the_txt)

Here you can find the source of HTMLFilter(String the_txt)

Description

Cleans up entered text to make it XML compatible and to prevent SQL injection tricks.

License

Open Source License

Parameter

Parameter Description
the_txt The raw text as entered into a GET or POST command.

Return

The cleaned text.

Declaration

public static String HTMLFilter(String the_txt) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w w  .  ja v a2 s .  c  o m*/
    * Cleans up entered text to make it XML compatible and to prevent SQL injection tricks.
    * @param the_txt The raw text as entered into a GET or POST command.
    * @return The cleaned text.
    */
    public static String HTMLFilter(String the_txt) {
        if (the_txt == null) {
            return null;
        }

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

Related

  1. htmlContentHeaderGen(String providerNo, String output, String errorMsg)
  2. htmlConvert(String htmlStr)
  3. HTMLEnc(String s)
  4. htmlEnclose(String html)
  5. htmlFilenameForClass(Class c)
  6. htmlFilter(String value)
  7. htmlFilterToEmpty(String value)
  8. htmlFooter()
  9. htmlFormat(String input)