Java HTML Encode toHtmlChars(String htmlReady)

Here you can find the source of toHtmlChars(String htmlReady)

Description

Description of the Method

License

Open Source License

Parameter

Parameter Description
htmlReady Description of the Parameter

Return

Description of the Return Value

Declaration

public static String toHtmlChars(String htmlReady) 

Method Source Code

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

public class Main {
    /**/*from  www  . ja  v a2s .co m*/
     * Description of the Method
     *
     * @param htmlReady Description of the Parameter
     * @return Description of the Return Value
     */
    public static String toHtmlChars(String htmlReady) {
        if (htmlReady != null) {
            htmlReady = replace(htmlReady, "\u00A1", "¡");
            htmlReady = replace(htmlReady, "\u00A2", "¢");
            htmlReady = replace(htmlReady, "\u00A3", "£");
            htmlReady = replace(htmlReady, "\u00A4", "¤");
            htmlReady = replace(htmlReady, "\u00A5", "¥");
            htmlReady = replace(htmlReady, "\u00A6", "¦");
            htmlReady = replace(htmlReady, "\u00A7", "§");
            htmlReady = replace(htmlReady, "\u00A8", "¨");
            htmlReady = replace(htmlReady, "\u00A9", "©");
            htmlReady = replace(htmlReady, "\u00AA", "ª");
            htmlReady = replace(htmlReady, "\u00AB", "«");
            htmlReady = replace(htmlReady, "\u00AC", "¬");
            htmlReady = replace(htmlReady, "\u00AD", "­");
            htmlReady = replace(htmlReady, "\u00AE", "®");
            htmlReady = replace(htmlReady, "\u00AF", "¯");
            htmlReady = replace(htmlReady, "\u00B0", "°");
            htmlReady = replace(htmlReady, "\u00B1", "±");
            htmlReady = replace(htmlReady, "\u00B2", "²");
            htmlReady = replace(htmlReady, "\u00B3", "³");
            htmlReady = replace(htmlReady, "\u00B4", "´");
            htmlReady = replace(htmlReady, "\u00B5", "µ");
            htmlReady = replace(htmlReady, "\u00B6", "¶");
            htmlReady = replace(htmlReady, "\u00B7", "·");
            htmlReady = replace(htmlReady, "\u00B8", "¸");
            htmlReady = replace(htmlReady, "\u00B9", "¹");
            htmlReady = replace(htmlReady, "\u00BA", "º");
            htmlReady = replace(htmlReady, "\u00BB", "»");
            htmlReady = replace(htmlReady, "\u00BC", "¼");
            htmlReady = replace(htmlReady, "\u00BD", "½");
            htmlReady = replace(htmlReady, "\u00BE", "¾");
            htmlReady = replace(htmlReady, "\u00BF", "¿");
            htmlReady = replace(htmlReady, "\u00C0", "À");
            htmlReady = replace(htmlReady, "\u00C1", "Á");
            htmlReady = replace(htmlReady, "\u00C2", "Â");
            htmlReady = replace(htmlReady, "\u00C3", "Ã");
            htmlReady = replace(htmlReady, "\u00C4", "Ä");
            htmlReady = replace(htmlReady, "\u00C5", "Å");
            htmlReady = replace(htmlReady, "\u00C6", "Æ");
            htmlReady = replace(htmlReady, "\u00C7", "Ç");
            htmlReady = replace(htmlReady, "\u00C8", "È");
            htmlReady = replace(htmlReady, "\u00C9", "É");
            htmlReady = replace(htmlReady, "\u00CA", "Ê");
            htmlReady = replace(htmlReady, "\u00CB", "Ë");
            htmlReady = replace(htmlReady, "\u00CC", "Ì");
            htmlReady = replace(htmlReady, "\u00CD", "Í");
            htmlReady = replace(htmlReady, "\u00CE", "Î");
            htmlReady = replace(htmlReady, "\u00CF", "Ï");
            htmlReady = replace(htmlReady, "\u00D0", "Ð");
            htmlReady = replace(htmlReady, "\u00D1", "Ñ");
            htmlReady = replace(htmlReady, "\u00D2", "Ò");
            htmlReady = replace(htmlReady, "\u00D3", "Ó");
            htmlReady = replace(htmlReady, "\u00D4", "Ô");
            htmlReady = replace(htmlReady, "\u00D5", "Õ");
            htmlReady = replace(htmlReady, "\u00D6", "Ö");
            htmlReady = replace(htmlReady, "\u00D7", "×");
            htmlReady = replace(htmlReady, "\u00D8", "Ø");
            htmlReady = replace(htmlReady, "\u00D9", "Ù");
            htmlReady = replace(htmlReady, "\u00DA", "Ú");
            htmlReady = replace(htmlReady, "\u00DB", "Û");
            htmlReady = replace(htmlReady, "\u00DC", "Ü");
            htmlReady = replace(htmlReady, "\u00DD", "Ý");
            htmlReady = replace(htmlReady, "\u00DE", "Þ");
            htmlReady = replace(htmlReady, "\u00DF", "ß");
            htmlReady = replace(htmlReady, "\u00E0", "à");
            htmlReady = replace(htmlReady, "\u00E1", "á");
            htmlReady = replace(htmlReady, "\u00E2", "â");
            htmlReady = replace(htmlReady, "\u00E3", "ã");
            htmlReady = replace(htmlReady, "\u00E4", "ä");
            htmlReady = replace(htmlReady, "\u00E5", "å");
            htmlReady = replace(htmlReady, "\u00E6", "æ");
            htmlReady = replace(htmlReady, "\u00E7", "ç");
            htmlReady = replace(htmlReady, "\u00E8", "è");
            htmlReady = replace(htmlReady, "\u00E9", "é");
            htmlReady = replace(htmlReady, "\u00EA", "ê");
            htmlReady = replace(htmlReady, "\u00EB", "ë");
            htmlReady = replace(htmlReady, "\u00EC", "ì");
            htmlReady = replace(htmlReady, "\u00ED", "í");
            htmlReady = replace(htmlReady, "\u00EE", "î");
            htmlReady = replace(htmlReady, "\u00EF", "ï");
            htmlReady = replace(htmlReady, "\u00F0", "ð");
            htmlReady = replace(htmlReady, "\u00F1", "ñ");
            htmlReady = replace(htmlReady, "\u00F2", "ò");
            htmlReady = replace(htmlReady, "\u00F3", "ó");
            htmlReady = replace(htmlReady, "\u00F4", "ô");
            htmlReady = replace(htmlReady, "\u00F5", "õ");
            htmlReady = replace(htmlReady, "\u00F6", "ö");
            htmlReady = replace(htmlReady, "\u00F7", "÷");
            htmlReady = replace(htmlReady, "\u00F8", "ø");
            htmlReady = replace(htmlReady, "\u00F9", "ù");
            htmlReady = replace(htmlReady, "\u00FA", "ú");
            htmlReady = replace(htmlReady, "\u00FB", "û");
            htmlReady = replace(htmlReady, "\u00FC", "ü");
            htmlReady = replace(htmlReady, "\u00FD", "ý");
            htmlReady = replace(htmlReady, "\u00FE", "þ");
            htmlReady = replace(htmlReady, "\u00FF", "ÿ");
            htmlReady = replace(htmlReady, "\u20AC", "€");
            return (htmlReady);
        } else {
            return ("");
        }
    }

    /**
     * Description of the Method
     *
     * @param str Description of Parameter
     * @param o   Description of Parameter
     * @param n   Description of Parameter
     * @return Description of the Returned Value
     */
    public static String replace(String str, String o, String n) {
        boolean all = true;
        if (str != null && o != null && o.length() > 0 && n != null) {
            StringBuffer result = null;
            int oldpos = 0;
            do {
                int pos = str.indexOf(o, oldpos);
                if (pos < 0) {
                    break;
                }
                if (result == null) {
                    result = new StringBuffer();
                }
                result.append(str.substring(oldpos, pos));
                result.append(n);
                pos += o.length();
                oldpos = pos;
            } while (all);
            if (oldpos == 0) {
                return str;
            } else {
                result.append(str.substring(oldpos));
                return result.toString();
            }
        } else {
            return str;
        }
    }

    /**
     * Description of the Method
     *
     * @param s Description of Parameter
     * @return Description of the Returned Value
     */
    public static String toString(String s) {
        if (s != null) {
            return (s);
        } else {
            return ("");
        }
    }
}

Related

  1. toHtml(String text)
  2. toHtml(String trace)
  3. toHtml(String txt)
  4. toHtml(String value, String defaultValue)
  5. toHTML(String xhtml)
  6. toHTMLContentString(String s, boolean replaceSpaces, boolean isXhtml)
  7. toHtmlCR(String text)
  8. toHTMLEncode(String string)
  9. toHTMLEscapedText(String s)