Here you can find the source of htmlEscape(String source)
E.g.
public static String htmlEscape(String source)
//package com.java2s; //License from project: Apache License import java.util.Map; import java.util.HashMap; public class Main { private static Map i2e = new HashMap(); /**//from w ww . ja va 2 s .c om * Turns funky characters into HTML entity equivalents.<p> * E.g. <tt>"bread" & "butter"</tt> => <tt>&quot;bread&quot; &amp; &quot;butter&quot;</tt> * <p>Update: supports nearly all HTML entities, including funky accents. See the source code for more detail. **/ public static String htmlEscape(String source) { StringBuffer buf = new StringBuffer(); if (source != null) { for (int i = 0; i < source.length(); ++i) { char ch = source.charAt(i); String entity = (String) i2e.get(new Integer((int) ch)); if (entity == null) { if (((int) ch) > 128) buf.append("&#" + ((int) ch) + ";"); else buf.append(ch); } else { buf.append("&" + entity + ";"); } } } return buf.toString(); } }