import java.util.*; //import Html; /** * This type represents a Answer from an faq style chunk of * text. The question and answer form an item. This class differs * from the Answer class in that the contents of the plain answer * cannot contain links or other non text elements. The * contents of the plain answer are just normal text. * * @author http://bumble.sf.net * @See Answer, FAQ, etc */ public class PlainAnswer 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 PlainAnswer() { this.contents = ""; } //-------------------------------------------- /** construct with some text */ public PlainAnswer(String sText) { this(); this.loadData(sText); } //-------------------------------------------- /** load data from text */ public void loadData(String sText) { this.isGood = this.isPlainAnswer(sText); if (!this.isGood) { return; } if (sText.trim().startsWith(PlainAnswer.INDICATOR)) { this.contents = sText.trim().substring(PlainAnswer.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 isPlainAnswer(String sText) { /* if (sText.trim().length() == 0) { return false; } if (!sText.trim().startsWith(PlainAnswer.INDICATOR)) { return false; } if (!sText.trim().endsWith(PlainAnswer.TERMINATOR)) { return false; } */ return true; } //-------------------------------------------- public String toString() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(PlainAnswer.INDICATOR); sbReturn.append(this.contents); sbReturn.append(PlainAnswer.TERMINATOR); return sbReturn.toString(); } //-------------------------------------------- public String printReport() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("PlainAnswer Indicator :"); sbReturn.append(PlainAnswer.INDICATOR); sbReturn.append(NEWLINE); sbReturn.append("PlainAnswer Terminator:"); sbReturn.append(PlainAnswer.TERMINATOR); sbReturn.append(NEWLINE); sbReturn.append("PlainAnswer contents:"); sbReturn.append(this.contents); sbReturn.append(NEWLINE); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("