001: /*
002: * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html.markup;
027:
028: import com.sun.tools.doclets.internal.toolkit.*;
029:
030: import com.sun.javadoc.*;
031: import java.io.*;
032: import java.util.*;
033: import com.sun.tools.doclets.internal.toolkit.util.*;
034:
035: /**
036: * Class for the Html Format Code Generation specific to JavaDoc.
037: * This Class contains methods related to the Html Code Generation which
038: * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
039: * and com.sun.tools.doclets.oneone.
040: *
041: * @since 1.2
042: * @author Atul M Dambalkar
043: * @author Robert Field
044: */
045: public abstract class HtmlDocWriter extends HtmlWriter {
046:
047: /**
048: * Constructor. Initializes the destination file name through the super
049: * class HtmlWriter.
050: *
051: * @param filename String file name.
052: */
053: public HtmlDocWriter(Configuration configuration, String filename)
054: throws IOException {
055: super (configuration, null,
056: configuration.destDirName + filename,
057: configuration.docencoding);
058: configuration.message.notice("doclet.Generating_0",
059: configuration.destDirName + filename);
060: }
061:
062: public HtmlDocWriter(Configuration configuration, String path,
063: String filename) throws IOException {
064: super (configuration, configuration.destDirName + path,
065: filename, configuration.docencoding);
066: configuration.message.notice("doclet.Generating_0",
067: configuration.destDirName
068: + ((path.length() > 0) ? path + File.separator
069: : "") + filename);
070: }
071:
072: /**
073: * Accessor for configuration.
074: */
075: public abstract Configuration configuration();
076:
077: /**
078: * Print Html Hyper Link.
079: *
080: * @param link String name of the file.
081: * @param where Position of the link in the file. Character '#' is not
082: * needed.
083: * @param label Tag for the link.
084: * @param bold Boolean that sets label to bold.
085: */
086: public void printHyperLink(String link, String where, String label,
087: boolean bold) {
088: print(getHyperLink(link, where, label, bold, "", "", ""));
089: }
090:
091: /**
092: * Print Html Hyper Link.
093: *
094: * @param link String name of the file.
095: * @param where Position of the link in the file. Character '#' is not
096: * needed.
097: * @param label Tag for the link.
098: */
099: public void printHyperLink(String link, String where, String label) {
100: printHyperLink(link, where, label, false);
101: }
102:
103: /**
104: * Print Html Hyper Link.
105: *
106: * @param link String name of the file.
107: * @param where Position of the link in the file. Character '#' is not
108: * needed.
109: * @param label Tag for the link.
110: * @param bold Boolean that sets label to bold.
111: * @param stylename String style of text defined in style sheet.
112: */
113: public void printHyperLink(String link, String where, String label,
114: boolean bold, String stylename) {
115: print(getHyperLink(link, where, label, bold, stylename, "", ""));
116: }
117:
118: /**
119: * Return Html Hyper Link string.
120: *
121: * @param link String name of the file.
122: * @param where Position of the link in the file. Character '#' is not
123: * needed.
124: * @param label Tag for the link.
125: * @param bold Boolean that sets label to bold.
126: * @return String Hyper Link.
127: */
128: public String getHyperLink(String link, String where, String label,
129: boolean bold) {
130: return getHyperLink(link, where, label, bold, "", "", "");
131: }
132:
133: /**
134: * Get Html Hyper Link string.
135: *
136: * @param link String name of the file.
137: * @param where Position of the link in the file. Character '#' is not
138: * needed.
139: * @param label Tag for the link.
140: * @param bold Boolean that sets label to bold.
141: * @param stylename String style of text defined in style sheet.
142: * @return String Hyper Link.
143: */
144: public String getHyperLink(String link, String where, String label,
145: boolean bold, String stylename) {
146: return getHyperLink(link, where, label, bold, stylename, "", "");
147: }
148:
149: /**
150: * Get Html Hyper Link string.
151: *
152: * @param link String name of the file.
153: * @param where Position of the link in the file. Character '#' is not
154: * needed.
155: * @param label Tag for the link.
156: * @param bold Boolean that sets label to bold.
157: * @param stylename String style of text defined in style sheet.
158: * @param title String that describes the link's content for accessibility.
159: * @param target Target frame.
160: * @return String Hyper Link.
161: */
162: public String getHyperLink(String link, String where, String label,
163: boolean bold, String stylename, String title, String target) {
164: StringBuffer retlink = new StringBuffer();
165: retlink.append("<A HREF=\"");
166: retlink.append(link);
167: if (where != null && where.length() != 0) {
168: retlink.append("#");
169: retlink.append(where);
170: }
171: retlink.append("\"");
172: if (title != null && title.length() != 0) {
173: retlink.append(" title=\"" + title + "\"");
174: }
175: if (target != null && target.length() != 0) {
176: retlink.append(" target=\"" + target + "\"");
177: }
178: retlink.append(">");
179: if (stylename != null && stylename.length() != 0) {
180: retlink.append("<FONT CLASS=\"");
181: retlink.append(stylename);
182: retlink.append("\">");
183: }
184: if (bold) {
185: retlink.append("<B>");
186: }
187: retlink.append(label);
188: if (bold) {
189: retlink.append("</B>");
190: }
191: if (stylename != null && stylename.length() != 0) {
192: retlink.append("</FONT>");
193: }
194: retlink.append("</A>");
195: return retlink.toString();
196: }
197:
198: /**
199: * Print link without positioning in the file.
200: *
201: * @param link String name of the file.
202: * @param label Tag for the link.
203: */
204: public void printHyperLink(String link, String label) {
205: print(getHyperLink(link, "", label, false));
206: }
207:
208: /**
209: * Get link string without positioning in the file.
210: *
211: * @param link String name of the file.
212: * @param label Tag for the link.
213: * @return Strign Hyper link.
214: */
215: public String getHyperLink(String link, String label) {
216: return getHyperLink(link, "", label, false);
217: }
218:
219: /**
220: * Print the name of the package, this class is in.
221: *
222: * @param cd ClassDoc.
223: */
224: public void printPkgName(ClassDoc cd) {
225: print(getPkgName(cd));
226: }
227:
228: /**
229: * Get the name of the package, this class is in.
230: *
231: * @param cd ClassDoc.
232: */
233: public String getPkgName(ClassDoc cd) {
234: String pkgName = cd.containingPackage().name();
235: if (pkgName.length() > 0) {
236: pkgName += ".";
237: return pkgName;
238: }
239: return "";
240: }
241:
242: /**
243: * Print the frameset version of the Html file header.
244: * Called only when generating an HTML frameset file.
245: *
246: * @param title Title of this HTML document.
247: */
248: public void printFramesetHeader(String title) {
249: printFramesetHeader(title, false);
250: }
251:
252: /**
253: * Print the frameset version of the Html file header.
254: * Called only when generating an HTML frameset file.
255: *
256: * @param title Title of this HTML document.
257: * @param noTimeStamp If true, don't print time stamp in header.
258: */
259: public void printFramesetHeader(String title, boolean noTimeStamp) {
260: println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 "
261: + "Frameset//EN\" "
262: + "\"http://www.w3.org/TR/html4/frameset.dtd\">");
263: println("<!--NewPage-->");
264: html();
265: head();
266: if (!noTimeStamp) {
267: print("<!-- Generated by javadoc on ");
268: print(today());
269: println("-->");
270: }
271: if (configuration.charset.length() > 0) {
272: println("<META http-equiv=\"Content-Type\" content=\"text/html; "
273: + "charset=" + configuration.charset + "\">");
274: }
275: title();
276: println(title);
277: titleEnd();
278: //Script to set the classFrame if necessary.
279: script();
280: println(" targetPage = \"\" + window.location.search;");
281: println(" if (targetPage != \"\" && targetPage != \"undefined\")");
282: println(" targetPage = targetPage.substring(1);");
283: println(" if (targetPage.indexOf(\":\") != -1)");
284: println(" targetPage = \"undefined\";");
285:
286: println(" function loadFrames() {");
287: println(" if (targetPage != \"\" && targetPage != \"undefined\")");
288: println(" top.classFrame.location = top.targetPage;");
289: println(" }");
290: scriptEnd();
291: noScript();
292: noScriptEnd();
293: headEnd();
294: }
295:
296: /**
297: * Print the appropriate spaces to format the class tree in the class page.
298: *
299: * @param len Number of spaces.
300: */
301: public String spaces(int len) {
302: String space = "";
303:
304: for (int i = 0; i < len; i++) {
305: space += " ";
306: }
307: return space;
308: }
309:
310: /**
311: * Print the closing </body> and </html> tags.
312: */
313: public void printBodyHtmlEnd() {
314: println();
315: bodyEnd();
316: htmlEnd();
317: }
318:
319: /**
320: * Calls {@link #printBodyHtmlEnd()} method.
321: */
322: public void printFooter() {
323: printBodyHtmlEnd();
324: }
325:
326: /**
327: * Print closing </html> tag.
328: */
329: public void printFrameFooter() {
330: htmlEnd();
331: }
332:
333: /**
334: * Print ten non-breaking spaces("&nbsp;").
335: */
336: public void printNbsps() {
337: print(" ");
338: }
339:
340: /**
341: * Get the day and date information for today, depending upon user option.
342: *
343: * @return String Today.
344: * @see java.util.Calendar
345: * @see java.util.GregorianCalendar
346: * @see java.util.TimeZone
347: */
348: public String today() {
349: Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
350: return calendar.getTime().toString();
351: }
352: }
|