import java.io.*; import java.util.*; class WriteHTMLFile { // // WriteHTMLFile - A set of methods to create and // write to an HTML file, encapsulating HTML-specific // codes to a single class. // // David Moisan, April 1st, 1999 // // Version 1.2 // // License terms: This is open source freely distributable // under the terms of the Gnu Public License (http://www.gnu.org) // // Changes in this version: // // Comment method now fixed to produce correct SGML comments // Doctype method added for easier validation // Right now, the DOCTYPE is hard-coded into the constructor // so that WriteHTMLFile uses HTML 4.0 Transitional. // This could change // // // These constants are added for readability and are used to // define whether or not a new line is written in the HTML // output stream. static final boolean NEWLINE = true; static final boolean NONEWLINE = false; PrintStream HTMLOut; String HTMLDocType=" -//W3C//DTD HTML 4.0 Transitional//EN"; // // Constructor -- Creates and opens file for output; // // WriteHTMLFile(String filename) throws IOException { FileOutputStream FileOut = new FileOutputStream(filename); this.HTMLOut = new PrintStream(FileOut); this.Doctype(HTMLDocType); this.WriteTag("", NEWLINE); } // // Low level HTML output methods // void WriteNewline(boolean Newline) throws IOException { if (Newline) { HTMLOut.println(); } } void CloseHTML() throws IOException { this.HTMLEnd(); HTMLOut.close(); } void WriteContent(String Content) throws IOException { final String STAG = "<"; // Start of HTML tag final String ETAG = ">"; // End of HTML tag final String ENT = "&"; // HTML entity designator final String HTMLDELIM = STAG+" "+ETAG+" "+ENT; String NextHTMLToken; StringTokenizer HTMLContentString = new StringTokenizer (Content, HTMLDELIM, true); while (HTMLContentString.hasMoreTokens()) { NextHTMLToken = HTMLContentString.nextToken(); if (NextHTMLToken.equals(STAG)) { HTMLOut.print("<"); } else if (NextHTMLToken.equals(ETAG)) { HTMLOut.print(">"); } else if (NextHTMLToken.equals(ENT)) { HTMLOut.print("&"); } else { HTMLOut.print(NextHTMLToken); } } } // // WriteTag -- Main method for writing tags and content // // There are three different method calls for convienience // // (Tag, Newline) // For simple empty tag insertion (e.g., ) // // (Tag, Content, Newline) // // For tags with content (such as
", NONEWLINE); } void ParaEndTag() throws IOException { this.WriteTag("
", NEWLINE); } void EmphTag() throws IOException { this.WriteTag("", NONEWLINE); } void EmphTag(String Content) throws IOException { this.WriteTag("", Content, "", NONEWLINE); } void EmphEndTag() throws IOException { this.WriteTag("", NONEWLINE); } void CiteTag() throws IOException { this.WriteTag("", NONEWLINE); } void CiteTag(String Content) throws IOException { this.WriteTag("", Content, "", NONEWLINE); } void CiteEndTag() throws IOException { this.WriteTag("", NONEWLINE); } void HeadingTag(int Level, String Content) throws IOException { this.WriteTag("