10
|
1 |
/*
|
|
2 |
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.doclets.formats.html.markup;
|
|
27 |
|
|
28 |
import com.sun.tools.doclets.internal.toolkit.*;
|
|
29 |
|
|
30 |
import com.sun.javadoc.*;
|
|
31 |
import java.io.*;
|
|
32 |
import java.util.*;
|
|
33 |
import com.sun.tools.doclets.internal.toolkit.util.*;
|
|
34 |
|
|
35 |
|
|
36 |
/**
|
|
37 |
* Class for the Html Format Code Generation specific to JavaDoc.
|
|
38 |
* This Class contains methods related to the Html Code Generation which
|
|
39 |
* are used by the Sub-Classes in the package com.sun.tools.doclets.standard
|
|
40 |
* and com.sun.tools.doclets.oneone.
|
|
41 |
*
|
|
42 |
* @since 1.2
|
|
43 |
* @author Atul M Dambalkar
|
|
44 |
* @author Robert Field
|
|
45 |
*/
|
|
46 |
public abstract class HtmlDocWriter extends HtmlWriter {
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Constructor. Initializes the destination file name through the super
|
|
50 |
* class HtmlWriter.
|
|
51 |
*
|
|
52 |
* @param filename String file name.
|
|
53 |
*/
|
|
54 |
public HtmlDocWriter(Configuration configuration,
|
|
55 |
String filename) throws IOException {
|
|
56 |
super(configuration,
|
|
57 |
null, configuration.destDirName + filename,
|
|
58 |
configuration.docencoding);
|
|
59 |
configuration.message.notice("doclet.Generating_0",
|
|
60 |
configuration.destDirName + filename);
|
|
61 |
}
|
|
62 |
|
|
63 |
public HtmlDocWriter(Configuration configuration,
|
|
64 |
String path, String filename) throws IOException {
|
|
65 |
super(configuration,
|
|
66 |
configuration.destDirName + path, filename,
|
|
67 |
configuration.docencoding);
|
|
68 |
configuration.message.notice("doclet.Generating_0",
|
|
69 |
configuration.destDirName +
|
|
70 |
((path.length() > 0)?
|
|
71 |
path + File.separator: "") + filename);
|
|
72 |
}
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Accessor for configuration.
|
|
76 |
*/
|
|
77 |
public abstract Configuration configuration();
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Print Html Hyper Link.
|
|
81 |
*
|
|
82 |
* @param link String name of the file.
|
|
83 |
* @param where Position of the link in the file. Character '#' is not
|
|
84 |
* needed.
|
|
85 |
* @param label Tag for the link.
|
|
86 |
* @param bold Boolean that sets label to bold.
|
|
87 |
*/
|
|
88 |
public void printHyperLink(String link, String where,
|
|
89 |
String label, boolean bold) {
|
|
90 |
print(getHyperLink(link, where, label, bold, "", "", ""));
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Print Html Hyper Link.
|
|
95 |
*
|
|
96 |
* @param link String name of the file.
|
|
97 |
* @param where Position of the link in the file. Character '#' is not
|
|
98 |
* needed.
|
|
99 |
* @param label Tag for the link.
|
|
100 |
*/
|
|
101 |
public void printHyperLink(String link, String where, String label) {
|
|
102 |
printHyperLink(link, where, label, false);
|
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Print Html Hyper Link.
|
|
107 |
*
|
|
108 |
* @param link String name of the file.
|
|
109 |
* @param where Position of the link in the file. Character '#' is not
|
|
110 |
* needed.
|
|
111 |
* @param label Tag for the link.
|
|
112 |
* @param bold Boolean that sets label to bold.
|
|
113 |
* @param stylename String style of text defined in style sheet.
|
|
114 |
*/
|
|
115 |
public void printHyperLink(String link, String where,
|
|
116 |
String label, boolean bold,
|
|
117 |
String stylename) {
|
|
118 |
print(getHyperLink(link, where, label, bold, stylename, "", ""));
|
|
119 |
}
|
|
120 |
|
|
121 |
/**
|
|
122 |
* Return Html Hyper Link string.
|
|
123 |
*
|
|
124 |
* @param link String name of the file.
|
|
125 |
* @param where Position of the link in the file. Character '#' is not
|
|
126 |
* needed.
|
|
127 |
* @param label Tag for the link.
|
|
128 |
* @param bold Boolean that sets label to bold.
|
|
129 |
* @return String Hyper Link.
|
|
130 |
*/
|
|
131 |
public String getHyperLink(String link, String where,
|
|
132 |
String label, boolean bold) {
|
|
133 |
return getHyperLink(link, where, label, bold, "", "", "");
|
|
134 |
}
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Get Html Hyper Link string.
|
|
138 |
*
|
|
139 |
* @param link String name of the file.
|
|
140 |
* @param where Position of the link in the file. Character '#' is not
|
|
141 |
* needed.
|
|
142 |
* @param label Tag for the link.
|
|
143 |
* @param bold Boolean that sets label to bold.
|
|
144 |
* @param stylename String style of text defined in style sheet.
|
|
145 |
* @return String Hyper Link.
|
|
146 |
*/
|
|
147 |
public String getHyperLink(String link, String where,
|
|
148 |
String label, boolean bold,
|
|
149 |
String stylename) {
|
|
150 |
return getHyperLink(link, where, label, bold, stylename, "", "");
|
|
151 |
}
|
|
152 |
|
|
153 |
/**
|
|
154 |
* Get Html Hyper Link string.
|
|
155 |
*
|
|
156 |
* @param link String name of the file.
|
|
157 |
* @param where Position of the link in the file. Character '#' is not
|
|
158 |
* needed.
|
|
159 |
* @param label Tag for the link.
|
|
160 |
* @param bold Boolean that sets label to bold.
|
|
161 |
* @param stylename String style of text defined in style sheet.
|
|
162 |
* @param title String that describes the link's content for accessibility.
|
|
163 |
* @param target Target frame.
|
|
164 |
* @return String Hyper Link.
|
|
165 |
*/
|
|
166 |
public String getHyperLink(String link, String where,
|
|
167 |
String label, boolean bold,
|
|
168 |
String stylename, String title, String target) {
|
|
169 |
StringBuffer retlink = new StringBuffer();
|
|
170 |
retlink.append("<A HREF=\"");
|
|
171 |
retlink.append(link);
|
|
172 |
if (where != null && where.length() != 0) {
|
|
173 |
retlink.append("#");
|
|
174 |
retlink.append(where);
|
|
175 |
}
|
|
176 |
retlink.append("\"");
|
|
177 |
if (title != null && title.length() != 0) {
|
|
178 |
retlink.append(" title=\"" + title + "\"");
|
|
179 |
}
|
|
180 |
if (target != null && target.length() != 0) {
|
|
181 |
retlink.append(" target=\"" + target + "\"");
|
|
182 |
}
|
|
183 |
retlink.append(">");
|
|
184 |
if (stylename != null && stylename.length() != 0) {
|
|
185 |
retlink.append("<FONT CLASS=\"");
|
|
186 |
retlink.append(stylename);
|
|
187 |
retlink.append("\">");
|
|
188 |
}
|
|
189 |
if (bold) {
|
|
190 |
retlink.append("<B>");
|
|
191 |
}
|
|
192 |
retlink.append(label);
|
|
193 |
if (bold) {
|
|
194 |
retlink.append("</B>");
|
|
195 |
}
|
|
196 |
if (stylename != null && stylename.length() != 0) {
|
|
197 |
retlink.append("</FONT>");
|
|
198 |
}
|
|
199 |
retlink.append("</A>");
|
|
200 |
return retlink.toString();
|
|
201 |
}
|
|
202 |
|
|
203 |
/**
|
|
204 |
* Print link without positioning in the file.
|
|
205 |
*
|
|
206 |
* @param link String name of the file.
|
|
207 |
* @param label Tag for the link.
|
|
208 |
*/
|
|
209 |
public void printHyperLink(String link, String label) {
|
|
210 |
print(getHyperLink(link, "", label, false));
|
|
211 |
}
|
|
212 |
|
|
213 |
/**
|
|
214 |
* Get link string without positioning in the file.
|
|
215 |
*
|
|
216 |
* @param link String name of the file.
|
|
217 |
* @param label Tag for the link.
|
|
218 |
* @return Strign Hyper link.
|
|
219 |
*/
|
|
220 |
public String getHyperLink(String link, String label) {
|
|
221 |
return getHyperLink(link, "", label, false);
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* Print the name of the package, this class is in.
|
|
226 |
*
|
|
227 |
* @param cd ClassDoc.
|
|
228 |
*/
|
|
229 |
public void printPkgName(ClassDoc cd) {
|
|
230 |
print(getPkgName(cd));
|
|
231 |
}
|
|
232 |
|
|
233 |
/**
|
|
234 |
* Get the name of the package, this class is in.
|
|
235 |
*
|
|
236 |
* @param cd ClassDoc.
|
|
237 |
*/
|
|
238 |
public String getPkgName(ClassDoc cd) {
|
|
239 |
String pkgName = cd.containingPackage().name();
|
|
240 |
if (pkgName.length() > 0) {
|
|
241 |
pkgName += ".";
|
|
242 |
return pkgName;
|
|
243 |
}
|
|
244 |
return "";
|
|
245 |
}
|
|
246 |
|
|
247 |
/**
|
|
248 |
* Print the frameset version of the Html file header.
|
|
249 |
* Called only when generating an HTML frameset file.
|
|
250 |
*
|
|
251 |
* @param title Title of this HTML document.
|
|
252 |
*/
|
|
253 |
public void printFramesetHeader(String title) {
|
|
254 |
printFramesetHeader(title, false);
|
|
255 |
}
|
|
256 |
|
|
257 |
/**
|
|
258 |
* Print the frameset version of the Html file header.
|
|
259 |
* Called only when generating an HTML frameset file.
|
|
260 |
*
|
|
261 |
* @param title Title of this HTML document.
|
|
262 |
* @param noTimeStamp If true, don't print time stamp in header.
|
|
263 |
*/
|
|
264 |
public void printFramesetHeader(String title, boolean noTimeStamp) {
|
|
265 |
println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
|
|
266 |
"Frameset//EN\" " +
|
|
267 |
"\"http://www.w3.org/TR/html4/frameset.dtd\">");
|
|
268 |
println("<!--NewPage-->");
|
|
269 |
html();
|
|
270 |
head();
|
|
271 |
if (! noTimeStamp) {
|
|
272 |
print("<!-- Generated by javadoc on ");
|
|
273 |
print(today());
|
|
274 |
println("-->");
|
|
275 |
}
|
|
276 |
if (configuration.charset.length() > 0) {
|
|
277 |
println("<META http-equiv=\"Content-Type\" content=\"text/html; "
|
|
278 |
+ "charset=" + configuration.charset + "\">");
|
|
279 |
}
|
|
280 |
title();
|
|
281 |
println(title);
|
|
282 |
titleEnd();
|
|
283 |
//Script to set the classFrame if necessary.
|
|
284 |
script();
|
|
285 |
println(" targetPage = \"\" + window.location.search;");
|
|
286 |
println(" if (targetPage != \"\" && targetPage != \"undefined\")");
|
|
287 |
println(" targetPage = targetPage.substring(1);");
|
|
288 |
println(" if (targetPage.indexOf(\":\") != -1)");
|
|
289 |
println(" targetPage = \"undefined\";");
|
|
290 |
|
|
291 |
println(" function loadFrames() {");
|
|
292 |
println(" if (targetPage != \"\" && targetPage != \"undefined\")");
|
|
293 |
println(" top.classFrame.location = top.targetPage;");
|
|
294 |
println(" }");
|
|
295 |
scriptEnd();
|
|
296 |
noScript();
|
|
297 |
noScriptEnd();
|
|
298 |
headEnd();
|
|
299 |
}
|
|
300 |
|
|
301 |
/**
|
|
302 |
* Print the appropriate spaces to format the class tree in the class page.
|
|
303 |
*
|
|
304 |
* @param len Number of spaces.
|
|
305 |
*/
|
|
306 |
public String spaces(int len) {
|
|
307 |
String space = "";
|
|
308 |
|
|
309 |
for (int i = 0; i < len; i++) {
|
|
310 |
space += " ";
|
|
311 |
}
|
|
312 |
return space;
|
|
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Print the closing </body> and </html> tags.
|
|
317 |
*/
|
|
318 |
public void printBodyHtmlEnd() {
|
|
319 |
println();
|
|
320 |
bodyEnd();
|
|
321 |
htmlEnd();
|
|
322 |
}
|
|
323 |
|
|
324 |
/**
|
|
325 |
* Calls {@link #printBodyHtmlEnd()} method.
|
|
326 |
*/
|
|
327 |
public void printFooter() {
|
|
328 |
printBodyHtmlEnd();
|
|
329 |
}
|
|
330 |
|
|
331 |
/**
|
|
332 |
* Print closing </html> tag.
|
|
333 |
*/
|
|
334 |
public void printFrameFooter() {
|
|
335 |
htmlEnd();
|
|
336 |
}
|
|
337 |
|
|
338 |
/**
|
|
339 |
* Print ten non-breaking spaces("&nbsp;").
|
|
340 |
*/
|
|
341 |
public void printNbsps() {
|
|
342 |
print(" ");
|
|
343 |
}
|
|
344 |
|
|
345 |
/**
|
|
346 |
* Get the day and date information for today, depending upon user option.
|
|
347 |
*
|
|
348 |
* @return String Today.
|
|
349 |
* @see java.util.Calendar
|
|
350 |
* @see java.util.GregorianCalendar
|
|
351 |
* @see java.util.TimeZone
|
|
352 |
*/
|
|
353 |
public String today() {
|
|
354 |
Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
|
|
355 |
return calendar.getTime().toString();
|
|
356 |
}
|
|
357 |
}
|