Mon, 09 Mar 2009 23:53:41 -0700
Merge
1 /*
2 * Copyright 1997-2009 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 */
26 package com.sun.tools.doclets.formats.html.markup;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
35 /**
36 * Class for the Html Format Code Generation specific to JavaDoc.
37 * This Class contains methods related to the Html Code Generation which
38 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
39 * and com.sun.tools.doclets.oneone.
40 *
41 * @since 1.2
42 * @author Atul M Dambalkar
43 * @author Robert Field
44 */
45 public abstract class HtmlDocWriter extends HtmlWriter {
47 /**
48 * Constructor. Initializes the destination file name through the super
49 * class HtmlWriter.
50 *
51 * @param filename String file name.
52 */
53 public HtmlDocWriter(Configuration configuration,
54 String filename) throws IOException {
55 super(configuration,
56 null, configuration.destDirName + filename,
57 configuration.docencoding);
58 // use File to normalize file separators
59 configuration.message.notice("doclet.Generating_0",
60 new File(configuration.destDirName, filename));
61 }
63 public HtmlDocWriter(Configuration configuration,
64 String path, String filename) throws IOException {
65 super(configuration,
66 configuration.destDirName + path, filename,
67 configuration.docencoding);
68 // use File to normalize file separators
69 configuration.message.notice("doclet.Generating_0",
70 new File(configuration.destDirName,
71 ((path.length() > 0)? path + File.separator: "") + filename));
72 }
74 /**
75 * Accessor for configuration.
76 */
77 public abstract Configuration configuration();
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 strong Boolean that sets label to strong.
87 */
88 public void printHyperLink(String link, String where,
89 String label, boolean strong) {
90 print(getHyperLink(link, where, label, strong, "", "", ""));
91 }
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 }
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 strong Boolean that sets label to strong.
113 * @param stylename String style of text defined in style sheet.
114 */
115 public void printHyperLink(String link, String where,
116 String label, boolean strong,
117 String stylename) {
118 print(getHyperLink(link, where, label, strong, stylename, "", ""));
119 }
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 strong Boolean that sets label to strong.
129 * @return String Hyper Link.
130 */
131 public String getHyperLink(String link, String where,
132 String label, boolean strong) {
133 return getHyperLink(link, where, label, strong, "", "", "");
134 }
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 strong Boolean that sets label to strong.
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 strong,
149 String stylename) {
150 return getHyperLink(link, where, label, strong, stylename, "", "");
151 }
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 strong Boolean that sets label to strong.
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 strong,
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 (strong) {
190 retlink.append("<STRONG>");
191 }
192 retlink.append(label);
193 if (strong) {
194 retlink.append("</STRONG>");
195 }
196 if (stylename != null && stylename.length() != 0) {
197 retlink.append("</FONT>");
198 }
199 retlink.append("</A>");
200 return retlink.toString();
201 }
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 }
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 }
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 }
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 }
247 /**
248 * Keep track of member details list. Print the definition list start tag
249 * if it is not printed yet.
250 */
251 public void printMemberDetailsListStartTag () {
252 if (!getMemberDetailsListPrinted()) {
253 dl();
254 memberDetailsListPrinted = true;
255 }
256 }
258 /**
259 * Print the definition list end tag if the list start tag was printed.
260 */
261 public void printMemberDetailsListEndTag () {
262 if (getMemberDetailsListPrinted()) {
263 dlEnd();
264 memberDetailsListPrinted = false;
265 }
266 }
268 public boolean getMemberDetailsListPrinted() {
269 return memberDetailsListPrinted;
270 }
272 /**
273 * Print the frameset version of the Html file header.
274 * Called only when generating an HTML frameset file.
275 *
276 * @param title Title of this HTML document.
277 */
278 public void printFramesetHeader(String title) {
279 printFramesetHeader(title, false);
280 }
282 /**
283 * Print the frameset version of the Html file header.
284 * Called only when generating an HTML frameset file.
285 *
286 * @param title Title of this HTML document.
287 * @param noTimeStamp If true, don't print time stamp in header.
288 */
289 public void printFramesetHeader(String title, boolean noTimeStamp) {
290 println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
291 "Frameset//EN\" " +
292 "\"http://www.w3.org/TR/html4/frameset.dtd\">");
293 println("<!--NewPage-->");
294 html();
295 head();
296 if (! noTimeStamp) {
297 print("<!-- Generated by javadoc on ");
298 print(today());
299 println("-->");
300 }
301 if (configuration.charset.length() > 0) {
302 println("<META http-equiv=\"Content-Type\" content=\"text/html; "
303 + "charset=" + configuration.charset + "\">");
304 }
305 title();
306 println(title);
307 titleEnd();
308 //Script to set the classFrame if necessary.
309 script();
310 println(" targetPage = \"\" + window.location.search;");
311 println(" if (targetPage != \"\" && targetPage != \"undefined\")");
312 println(" targetPage = targetPage.substring(1);");
313 println(" if (targetPage.indexOf(\":\") != -1)");
314 println(" targetPage = \"undefined\";");
316 println(" function loadFrames() {");
317 println(" if (targetPage != \"\" && targetPage != \"undefined\")");
318 println(" top.classFrame.location = top.targetPage;");
319 println(" }");
320 scriptEnd();
321 noScript();
322 noScriptEnd();
323 headEnd();
324 }
326 /**
327 * Print the appropriate spaces to format the class tree in the class page.
328 *
329 * @param len Number of spaces.
330 */
331 public String spaces(int len) {
332 String space = "";
334 for (int i = 0; i < len; i++) {
335 space += " ";
336 }
337 return space;
338 }
340 /**
341 * Print the closing </body> and </html> tags.
342 */
343 public void printBodyHtmlEnd() {
344 println();
345 bodyEnd();
346 htmlEnd();
347 }
349 /**
350 * Calls {@link #printBodyHtmlEnd()} method.
351 */
352 public void printFooter() {
353 printBodyHtmlEnd();
354 }
356 /**
357 * Print closing </html> tag.
358 */
359 public void printFrameFooter() {
360 htmlEnd();
361 }
363 /**
364 * Print ten non-breaking spaces("&nbsp;").
365 */
366 public void printNbsps() {
367 print(" ");
368 }
370 /**
371 * Get the day and date information for today, depending upon user option.
372 *
373 * @return String Today.
374 * @see java.util.Calendar
375 * @see java.util.GregorianCalendar
376 * @see java.util.TimeZone
377 */
378 public String today() {
379 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
380 return calendar.getTime().toString();
381 }
382 }