Java HTML Encode htmlEncode(Object input)

Here you can find the source of htmlEncode(Object input)

Description

html Encode

License

Open Source License

Declaration

public static String htmlEncode(Object input) 

Method Source Code

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

public class Main {

    public static String htmlEncode(Object input) {
        if (input == null) {
            return "";
        }//from w w  w.j  a  va2  s.com

        String strInput = input.toString().trim();

        StringBuilder output = new StringBuilder();
        int len = strInput.length();
        char ch;
        for (int i = 0; i < len; i++) {
            ch = strInput.charAt(i);
            if (ch == '&') {
                output.append("&amp;");
                continue;
            }
            if (ch == '<') {
                output.append("&lt;");
                continue;
            }
            if (ch == '>') {
                output.append("&gt;");
                continue;
            }
            if (ch == '"') {
                output.append("&quot;");
            } else {
                output.append(ch);
            }
        }
        return output.toString();
    }
}

Related

  1. html(String text)
  2. html(String text)
  3. html_encode(String input_string)
  4. HTMLBREncode(String str)
  5. htmlEncode(final String source, StringBuffer target)
  6. htmlEncode(String html)
  7. htmlEncode(String html)
  8. htmlEncode(String input)
  9. htmlEncode(String input)