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("