import java.util.*; /** * This type represents a Answer from an faq style chunk of * text. The question and answer form an item. * * @author http://bumble.sf.net * @See Answer, FAQ, etc */ public class Answer extends Object { //-------------------------------------------- private static String NEWLINE = System.getProperty("line.separator"); //-------------------------------------------- /** the text of the Answer */ private String contents; //-------------------------------------------- public static String TERMINATOR = ""; //-------------------------------------------- public static String INDICATOR = "a:"; //-------------------------------------------- private boolean isGood; //-------------------------------------------- //-------------------------------------------- public Answer() { this.contents = ""; } //-------------------------------------------- /** construct with some text */ public Answer(String sText) { this(); this.loadData(sText); } //-------------------------------------------- /** load data from text */ public void loadData(String sText) { this.isGood = this.isAnswer(sText); if (!this.isGood) { return; } if (sText.trim().startsWith(Answer.INDICATOR)) { this.contents = sText.trim().substring(Answer.INDICATOR.length()); } else { this.contents = sText; } } //-------------------------------------------- public String getContents() { return this.contents; } //-------------------------------------------- public void setContents(String sContents) { this.contents = sContents; } //-------------------------------------------- /** checks if this looks like a Answer, but an answer * will be whatever is left over */ public static boolean isAnswer(String sText) { /* if (sText.trim().length() == 0) { return false; } if (!sText.trim().startsWith(Answer.INDICATOR)) { return false; } if (!sText.trim().endsWith(Answer.TERMINATOR)) { return false; } */ return true; } //-------------------------------------------- public String toString() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(Answer.INDICATOR); sbReturn.append(this.contents); sbReturn.append(Answer.TERMINATOR); return sbReturn.toString(); } //-------------------------------------------- public String printReport() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("Answer Indicator :"); sbReturn.append(Answer.INDICATOR); sbReturn.append(NEWLINE); sbReturn.append("Answer Terminator:"); sbReturn.append(Answer.TERMINATOR); sbReturn.append(NEWLINE); sbReturn.append("Answer contents:"); sbReturn.append(this.contents); sbReturn.append(NEWLINE); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("