Java String Escape escapeHTML(String source)

Here you can find the source of escapeHTML(String source)

Description

Convert a regular string to a string with escaped HTML entities (e.g.

License

Open Source License

Declaration

public static final String escapeHTML(String source) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    private static HashMap<String, String> s_reverseHtmlEntities;

    /**//  ww w  . ja v a 2 s  . co  m
     * Convert a regular string to a string with escaped
     * HTML entities (e.g. < changes to &lt; )
     */
    public static final String escapeHTML(String source) {

        StringBuilder ret = new StringBuilder();
        String val = null;
        int idx = 0;

        for (idx = 0; idx < source.length(); idx++) {
            val = s_reverseHtmlEntities.get(source.substring(idx, idx + 1));
            if (val == null) {
                ret.append(source.charAt(idx));
            } else {
                ret.append(val);
            }
        }

        return ret.toString();
    }
}

Related

  1. escape(String string, String chars)
  2. escapeASN1(String str)
  3. escapeCellText(String text, boolean wrap, boolean multiline)
  4. escapeCharacters(String string)
  5. escapeHTML(String s)
  6. escapeHTMLTags(String in)
  7. escapeInstanceIdentifier(String instanceIdentifier)
  8. escapeJavaString(String str)
  9. escapeJavaStyleString(StringBuilder out, String str, boolean escapeSingleQuote, boolean escapeForwardSlash)