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

StringescapeHTML(String aText)
escape HTML
if (aText == null) {
    return null;
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
...
StringescapeHtml(String s)
escape Html
if (s == null) {
    return null;
StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    String nc = ESCAPES.get(c);
    if (nc != null) {
...
StringescapeHTML(String s)
escape HTML
for (Character c : HTML_ENTITIES.keySet()) {
    if (s.indexOf(c) >= 0) {
        s = s.replace(c.toString(), HTML_ENTITIES.get(c));
return s;
StringescapeHTML(String s)
escape HTML
if (s == null)
    return "";
StringBuffer sb = new StringBuffer(s.length() + 100);
Map<Character, String> unent = getHtmlUnEntities();
for (int ii = 0, ll = s.length(); ii < ll; ii++) {
    char ch = s.charAt(ii);
    String ent = unent.get(ch);
    if (ent != null) {
...
StringescapeHtml(String s)
escape Html
final StringBuilder out = new StringBuilder(Math.max(16, s.length()));
for (int i = 0; i < s.length(); i++) {
    final char c = s.charAt(i);
    if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
        out.append("&#");
        out.append((int) c);
        out.append(';');
    } else {
...
StringescapeHTML(String text)
escape HTML
StringBuilder escaped = new StringBuilder();
int n = text.length();
for (int i = 0; i < n; i++) {
    char c = text.charAt(i);
    escaped.append(HTML2ESCAPE_MAP.containsKey(c) ? HTML2ESCAPE_MAP.get(c) : c);
return escaped.toString();
StringescapeHTML(String text)
escape HTML
StringBuilder escaped = new StringBuilder();
StringCharacterIterator iterator = new StringCharacterIterator(text);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        escaped.append("&lt;");
    } else if (character == '>') {
        escaped.append("&gt;");
...
StringescapeHTMLLine(String line)
escape HTML Line
if (escapeList == null) {
    init();
String key;
for (Iterator var2 = escapeList.keySet().iterator(); var2
        .hasNext(); line = line.replace(key, (String) escapeList.get(key))) {
    key = (String) var2.next();
return line;
StringescapeHTMLSpecialChars(String aText)
Escape characters for text appearing in HTML markup.
StringBuilder result = new StringBuilder();
StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
    } else if (character == '>') {
        result.append("&gt;");
...
StringescapeHTMLTagCopy(String text)
Replace characters having special meaning inside HTML tags with their escaped equivalents, using character entities such as '&'.
final StringBuffer result = new StringBuffer();
final StringCharacterIterator iterator = new StringCharacterIterator(text);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
    } else if (character == '>') {
        result.append("&gt;");
...