home *** CD-ROM | disk | FTP | other *** search
- import java.io.*;
-
- 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, May 6th, 1996
- //
- // Version 0.4a
- //
-
- PrintStream HTMLOut;
- //
- // Constructor -- Creates and opens file for output;
- //
-
- WriteHTMLFile(String filename) throws IOException {
- FileOutputStream FileOut = new FileOutputStream(filename);
- this.HTMLOut = new PrintStream(FileOut);
- this.WriteTag("<HTML>", true);
- }
-
- //
- // Low level HTML output methods
- //
-
- void WriteNewline(boolean Newline) throws IOException {
- if (Newline) {
- HTMLOut.println();
- }
- }
-
- void CloseHTML() throws IOException {
- this.WriteTag("</HTML>", true);
- HTMLOut.close();
- }
-
- void WriteContent(String Content) throws IOException {
- // Note: Simply a print for now
- // Future releases will have an HTML entity
- // translator to insure bulletproof output
- HTMLOut.print(Content);
- }
-
- //
- // WriteTag -- Main method for writing tags and content
- //
-
- void WriteTag(String Tag, boolean Newline) throws IOException {
- HTMLOut.print(Tag);
- this.WriteNewline(Newline);
- }
-
- void WriteTag(String Tag, String Content, boolean Newline) throws IOException {
- this.WriteTag(Tag, false);
- this.WriteContent(Content);
- this.WriteNewline(Newline);
- }
-
- void WriteTag(String Tag1, String Content, String Tag2, boolean Newline) throws IOException {
- this.WriteTag(Tag1, false);
- this.WriteContent(Content);
- this.WriteTag(Tag2, Newline);
- }
-
- //
- // High level HTML methods
- //
-
- void Comment(String Content) throws IOException {
- this.WriteTag("<-- ",Content," -->", true);
- }
-
- void TitleTag(String Content) throws IOException {
- this.WriteTag("<TITLE>",Content,"</TITLE>", true);
- }
-
- void BodyTag() throws IOException {
- this.WriteTag("<BODY>", true);
- }
-
- void BodyEndTag() throws IOException {
- this.WriteTag("</BODY>", true);
- }
-
- void HeadTag() throws IOException {
- this.WriteTag("<HEAD>", true);
- }
-
- void HeadEndTag() throws IOException {
- this.WriteTag("</HEAD>", true);
- }
-
- void ParaTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("<P>", false);
- }
-
- void ParaEndTag() throws IOException {
- this.WriteTag("</P>", true);
- }
-
- void EmphTag() throws IOException {
- this.WriteTag("<EM>", false);
- }
-
- void EmphEndTag() throws IOException {
- this.WriteTag("</EM>", false);
- }
-
- void HeadingTag(int Level, String Content) throws IOException {
- this.WriteTag("<H"+Level+">", Content, "</H"+Level+">", true);
- }
-
- void HorizRuleTag() throws IOException {
- this.WriteTag("<HR>", true);
- }
-
- void LineBreakTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("<BR>", false);
- }
-
- void UnordListTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("<UL>", true);
- }
-
- void UnordListEndTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("</UL>", true);
- }
-
- void OrdListTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("<OL>", true);
- }
-
- void OrdListEndTag() throws IOException {
- this.WriteNewline(true);
- this.WriteTag("</OL>", true);
- }
-
- void ListItemTag(String Content) throws IOException {
- this.WriteTag("<LI>",Content,true);
- }
-
- void ListItemTag() throws IOException {
- this.WriteTag("<LI>", false);
- }
- //
- // Link tag methods
- //
- // Note that the URL (HREF and NAME) is _not_ in quotes!
- //
-
- void AnchorLink(String URL, String Content, boolean newline) throws IOException {
- this.WriteTag("<A HREF=\""+URL+"\">", Content,"</A>", newline);
- }
-
- void NameLink(String Name, String Content, boolean newline) throws IOException {
- this.WriteTag("<A NAME=\""+Name+"\">", Content,"</A>",newline);
- }
- }
-