Here you can find the source of toHtmlText(String text)
public static String toHtmlText(String text)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHtmlText(String text) { StringBuffer htmlText = null; for (int i = 0; i < text.length(); i++) { String rep; // replacement string char ch = text.charAt(i); switch (ch) { case '<': rep = "<"; // NOI18N break; case '>': rep = ">"; // NOI18N break; case '\n': rep = "<br>"; // NOI18N break; default: rep = null;/*from w w w .j a v a 2 s . c o m*/ break; } if (rep != null) { if (htmlText == null) { // Expect 20% of text to be html tags text htmlText = new StringBuffer(120 * text.length() / 100); if (i > 0) { htmlText.append(text.substring(0, i)); } } htmlText.append(rep); } else { // no replacement if (htmlText != null) { htmlText.append(ch); } } } return (htmlText != null) ? htmlText.toString() : text; } }