Here you can find the source of toHtmlValue(String s)
Parameter | Description |
---|---|
s | Description of Parameter |
public static String toHtmlValue(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. ja v a 2s.co m*/ * Description of the Method * * @param s Description of Parameter * @return Description of the Returned Value */ public static String toHtmlValue(String s) { if (s != null) { String htmlReady = s.trim(); htmlReady = replace(htmlReady, "&", "&"); htmlReady = replace(htmlReady, "\"", """); htmlReady = replace(htmlReady, "<", "<"); htmlReady = replace(htmlReady, ">", ">"); htmlReady = replace(htmlReady, "\r\n", "<br>"); htmlReady = replace(htmlReady, "\n\r", "<br>"); htmlReady = replace(htmlReady, "\n", "<br>"); htmlReady = replace(htmlReady, "\r", "<br>"); htmlReady = replace(htmlReady, "//lt;", "<"); htmlReady = replace(htmlReady, "//gt;", ">"); //a second call to the function (done in surveys) //changes <br> to <br>, this needs to be reverted htmlReady = replace(htmlReady, "<br>", "<br>"); htmlReady = toHtmlChars(htmlReady); 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 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 s Description of Parameter * @return Description of the Returned Value */ public static String toString(String s) { if (s != null) { return (s); } else { return (""); } } }