Here you can find the source of htmlEncode(String strSrc)
public static String htmlEncode(String strSrc)
//package com.java2s; //License from project: Open Source License public class Main { public static String htmlEncode(String strSrc) { if (strSrc == null) { return ""; }//from www . ja v a2 s. c o m char[] arrCsrc = strSrc.toCharArray(); StringBuilder buf = new StringBuilder(arrCsrc.length); char ch; for (char anArrCSrc : arrCsrc) { ch = anArrCSrc; if (ch == '<') { buf.append("<"); } else if (ch == '>') { buf.append(">"); } else if (ch == '"') { buf.append("""); } else if (ch == '\'') { buf.append("'"); } else if (ch == '&') { buf.append("&"); } else { buf.append(ch); } } return buf.toString(); } public static String htmlEncode(String strSrc, int quotes) { if (strSrc == null) { return ""; } if (quotes == 0) { return htmlEncode(strSrc); } char[] arrCsrc = strSrc.toCharArray(); StringBuilder buf = new StringBuilder(arrCsrc.length); char ch; for (int i = 0; i < arrCsrc.length; i++) { ch = arrCsrc[i]; if (ch == '<') { buf.append("<"); } else if (ch == '>') { buf.append(">"); } else if (ch == '"' && quotes == 1) { buf.append("""); } else if (ch == '\'' && quotes == 2) { buf.append("'"); } else if (ch == '&') { buf.append("&"); } else { buf.append(ch); } } return buf.toString(); } }