Java HTML Filter filterHTML(String input)

Here you can find the source of filterHTML(String input)

Description

filter HTML

License

Open Source License

Declaration

public static String filterHTML(String input) 

Method Source Code

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

public class Main {
    public static String filterHTML(String input) {
        StringBuffer filtered = new StringBuffer(input.length());
        char c;// w  w  w. j  a  va  2s  .c  o  m

        for (int i = 0; i < input.length(); i++) {

            c = input.charAt(i);

            if (c == '<') {
                filtered.append("&lt;");
            } else if (c == '>') {
                filtered.append("&gt;");
            } else if (c == '=') {
                filtered.append("&#61;");
            } else if (c == '&') {
                filtered.append("&amp;");
            } else {
                filtered.append(c);
            }
        }
        return filterForSQL(filtered.toString());
    }

    public static String filterForSQL(String input) {
        StringBuffer filtered = new StringBuffer(input.length());
        char c;

        for (int i = 0; i < input.length(); i++) {

            c = input.charAt(i);

            if (c == '\'') {
                filtered.append("\'\'");
            } else if (c == '\\') {
                filtered.append("\\\\");
            } else {
                filtered.append(c);
            }
        }
        return filtered.toString();
    }
}

Related

  1. filterHtml(String body)
  2. filterHTML(String input)
  3. filterHtml(String input)
  4. filterHtml(String s)
  5. filterHTML(String s)
  6. filterHtmlAndTruncate(String s)