Java Utililty Methods HTML Escape

List of utility methods to do HTML Escape

Description

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

Method

StringhtmlescapeAll(String s1)
Turns all characters into HTML entity equivalents
if (s1 == null)
    return null;
StringBuffer buf = new StringBuffer();
int i;
for (i = 0; i < s1.length(); ++i) {
    char ch = s1.charAt(i);
    buf.append("&#" + ((int) ch) + ";");
return buf.toString();
StringhtmlEscapeBasicMarkup(final String text)
Performs necessary escaping to render arbitrary plain text as plain text without any markup.
final StringBuilder buf = new StringBuilder(text.length() + 64);
for (int i = 0; i < text.length(); i++) {
    final char ch = text.charAt(i);
    switch (ch) {
    case '<':
        buf.append("&lt;");
        break;
    case '&':
...
StringHTMLEscapeBr(String original)
HTML Escape Br
if (original == null)
    return "";
StringBuffer out = new StringBuffer("");
char[] chars = original.toCharArray();
for (int i = 0; i < chars.length; i++) {
    boolean found = true;
    switch (chars[i]) {
    case '\n':
...
StringBufferhtmlEscapeSpace(String uri)
html Escape Space
StringBuffer sbURI = new StringBuffer((int) (uri.length() * 1.5));
char ch;
for (int i = 0; i < uri.length(); ++i) {
    ch = uri.charAt(i);
    if (ch == ' ') {
        sbURI.append("%20");
    } else if (ch == '\\') {
        sbURI.append('/');
...
StringhtmlUnescape(String safeHtml)
html Unescape
if (safeHtml == null)
    return null;
if (safeHtml.indexOf("&lt;") != -1) {
    safeHtml = safeHtml.replace("&lt;", "<");
if (safeHtml.indexOf("&gt;") != -1) {
    safeHtml = safeHtml.replace("&gt;", ">");
if (safeHtml.indexOf("&quot;") != -1) {
    safeHtml = safeHtml.replace("&quot;", "\"");
if (safeHtml.indexOf("&#39;") != -1) {
    safeHtml = safeHtml.replace("&#39;", "'");
if (safeHtml.indexOf("&amp;") != -1) {
    safeHtml = safeHtml.replace("&amp;", "&");
return safeHtml;