01 
02 /*
03  *  JavaDoq 1.0 - DOCUment JAVA In Source
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.javadoq.com>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package com.javadoq.html;
21 
22 import com.javadoq.JavaDoq;
23 
24 /**
25  * <p>An abstract base class of transformers that create target HTML files.</p>
26  * 
27  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.javadoq.com" target="_blank">http://www.javadoq.com</a>
28  */
29 public abstract class DoqHTMLFile extends Doq
30 {
31     /**
32      * <p>The {@link JavaDoq} environment of this transformer.</p>
33      * @since 1.0
34      */
35     public final JavaDoq jdoq;
36 
37     /**
38      * <p>Constructs a {@link DoqHTMLFile} transformer without style sheet.</p>
39      * <p>This constructor invokes its super constructor to create and open the target file.</p>
40      * @param jdoq The {@link JavaDoq} environment for the transformer.
41      * @param fileName The absolute path of the source file to transform.
42      * @param title The title for the target HTML file.
43      * @since 1.0
44      */
45     protected DoqHTMLFile(JavaDoq jdoq, String fileName, String title) {
46         this(jdoq, fileName, title, STYLE_SHEET);
47     }
48 
49     /**
50      * <p>Constructs a {@link DoqHTMLFile} transformer with a given style sheet.</p>
51      * <p>This constructor invokes its super constructor to create and open the target file.</p>
52      * @param jdoq The {@link JavaDoq} environment for the transformer.
53      * @param fileName The absolute path of the source file to transform.
54      * @param title The title for the target HTML file.
55      * @param css The name of the cascade style sheet file.
56      * @since 1.0
57      */
58     protected DoqHTMLFile(JavaDoq jdoq, String fileName, String title, String css) {
59         super(fileName);
60         this.jdoq = jdoq;
61         writeLine("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//\">");
62         writeLine("<html>");
63         writeLine("<head>");
64         writeLine("<meta name=\"generator\" content=\"" + JavaDoq.VERSION + "\" charset='utf-8'>");
65         writeLine("<title>JavaDoq: " + title + "</title>");
66         if (css != null) {
67             writeLine("<link rel =\"stylesheet\" type=\"text/css\" href=\"" + css + "\" title=\"style\">");
68         }
69         writeLine("</head>");
70     }
71 
72     /**
73      * <p>Writes a frame item to the target HTML file.</p>
74      * @param href The hyper link for the frame item.
75      * @param target The target for the frame item.
76      * @param text The text for the frame item.
77      * @since 1.0
78      */
79     protected final void writeFrameItem(String href, String target, String text) {
80         writeLine("<br><a href=\"" + href + "\" target=\"" + target + "\">" + text + "</a>");
81     }
82 
83     /**
84      * <p>Closes the target HTML file.</p>
85      * <p>This method closes HTML and invokes its super method to close the file.</p>
86      * @since 1.0
87      */
88     @Override
89     public void close() {
90         writeLine("</html>");
91         super.close();
92     }
93 }