import java.util.*; //import Html; //import MixedText; /** * This type is a definition of some textual term which is * part of a glossary which explains a list of terms. * * * @author http://bumble.sf.net * @See GlossaryItem, GlossaryTerm, Glossary */ public class Definition extends Object { //-------------------------------------------- private static String NEWLINE = System.getProperty("line.separator"); //-------------------------------------------- /** the text of the Definition */ private MixedText contents; //-------------------------------------------- public static String TERMINATOR = ""; //-------------------------------------------- public static String INDICATOR = ""; //-------------------------------------------- private boolean isGood; //-------------------------------------------- //-------------------------------------------- public Definition() { this.contents = new MixedText(); } //-------------------------------------------- /** construct with some text */ public Definition(String sText) { this(); this.loadData(sText); } //-------------------------------------------- /** load data from text */ public void loadData(String sText) { this.isGood = this.isDefinition(sText); if (!this.isGood) { return; } if (sText.trim().startsWith(Definition.INDICATOR)) { this.contents = new MixedText( sText.trim().substring(Definition.INDICATOR.length())); } else { this.contents = new MixedText(sText); } } //-------------------------------------------- public MixedText getContents() { return this.contents; } //-------------------------------------------- public void setContents(String sContents) { this.contents = new MixedText(sContents); } //-------------------------------------------- /** this may remain unused since the definition will be * whatever comes after the term * */ public static boolean recognize(String sText) { if (!sText.endsWith(Definition.INDICATOR)) { return false; } //-- a single quote escapes, as is usual //-- if (sText.endsWith("'" + Definition.INDICATOR)) { return false; } return true; } //-------------------------------------------- /** checks if this looks like a Definition, but an Definition * will be whatever is left over */ public static boolean isDefinition(String sText) { /* ---------------- if (sText.trim().length() == 0) { return false; } if (!sText.trim().startsWith(Definition.INDICATOR)) { return false; } if (!sText.trim().endsWith(Definition.TERMINATOR)) { return false; } */ return true; } //-------------------------------------------- public String toString() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(Definition.INDICATOR); sbReturn.append(this.contents.toString()); sbReturn.append(Definition.TERMINATOR); return sbReturn.toString(); } //-------------------------------------------- public String printReport() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("Definition Indicator >"); sbReturn.append(Definition.INDICATOR); sbReturn.append(NEWLINE); sbReturn.append("Definition Terminator>"); sbReturn.append(Definition.TERMINATOR); sbReturn.append(NEWLINE); sbReturn.append("Definition contents >"); sbReturn.append(this.contents.toString()); sbReturn.append(NEWLINE); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("
"); sbReturn.append(NEWLINE); sbReturn.append(this.contents.printHtml().trim()); sbReturn.append(NEWLINE); sbReturn.append("
"); return sbReturn.toString(); } //-------------------------------------------- public String printDocBook() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(""); sbReturn.append(NEWLINE); sbReturn.append(""); sbReturn.append(this.contents.toString().trim()); sbReturn.append(""); sbReturn.append(NEWLINE); sbReturn.append(""); sbReturn.append(NEWLINE); 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 Definition text"); sbUsageMessage.append(NEWLINE); sbUsageMessage.append(" eg java Definition \" not an enhancement\" "); sbUsageMessage.append(NEWLINE); StringBuffer sbMessage = new StringBuffer(""); if (args.length == 0) { System.out.println(sbUsageMessage); System.exit(-1); } Definition rTest = new Definition(args[0]); System.out.println(".printHtml()"); System.out.println(rTest.printHtml()); System.out.println(".printDocBook()"); System.out.println(rTest.printDocBook()); System.out.println(""); System.out.println(".toString()"); System.out.println(rTest.toString()); System.out.println(""); System.out.println(".printReport()"); System.out.println(rTest.printReport()); } //-- main() } //-- Definition class