import java.util.*; //import Html; //import MixedText; /** * This type represents a Answer from an faq style chunk of * text. The contents of the answer may contain links. * * @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 MixedText contents; //-------------------------------------------- public static String TERMINATOR = ""; //-------------------------------------------- public static String INDICATOR = "a:"; //-------------------------------------------- private boolean isGood; //-------------------------------------------- //-------------------------------------------- public Answer() { this.contents = new MixedText(); } //-------------------------------------------- /** 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 = new MixedText( sText.trim().substring(Answer.INDICATOR.length())); } else { this.contents = new MixedText(sText); } } //-------------------------------------------- public MixedText getContents() { return this.contents; } //-------------------------------------------- public void setContents(String sContents) { this.contents = new MixedText(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.toString()); 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.toString()); sbReturn.append(NEWLINE); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("