home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / APPLETS / WRITEHTM.JAV < prev   
Encoding:
Text File  |  1997-02-27  |  4.1 KB  |  167 lines

  1. import java.io.*;
  2.  
  3. class WriteHTMLFile {
  4. //
  5. // WriteHTMLFile - A set of methods to create and
  6. // write to an HTML file, encapsulating HTML-specific
  7. // codes to a single class.
  8. //
  9. // David Moisan, May 6th, 1996
  10. //
  11. // Version 0.4a
  12. //
  13.  
  14.    PrintStream HTMLOut;
  15. //
  16. // Constructor -- Creates and opens file for output;
  17. //
  18.  
  19.    WriteHTMLFile(String filename) throws IOException {
  20.       FileOutputStream FileOut = new FileOutputStream(filename);
  21.       this.HTMLOut = new PrintStream(FileOut);
  22.       this.WriteTag("<HTML>", true);
  23.       }    
  24.  
  25. // 
  26. // Low level HTML output methods
  27. //
  28.  
  29.    void WriteNewline(boolean Newline) throws IOException {
  30.       if (Newline) {
  31.          HTMLOut.println();
  32.          }
  33.       }
  34.  
  35.    void CloseHTML() throws IOException {
  36.       this.WriteTag("</HTML>", true);
  37.       HTMLOut.close();
  38.       }
  39.  
  40.    void WriteContent(String Content) throws IOException {
  41.       // Note:  Simply a print for now
  42.       // Future releases will have an HTML entity
  43.       // translator to insure bulletproof output
  44.       HTMLOut.print(Content);
  45.       }
  46.  
  47. //
  48. // WriteTag -- Main method for writing tags and content
  49. //
  50.  
  51.    void WriteTag(String Tag, boolean Newline) throws IOException {
  52.       HTMLOut.print(Tag);
  53.       this.WriteNewline(Newline);
  54.       }
  55.  
  56.    void WriteTag(String Tag, String Content, boolean Newline) throws IOException {
  57.       this.WriteTag(Tag, false);
  58.       this.WriteContent(Content);
  59.       this.WriteNewline(Newline);
  60.       }
  61.  
  62.    void WriteTag(String Tag1, String Content, String Tag2, boolean Newline) throws IOException {
  63.        this.WriteTag(Tag1, false);
  64.       this.WriteContent(Content);
  65.       this.WriteTag(Tag2, Newline);
  66.       }
  67.  
  68. //
  69. // High level HTML methods
  70. //
  71.  
  72.     void Comment(String Content) throws IOException {
  73.         this.WriteTag("<-- ",Content," -->", true);
  74.         }
  75.  
  76.     void TitleTag(String Content) throws IOException {
  77.         this.WriteTag("<TITLE>",Content,"</TITLE>", true);
  78.         }
  79.     
  80.     void BodyTag() throws IOException {
  81.         this.WriteTag("<BODY>", true);
  82.         }
  83.  
  84.     void BodyEndTag() throws IOException {
  85.         this.WriteTag("</BODY>", true);        
  86.         }
  87.  
  88.     void HeadTag() throws IOException {    
  89.         this.WriteTag("<HEAD>", true);
  90.         }
  91.  
  92.     void HeadEndTag() throws IOException {
  93.         this.WriteTag("</HEAD>", true);
  94.         }
  95.  
  96.     void ParaTag() throws IOException {
  97.         this.WriteNewline(true);
  98.         this.WriteTag("<P>", false);
  99.         }
  100.  
  101.     void ParaEndTag() throws IOException {
  102.         this.WriteTag("</P>", true);
  103.         }
  104.  
  105.     void EmphTag() throws IOException {
  106.         this.WriteTag("<EM>", false);
  107.         }
  108.  
  109.     void EmphEndTag() throws IOException {
  110.         this.WriteTag("</EM>", false);
  111.         }
  112.  
  113.     void HeadingTag(int Level, String Content) throws IOException {
  114.         this.WriteTag("<H"+Level+">", Content, "</H"+Level+">", true);
  115.         }
  116.  
  117.     void HorizRuleTag() throws IOException {
  118.         this.WriteTag("<HR>", true);
  119.         }
  120.  
  121.     void LineBreakTag() throws IOException {
  122.         this.WriteNewline(true);
  123.         this.WriteTag("<BR>", false);
  124.         }
  125.  
  126.     void UnordListTag() throws IOException {
  127.         this.WriteNewline(true);
  128.         this.WriteTag("<UL>", true);
  129.         }
  130.  
  131.     void UnordListEndTag() throws IOException {
  132.         this.WriteNewline(true);
  133.         this.WriteTag("</UL>", true);
  134.         }
  135.  
  136.     void OrdListTag() throws IOException {
  137.         this.WriteNewline(true);
  138.         this.WriteTag("<OL>", true);
  139.         }
  140.  
  141.     void OrdListEndTag() throws IOException {
  142.         this.WriteNewline(true);
  143.         this.WriteTag("</OL>", true);
  144.         }
  145.    
  146.     void ListItemTag(String Content) throws IOException {
  147.         this.WriteTag("<LI>",Content,true);
  148.         }
  149.     
  150.     void ListItemTag() throws IOException {
  151.         this.WriteTag("<LI>", false);
  152.         }
  153. //
  154. // Link tag methods
  155. //
  156. // Note that the URL (HREF and NAME) is _not_ in quotes!
  157. //
  158.  
  159.     void AnchorLink(String URL, String Content, boolean newline) throws IOException {
  160.         this.WriteTag("<A HREF=\""+URL+"\">", Content,"</A>", newline);
  161.         }
  162.  
  163.     void NameLink(String Name, String Content, boolean newline) throws IOException {
  164.         this.WriteTag("<A NAME=\""+Name+"\">", Content,"</A>",newline);
  165.         }
  166. }
  167.