Java tutorial
//package com.java2s; public class Main { public static String formatHtml2Fop(String str) { String originPairTags[] = new String[] { "U", "SUB", "SUP" }; String destinPairStartTags[] = new String[] { "<fo:inline text-decoration=\"underline\">", "<fo:inline text-decoration=\"sub\">", "<fo:inline text-decoration=\"super\" font-size=\"75%\">" }; String destinPairEndTags[] = new String[] { "</fo:inline>", "</fo:inline>", "</fo:inline>" }; String originSingleTags[] = new String[] { "BR", "P" }; String destinSingleTags[] = new String[] { "<fo:block/>", "<fo:block/>" }; for (int i = 0; i < originPairTags.length; i++) { str = pairTagFormat(str, originPairTags[i], destinPairStartTags[i], destinPairEndTags[i]); } for (int i = 0; i < originSingleTags.length; i++) { str = singleTagFormat(str, originSingleTags[i], destinSingleTags[i]); } str = str.replaceAll(" ", " "); str = str.replaceAll("&nbsp;", " "); System.out.println("----------" + str); return str; } private static String pairTagFormat(String originStr, String originTag, String destinStartTag, String destinEndTag) { originTag = originTag.toUpperCase(); String originLowTag = originTag.toLowerCase(); String reg = "((<)|<)\\s*((" + originTag + ")|(" + originLowTag + "))\\s*(>|(>))"; String temp = originStr.replaceAll(reg, destinStartTag); reg = "((<)|<)\\s*(\\/)\\s*((" + originTag + ")|(" + originLowTag + "))\\s*(>|(>))"; temp = temp.replaceAll(reg, destinEndTag); return temp; } private static String singleTagFormat(String originStr, String originTag, String destinTag) { originTag = originTag.toUpperCase(); String originLowTag = originTag.toLowerCase(); String reg = "((<)|<)\\s*(\\/)?\\s*((" + originTag + ")|(" + originLowTag + "))\\s*((\\\\)|(\\/))?\\s*(>|(>))"; String temp = originStr.replaceAll(reg, destinTag); return temp; } }