首先先介绍一下HTML的文本解析代码: package project.util;/** *//** * This class is used for parsing the string that contains * HTML elements, especially hyperlinks.
* It contains a developer-defined syntax to allow the user * to make a customized hyperlink. * * @author Zenny Chen * */public class HTMLParser ...{ // HTML elements for output private static final String begin_enter = "
"; private static final String end_enter = "
"; private static final String begin_hyperlink = ""; private static final String end_hyperlink = ""; // some interpunctions private static final char char_enter = ' '; private static final char quotation_mark = '"'; // hyperlink types to parse private static final String notes_link = "notes://"; private static final String http_link = "http://"; // customized format private static final String link_ref = "@link="; private static final String link_name = "@name="; private int cursor = 0; private int content_length = 0; private char[] src = null; private char[] dest = null; private final int mark_length = 5; /** *//** * [0] stores href value initial position
* [1] stores href value eventual position
* [2] stores link name initial position
* [3] stores link name eventual position
* [4] stores next continuing position */ private int[] position_marks = new int[mark_length]; public HTMLParser() ...{ } /** *//** * It is the only method that user will use in this class. * @param ref the raw string that user inputs * @return a hyperlink formatted string */ public String getHTMLFormString(String ref) ...{ src = ref.toCharArray(); content_length = ref.length(); final int length = (content_length << 2) + 128; dest = new char[length]; boolean has_enter_mark = false; for(int i=0; i * The form is: "{@link=xxx @name=xxx}" * @param initpos * @return a boolean value */ private boolean isConfiguredHyperlink(int initpos) ...{ int i = initpos; boolean phase_ok = false; // phase 1 if(src[i++] == '{') ...{ // phase 2 int len = content_length - i; for(int j=0; j