Here you can find the source of htmEncode(String input)
public static String htmEncode(String input)
//package com.java2s; public class Main { private static final int VALUE_10 = 10; private static final int VALUE_13 = 13; private static final int VALUE_32 = 32; private static final int VALUE_60 = 60; private static final int VALUE_62 = 62; private static final int VALUE_38 = 38; private static final int VALUE_34 = 34; private static final int VALUE_165 = 165; private static final int VALUE_174 = 174; private static final int VALUE_8482 = 8482; private static final int VALUE_8364 = 8364; private static final int VALUE_169 = 169; public static String htmEncode(String input) { if (null == input || "".equals(input)) { return input; }//from w w w .j a v a 2s . c o m StringBuffer stringbuffer = new StringBuffer(); int j = input.length(); for (int i = 0; i < j; i++) { char c = input.charAt(i); switch (c) { case VALUE_60: stringbuffer.append("<"); break; case VALUE_62: stringbuffer.append(">"); break; case VALUE_38: stringbuffer.append("&"); break; case VALUE_34: stringbuffer.append("""); break; case VALUE_169: stringbuffer.append("©"); break; case VALUE_174: stringbuffer.append("®"); break; case VALUE_165: stringbuffer.append("¥"); break; case VALUE_8364: stringbuffer.append("€"); break; case VALUE_8482: stringbuffer.append("™"); break; case VALUE_13: if (i < j - 1 && input.charAt(i + 1) == VALUE_10) { stringbuffer.append("<br>"); i++; } break; case VALUE_32: if (i < j - 1 && input.charAt(i + 1) == ' ') { stringbuffer.append(" "); i++; break; } default: stringbuffer.append(c); break; } } return new String(stringbuffer.toString()); } }