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.  
  4.  
  5. class WriteHTMLFile {
  6.  
  7. //
  8.  
  9. // WriteHTMLFile - A set of methods to create and
  10.  
  11. // write to an HTML file, encapsulating HTML-specific
  12.  
  13. // codes to a single class.
  14.  
  15. //
  16.  
  17. // David Moisan, May 6th, 1996
  18.  
  19. //
  20.  
  21. // Version 0.4a
  22.  
  23. //
  24.  
  25.  
  26.  
  27.    PrintStream HTMLOut;
  28.  
  29. //
  30.  
  31. // Constructor -- Creates and opens file for output;
  32.  
  33. //
  34.  
  35.  
  36.  
  37.    WriteHTMLFile(String filename) throws IOException {
  38.  
  39.       FileOutputStream FileOut = new FileOutputStream(filename);
  40.  
  41.       this.HTMLOut = new PrintStream(FileOut);
  42.  
  43.       this.WriteTag("<HTML>", true);
  44.  
  45.       }    
  46.  
  47.  
  48.  
  49. // 
  50.  
  51. // Low level HTML output methods
  52.  
  53. //
  54.  
  55.  
  56.  
  57.    void WriteNewline(boolean Newline) throws IOException {
  58.  
  59.       if (Newline) {
  60.  
  61.          HTMLOut.println();
  62.  
  63.          }
  64.  
  65.       }
  66.  
  67.  
  68.  
  69.    void CloseHTML() throws IOException {
  70.  
  71.       this.WriteTag("</HTML>", true);
  72.  
  73.       HTMLOut.close();
  74.  
  75.       }
  76.  
  77.  
  78.  
  79.    void WriteContent(String Content) throws IOException {
  80.  
  81.       // Note:  Simply a print for now
  82.  
  83.       // Future releases will have an HTML entity
  84.  
  85.       // translator to insure bulletproof output
  86.  
  87.       HTMLOut.print(Content);
  88.  
  89.       }
  90.  
  91.  
  92.  
  93. //
  94.  
  95. // WriteTag -- Main method for writing tags and content
  96.  
  97. //
  98.  
  99.  
  100.  
  101.    void WriteTag(String Tag, boolean Newline) throws IOException {
  102.  
  103.       HTMLOut.print(Tag);
  104.  
  105.       this.WriteNewline(Newline);
  106.  
  107.       }
  108.  
  109.  
  110.  
  111.    void WriteTag(String Tag, String Content, boolean Newline) throws IOException {
  112.  
  113.       this.WriteTag(Tag, false);
  114.  
  115.       this.WriteContent(Content);
  116.  
  117.       this.WriteNewline(Newline);
  118.  
  119.       }
  120.  
  121.  
  122.  
  123.    void WriteTag(String Tag1, String Content, String Tag2, boolean Newline) throws IOException {
  124.  
  125.        this.WriteTag(Tag1, false);
  126.  
  127.       this.WriteContent(Content);
  128.  
  129.       this.WriteTag(Tag2, Newline);
  130.  
  131.       }
  132.  
  133.  
  134.  
  135. //
  136.  
  137. // High level HTML methods
  138.  
  139. //
  140.  
  141.  
  142.  
  143.     void Comment(String Content) throws IOException {
  144.  
  145.         this.WriteTag("<-- ",Content," -->", true);
  146.  
  147.         }
  148.  
  149.  
  150.  
  151.     void TitleTag(String Content) throws IOException {
  152.  
  153.         this.WriteTag("<TITLE>",Content,"</TITLE>", true);
  154.  
  155.         }
  156.  
  157.     
  158.  
  159.     void BodyTag() throws IOException {
  160.  
  161.         this.WriteTag("<BODY>", true);
  162.  
  163.         }
  164.  
  165.  
  166.  
  167.     void BodyEndTag() throws IOException {
  168.  
  169.         this.WriteTag("</BODY>", true);        
  170.  
  171.         }
  172.  
  173.  
  174.  
  175.     void HeadTag() throws IOException {    
  176.  
  177.         this.WriteTag("<HEAD>", true);
  178.  
  179.         }
  180.  
  181.  
  182.  
  183.     void HeadEndTag() throws IOException {
  184.  
  185.         this.WriteTag("</HEAD>", true);
  186.  
  187.         }
  188.  
  189.  
  190.  
  191.     void ParaTag() throws IOException {
  192.  
  193.         this.WriteNewline(true);
  194.  
  195.         this.WriteTag("<P>", false);
  196.  
  197.         }
  198.  
  199.  
  200.  
  201.     void ParaEndTag() throws IOException {
  202.  
  203.         this.WriteTag("</P>", true);
  204.  
  205.         }
  206.  
  207.  
  208.  
  209.     void EmphTag() throws IOException {
  210.  
  211.         this.WriteTag("<EM>", false);
  212.  
  213.         }
  214.  
  215.  
  216.  
  217.     void EmphEndTag() throws IOException {
  218.  
  219.         this.WriteTag("</EM>", false);
  220.  
  221.         }
  222.  
  223.  
  224.  
  225.     void HeadingTag(int Level, String Content) throws IOException {
  226.  
  227.         this.WriteTag("<H"+Level+">", Content, "</H"+Level+">", true);
  228.  
  229.         }
  230.  
  231.  
  232.  
  233.     void HorizRuleTag() throws IOException {
  234.  
  235.         this.WriteTag("<HR>", true);
  236.  
  237.         }
  238.  
  239.  
  240.  
  241.     void LineBreakTag() throws IOException {
  242.  
  243.         this.WriteNewline(true);
  244.  
  245.         this.WriteTag("<BR>", false);
  246.  
  247.         }
  248.  
  249.  
  250.  
  251.     void UnordListTag() throws IOException {
  252.  
  253.         this.WriteNewline(true);
  254.  
  255.         this.WriteTag("<UL>", true);
  256.  
  257.         }
  258.  
  259.  
  260.  
  261.     void UnordListEndTag() throws IOException {
  262.  
  263.         this.WriteNewline(true);
  264.  
  265.         this.WriteTag("</UL>", true);
  266.  
  267.         }
  268.  
  269.  
  270.  
  271.     void OrdListTag() throws IOException {
  272.  
  273.         this.WriteNewline(true);
  274.  
  275.         this.WriteTag("<OL>", true);
  276.  
  277.         }
  278.  
  279.  
  280.  
  281.     void OrdListEndTag() throws IOException {
  282.  
  283.         this.WriteNewline(true);
  284.  
  285.         this.WriteTag("</OL>", true);
  286.  
  287.         }
  288.  
  289.    
  290.  
  291.     void ListItemTag(String Content) throws IOException {
  292.  
  293.         this.WriteTag("<LI>",Content,true);
  294.  
  295.         }
  296.  
  297.     
  298.  
  299.     void ListItemTag() throws IOException {
  300.  
  301.         this.WriteTag("<LI>", false);
  302.  
  303.         }
  304.  
  305. //
  306.  
  307. // Link tag methods
  308.  
  309. //
  310.  
  311. // Note that the URL (HREF and NAME) is _not_ in quotes!
  312.  
  313. //
  314.  
  315.  
  316.  
  317.     void AnchorLink(String URL, String Content, boolean newline) throws IOException {
  318.  
  319.         this.WriteTag("<A HREF=\""+URL+"\">", Content,"</A>", newline);
  320.  
  321.         }
  322.  
  323.  
  324.  
  325.     void NameLink(String Name, String Content, boolean newline) throws IOException {
  326.  
  327.         this.WriteTag("<A NAME=\""+Name+"\">", Content,"</A>",newline);
  328.  
  329.         }
  330.  
  331. }
  332.  
  333.