import java.net.*; import java.io.*; import java.util.*; //import Html; /** * This type is one term from a glossary. A term should be * a phrase or word or some textual form which may be defined * or have a definition associated with it. The combination * of phrase and definition is called a GlossaryItem and the * whole list is called a Glossary. * * @author http://bumble.sf.net * @See Glossary */ public class FootnoteID extends Object { //-------------------------------------------- private static String NEWLINE = System.getProperty("line.separator"); //-------------------------------------------- /** the text of the id */ private String text; //-------------------------------------------- public static String TERMINATOR = ";"; //-------------------------------------------- public static String INDICATOR = NEWLINE; //-------------------------------------------- private boolean isGood; //-------------------------------------------- //-------------------------------------------- public FootnoteID() { this.text = ""; } //-------------------------------------------- /** construct with some text */ public FootnoteID(String sText) { this(); this.loadData(sText); } //-------------------------------------------- /** load data from text */ public void loadData(String sText) { String sTextTrimmed; this.isGood = this.isFootnoteID(sText); if (!this.isGood) { return; } sTextTrimmed = sText.trim(); this.text = sTextTrimmed.substring( this.INDICATOR.length(), sTextTrimmed.length() - this.TERMINATOR.length()); } //-- method: loadData //-------------------------------------------- public String getText() { return this.text; } //-------------------------------------------- public void setText(String sText) { this.text = sText; } //-------------------------------------------- public static boolean recognize(String sText) { if (!sText.endsWith(FootnoteID.INDICATOR)) { return false; } //-- a single quote escapes, as is usual //-- if (sText.endsWith("'" + FootnoteID.INDICATOR)) { return false; } return true; } //-------------------------------------------- /** checks if this looks like a FootnoteID */ public static boolean isFootnoteID(String sText) { if (sText.trim().length() == 0) { return false; } if (!sText.trim().startsWith(FootnoteID.INDICATOR)) { return false; } if (!sText.trim().endsWith(FootnoteID.TERMINATOR)) { return false; } return true; } //-------------------------------------------- public String toString() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(FootnoteID.INDICATOR); sbReturn.append(this.text); sbReturn.append(FootnoteID.TERMINATOR); return sbReturn.toString(); } //-------------------------------------------- public String printReport() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("FootnoteID Indicator :"); sbReturn.append(FootnoteID.INDICATOR); sbReturn.append(NEWLINE); sbReturn.append("FootnoteID Terminator:"); sbReturn.append(FootnoteID.TERMINATOR); sbReturn.append(NEWLINE); sbReturn.append("glossary term text:"); sbReturn.append(this.text); sbReturn.append(NEWLINE); return sbReturn.toString(); } //-------------------------------------------- public String printHtml() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("
"); sbReturn.append(Html.encode(this.text.trim())); sbReturn.append("
"); return sbReturn.toString(); } //-------------------------------------------- public String printIndexedHtml(int iIndex) { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append("
"); sbReturn.append(NEWLINE); sbReturn.append( ""); sbReturn.append(NEWLINE); sbReturn.append("(*)"); sbReturn.append(""); sbReturn.append(NEWLINE); sbReturn.append(""); sbReturn.append(NEWLINE); sbReturn.append(""); sbReturn.append(Html.encode(this.text.trim())); sbReturn.append("
"); return sbReturn.toString(); } //-------------------------------------------- /** docbook footnotes dont work as I would like. */ public String printDocBook() { StringBuffer sbReturn = new StringBuffer(""); sbReturn.append(""); sbReturn.append(""); sbReturn.append(Html.encode(this.text.trim())); sbReturn.append(""); 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 FootnoteID text"); sbUsageMessage.append(NEWLINE); sbUsageMessage.append(" eg java FootnoteID \""); sbUsageMessage.append(FootnoteID.INDICATOR); sbUsageMessage.append("a"); sbUsageMessage.append(FootnoteID.TERMINATOR); sbUsageMessage.append("\""); sbUsageMessage.append(NEWLINE); StringBuffer sbMessage = new StringBuffer(""); if (args.length == 0) { System.out.println(sbUsageMessage); System.exit(-1); } FootnoteID rTest = new FootnoteID(args[0]); System.out.println(".printHtml()"); System.out.println(rTest.printHtml()); System.out.println(".printDocBook()"); System.out.println(rTest.printDocBook()); System.out.println(".toString()"); System.out.println(rTest.toString()); System.out.println(".printReport()"); System.out.println(rTest.printReport()); } //-- main() } //-- FootnoteID class