Here you can find the source of translate(String originalHtml)
public static String translate(String originalHtml)
//package com.java2s; /*/*from w w w.ja va2 s. c om*/ * Copyright (c) 2006 Rick Mugridge, www.RimuResearch.com * Released under the terms of the GNU General Public License version 2 or later. */ public class Main { public static String translate(String originalHtml) { String html = originalHtml; while (true) { int end; int start = html.indexOf("<br/>* "); int offset = 7; if (start < 0) { start = html.indexOf("\n* "); offset = 3; end = html.indexOf("\n", start + offset); } else end = html.indexOf("<br/>", start + offset); if (start < 0) break; int tagEnd; if (end < 0) { end = html.length(); tagEnd = end; } else tagEnd = end + offset - 2; String line = findRows(html.substring(start + offset, end)); String table = "\n<table><tr>" + line + "</tr></table>\n"; html = html.substring(0, start) + table + html.substring(tagEnd); } return html; } private static String findRows(String originalLine) { String line = originalLine; String table = ""; while (true) { if ("".equals(line)) break; int endCell = end(line); table += "<td>" + line.substring(0, endCell).trim() + "</td>"; line = line.substring(endCell); if (line.startsWith(" ")) line = line.substring(1); } return table; } private static int end(String line) { if (line.startsWith("<i>")) return end(line, "</i>"); if (line.startsWith("<b>")) return end(line, "</b>"); return Math.min(start(line, "<i>"), start(line, "<b>")); } private static int end(String line, String endTag) { int end = line.indexOf(endTag); if (end < 0) end = line.length(); else end += 4; return end; } private static int start(String line, String tag) { int it = line.indexOf(tag); if (it < 0) return line.length(); return it; } }