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