import java.util.*; //import Html; //import TextTool; //import QuoteText; /** * * This type is a piece of text which does not have any * link information associated with it. * * @author http://bumble.sf.net * */ public class PlainText extends Object implements DocumentElement { //-------------------------------------------- private static String NEWLINE = System.getProperty("line.separator"); //-------------------------------------------- /** the contents */ private String text; //-------------------------------------------- private boolean isGood; //-------------------------------------------- //-------------------------------------------- public PlainText() { this.text = ""; } //-------------------------------------------- /** construct with some text */ public PlainText(String sText) { this(); this.loadData(sText); } //-------------------------------------------- /** load data from text */ public void loadData(String sText) { String sTextTrimmed; this.isGood = this.isPlainText(sText); if (!this.isGood) { return; } this.text = sText; } //-- method: loadData //-------------------------------------------- public String getText() { return this.text; } //-------------------------------------------- public void setText(String sText) { this.text = sText; } //-------------------------------------------- public int getLength() { return this.text.length(); } //-------------------------------------------- /** since plain text has no structure which I can * think of, no checks will be made at the moment */ public static boolean isPlainText(String sText) { return true; } //-------------------------------------------- public String toString() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(this.text); return sbReturn.toString(); } //-------------------------------------------- public String printReport() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("Contents >"); sbReturn.append(this.text); sbReturn.append(NEWLINE); sbReturn.append("Length >"); sbReturn.append(this.getLength()); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(Html.encode(this.text)); return sbReturn.toString(); } //-------------------------------------------- /** provide docbook xml. maybe useful for converting * to other formats */ public String printDocBook() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(""); sbReturn.append(Html.encode(this.text)); sbReturn.append(""); return sbReturn.toString(); } //-------------------------------------------- public String print() { StringBuffer sbReturn = new StringBuffer(""); return this.toString(); } //-------------------------------------------- /** a main method for testing */ public static void main(String[] args) throws Exception { StringBuffer sbUsageMessage = new StringBuffer(""); sbUsageMessage.append("test usage: java PlainText text"); sbUsageMessage.append(NEWLINE); sbUsageMessage.append("eg: java PlainText \"text here\" "); sbUsageMessage.append(NEWLINE); StringBuffer sbMessage = new StringBuffer(""); if (args.length == 0) { System.out.println(sbUsageMessage); System.exit(-1); } PlainText text = new PlainText(args[0]); System.out.println(".printHtml()"); System.out.println(text.printHtml()); System.out.println(".toString()"); System.out.println(text.toString()); System.out.println(".printReport()"); System.out.println(text.printReport()); } //-- main() } //-- PlainText class