Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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("&nbsp;", " ");
        str = str.replaceAll("&amp;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 = "((&lt;)|<)\\s*((" + originTag + ")|(" + originLowTag + "))\\s*(>|(&gt;))";
        String temp = originStr.replaceAll(reg, destinStartTag);
        reg = "((&lt;)|<)\\s*(\\/)\\s*((" + originTag + ")|(" + originLowTag + "))\\s*(>|(&gt;))";
        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 = "((&lt;)|<)\\s*(\\/)?\\s*((" + originTag + ")|(" + originLowTag
                + "))\\s*((\\\\)|(\\/))?\\s*(>|(&gt;))";
        String temp = originStr.replaceAll(reg, destinTag);
        return temp;
    }
}