Java Utililty Methods HTML Encode

List of utility methods to do HTML Encode

Description

The list of methods to do HTML Encode are organized into topic(s).

Method

StringtextToHtml(String text)
text To Html
if (text == null) {
    return "";
text = text.replaceAll("&", "&");
text = text.replaceAll(">", ">");
text = text.replaceAll("<", "&lt;");
text = text.replaceAll("\"", "&quot;");
text = text.replaceAll("\\n", "<br/>");
...
StringtextToHTML(String text)
text To HTML
if (text == null) {
    return "";
text = text.replace("\"", "&quot;").replace("\n", "<br>");
return text;
StringtextToHTML(String text)
Converts a text string to HTML or XML entities.
return textToHTML(text, false);
StringtoHtml(String message)
Surrounds with html tags.
if (message != null) {
    return HTML_START + message + HTML_END;
return null;
StringtoHTML(String msg)

Turns the specified message into HTML code, for use with JLabels, tooltips and such, to achieve multiline text.

msg = msg.replaceAll("<", "&lt;");
msg = msg.replaceAll(">", "&gt;");
msg = msg.replaceAll("\n", "<br/>");
return "<html>" + msg + "</html>";
StringtoHTML(String org, boolean inputValue)
to HTML
StringBuffer result = new StringBuffer(org.length());
char[] chars = org.toCharArray();
for (int i = 0; i < chars.length; i++) {
    if (chars[i] == '\"')
        result.append("&quot;");
    else if (chars[i] == '<')
        result.append("&lt;");
    else if (chars[i] == '>')
...
StringtoHtml(String p_str)
to Html
if (p_str == null || p_str.length() == 0)
    return "";
p_str = p_str.replaceAll("<", "&lt;");
p_str = p_str.replaceAll(">", "&gt;");
p_str = p_str.replaceAll("&", "&amp;");
p_str = p_str.replaceAll("\"", "&quot;");
return p_str;
StringtoHTML(String plainText)
to HTML
plainText = plainText.replace(System.getProperty("line.separator"), "<br>");
return "<html><head></head><body>" + plainText + "</body></html>";
StringtoHTML(String rawText)
Turns a string into HTML displayable text by escaping special characters ('<','&' etc...).
String test;
if (rawText.length() > 14)
    test = rawText.substring(0, 14).toLowerCase();
else
    test = rawText.toLowerCase();
if (test.startsWith("<html>") || test.startsWith("<!doctype html>")) {
    if (test.startsWith("<html>"))
        rawText = rawText.substring(6);
...
StringtoHTML(String s)
Converts the given String into HTML, i.e., replacing some char entities with HTML entities.
String result;
if (s == null)
    return "";
result = s;
result = result.replaceAll("&", "&amp;");
result = result.replaceAll("<", "&lt;");
result = result.replaceAll(">", "&gt;");
result = result.replaceAll("@", "&#64;");
...