duke@1: /* ohair@554: * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html.markup; duke@1: jjg@197: import java.io.*; jjg@197: import java.util.*; duke@1: duke@1: import com.sun.javadoc.*; jjg@197: import com.sun.tools.doclets.internal.toolkit.*; duke@1: duke@1: duke@1: /** duke@1: * Class for the Html Format Code Generation specific to JavaDoc. duke@1: * This Class contains methods related to the Html Code Generation which duke@1: * are used by the Sub-Classes in the package com.sun.tools.doclets.standard duke@1: * and com.sun.tools.doclets.oneone. duke@1: * duke@1: * @since 1.2 duke@1: * @author Atul M Dambalkar duke@1: * @author Robert Field duke@1: */ duke@1: public abstract class HtmlDocWriter extends HtmlWriter { duke@1: duke@1: /** duke@1: * Constructor. Initializes the destination file name through the super duke@1: * class HtmlWriter. duke@1: * duke@1: * @param filename String file name. duke@1: */ duke@1: public HtmlDocWriter(Configuration configuration, duke@1: String filename) throws IOException { duke@1: super(configuration, duke@1: null, configuration.destDirName + filename, duke@1: configuration.docencoding); jjg@197: // use File to normalize file separators duke@1: configuration.message.notice("doclet.Generating_0", jjg@197: new File(configuration.destDirName, filename)); duke@1: } duke@1: duke@1: public HtmlDocWriter(Configuration configuration, duke@1: String path, String filename) throws IOException { duke@1: super(configuration, duke@1: configuration.destDirName + path, filename, duke@1: configuration.docencoding); jjg@197: // use File to normalize file separators duke@1: configuration.message.notice("doclet.Generating_0", jjg@197: new File(configuration.destDirName, jjg@197: ((path.length() > 0)? path + File.separator: "") + filename)); duke@1: } duke@1: duke@1: /** duke@1: * Accessor for configuration. duke@1: */ duke@1: public abstract Configuration configuration(); duke@1: duke@1: /** duke@1: * Print Html Hyper Link. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. bpatel@182: * @param strong Boolean that sets label to strong. duke@1: */ duke@1: public void printHyperLink(String link, String where, bpatel@182: String label, boolean strong) { bpatel@766: print(getHyperLinkString(link, where, label, strong, "", "", "")); duke@1: } duke@1: duke@1: /** duke@1: * Print Html Hyper Link. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. duke@1: */ duke@1: public void printHyperLink(String link, String where, String label) { duke@1: printHyperLink(link, where, label, false); duke@1: } duke@1: duke@1: /** duke@1: * Print Html Hyper Link. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. bpatel@182: * @param strong Boolean that sets label to strong. duke@1: * @param stylename String style of text defined in style sheet. duke@1: */ duke@1: public void printHyperLink(String link, String where, bpatel@182: String label, boolean strong, duke@1: String stylename) { bpatel@766: print(getHyperLinkString(link, where, label, strong, stylename, "", "")); duke@1: } duke@1: duke@1: /** duke@1: * Return Html Hyper Link string. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. bpatel@182: * @param strong Boolean that sets label to strong. duke@1: * @return String Hyper Link. duke@1: */ bpatel@766: public String getHyperLinkString(String link, String where, bpatel@182: String label, boolean strong) { bpatel@766: return getHyperLinkString(link, where, label, strong, "", "", ""); duke@1: } duke@1: duke@1: /** duke@1: * Get Html Hyper Link string. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. bpatel@182: * @param strong Boolean that sets label to strong. duke@1: * @param stylename String style of text defined in style sheet. duke@1: * @return String Hyper Link. duke@1: */ bpatel@766: public String getHyperLinkString(String link, String where, bpatel@182: String label, boolean strong, duke@1: String stylename) { bpatel@766: return getHyperLinkString(link, where, label, strong, stylename, "", ""); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get Html Hyper Link string. bpatel@766: * bpatel@766: * @param link String name of the file. bpatel@766: * @param where Position of the link in the file. Character '#' is not bpatel@766: * needed. bpatel@766: * @param label Tag for the link. bpatel@766: * @return a content tree for the hyper link bpatel@766: */ bpatel@766: public Content getHyperLink(String link, String where, bpatel@766: Content label) { bpatel@766: return getHyperLink(link, where, label, "", ""); duke@1: } duke@1: duke@1: /** duke@1: * Get Html Hyper Link string. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param where Position of the link in the file. Character '#' is not duke@1: * needed. duke@1: * @param label Tag for the link. bpatel@182: * @param strong Boolean that sets label to strong. duke@1: * @param stylename String style of text defined in style sheet. duke@1: * @param title String that describes the link's content for accessibility. duke@1: * @param target Target frame. duke@1: * @return String Hyper Link. duke@1: */ bpatel@766: public String getHyperLinkString(String link, String where, bpatel@182: String label, boolean strong, duke@1: String stylename, String title, String target) { duke@1: StringBuffer retlink = new StringBuffer(); bpatel@766: retlink.append(""); duke@1: if (stylename != null && stylename.length() != 0) { duke@1: retlink.append(""); duke@1: } bpatel@182: if (strong) { bpatel@766: retlink.append(""); duke@1: } duke@1: retlink.append(label); bpatel@182: if (strong) { bpatel@766: retlink.append(""); duke@1: } duke@1: if (stylename != null && stylename.length() != 0) { duke@1: retlink.append(""); duke@1: } bpatel@766: retlink.append(""); duke@1: return retlink.toString(); duke@1: } duke@1: duke@1: /** bpatel@766: * Get Html Hyper Link. duke@1: * duke@1: * @param link String name of the file. bpatel@766: * @param where Position of the link in the file. Character '#' is not bpatel@766: * needed. duke@1: * @param label Tag for the link. bpatel@766: * @param title String that describes the link's content for accessibility. bpatel@766: * @param target Target frame. bpatel@766: * @return a content tree for the hyper link. duke@1: */ bpatel@766: public Content getHyperLink(String link, String where, bpatel@766: Content label, String title, String target) { bpatel@766: if (where != null && where.length() != 0) { bpatel@766: link += "#" + where; bpatel@766: } bpatel@766: HtmlTree anchor = HtmlTree.A(link, label); bpatel@766: if (title != null && title.length() != 0) { bpatel@766: anchor.addAttr(HtmlAttr.TITLE, title); bpatel@766: } bpatel@766: if (target != null && target.length() != 0) { bpatel@766: anchor.addAttr(HtmlAttr.TARGET, target); bpatel@766: } bpatel@766: return anchor; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get a hyperlink to a file. bpatel@766: * bpatel@766: * @param link String name of the file bpatel@766: * @param label Label for the link bpatel@766: * @return a content for the hyperlink to the file bpatel@766: */ bpatel@766: public Content getHyperLink(String link, Content label) { bpatel@766: return getHyperLink(link, "", label); duke@1: } duke@1: duke@1: /** duke@1: * Get link string without positioning in the file. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param label Tag for the link. duke@1: * @return Strign Hyper link. duke@1: */ bpatel@766: public String getHyperLinkString(String link, String label) { bpatel@766: return getHyperLinkString(link, "", label, false); duke@1: } duke@1: duke@1: /** duke@1: * Print the name of the package, this class is in. duke@1: * duke@1: * @param cd ClassDoc. duke@1: */ duke@1: public void printPkgName(ClassDoc cd) { duke@1: print(getPkgName(cd)); duke@1: } duke@1: duke@1: /** duke@1: * Get the name of the package, this class is in. duke@1: * duke@1: * @param cd ClassDoc. duke@1: */ duke@1: public String getPkgName(ClassDoc cd) { duke@1: String pkgName = cd.containingPackage().name(); duke@1: if (pkgName.length() > 0) { duke@1: pkgName += "."; duke@1: return pkgName; duke@1: } duke@1: return ""; duke@1: } duke@1: duke@1: /** bpatel@233: * Keep track of member details list. Print the definition list start tag bpatel@233: * if it is not printed yet. bpatel@233: */ bpatel@233: public void printMemberDetailsListStartTag () { bpatel@233: if (!getMemberDetailsListPrinted()) { bpatel@233: dl(); bpatel@233: memberDetailsListPrinted = true; bpatel@233: } bpatel@233: } bpatel@233: bpatel@233: /** bpatel@233: * Print the definition list end tag if the list start tag was printed. bpatel@233: */ bpatel@233: public void printMemberDetailsListEndTag () { bpatel@233: if (getMemberDetailsListPrinted()) { bpatel@233: dlEnd(); bpatel@233: memberDetailsListPrinted = false; bpatel@233: } bpatel@233: } bpatel@233: bpatel@233: public boolean getMemberDetailsListPrinted() { bpatel@233: return memberDetailsListPrinted; bpatel@233: } bpatel@233: bpatel@233: /** duke@1: * Print the frameset version of the Html file header. duke@1: * Called only when generating an HTML frameset file. duke@1: * bpatel@766: * @param title Title of this HTML document bpatel@766: * @param noTimeStamp If true, don't print time stamp in header bpatel@766: * @param frameset the frameset to be added to the HTML document duke@1: */ bpatel@766: public void printFramesetDocument(String title, boolean noTimeStamp, bpatel@766: Content frameset) { bpatel@766: Content htmlDocType = DocType.Frameset(); bpatel@766: Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); bpatel@766: Content head = new HtmlTree(HtmlTag.HEAD); duke@1: if (! noTimeStamp) { bpatel@766: Content headComment = new Comment("Generated by javadoc on " + today()); bpatel@766: head.addContent(headComment); duke@1: } duke@1: if (configuration.charset.length() > 0) { bpatel@766: Content meta = HtmlTree.META("Content-Type", "text/html", bpatel@766: configuration.charset); bpatel@766: head.addContent(meta); duke@1: } bpatel@766: Content windowTitle = HtmlTree.TITLE(new StringContent(title)); bpatel@766: head.addContent(windowTitle); bpatel@766: head.addContent(getFramesetJavaScript()); bpatel@766: Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), bpatel@766: head, frameset); bpatel@766: Content htmlDocument = new HtmlDocument(htmlDocType, bpatel@766: htmlComment, htmlTree); bpatel@766: print(htmlDocument.toString()); duke@1: } duke@1: duke@1: /** duke@1: * Print the appropriate spaces to format the class tree in the class page. duke@1: * duke@1: * @param len Number of spaces. duke@1: */ duke@1: public String spaces(int len) { duke@1: String space = ""; duke@1: duke@1: for (int i = 0; i < len; i++) { duke@1: space += " "; duke@1: } duke@1: return space; duke@1: } duke@1: duke@1: /** duke@1: * Print the closing </body> and </html> tags. duke@1: */ duke@1: public void printBodyHtmlEnd() { duke@1: println(); duke@1: bodyEnd(); duke@1: htmlEnd(); duke@1: } duke@1: duke@1: /** duke@1: * Calls {@link #printBodyHtmlEnd()} method. duke@1: */ duke@1: public void printFooter() { duke@1: printBodyHtmlEnd(); duke@1: } duke@1: duke@1: /** duke@1: * Print closing </html> tag. duke@1: */ duke@1: public void printFrameFooter() { duke@1: htmlEnd(); duke@1: } duke@1: duke@1: /** duke@1: * Print ten non-breaking spaces("&nbsp;"). duke@1: */ duke@1: public void printNbsps() { duke@1: print("          "); duke@1: } duke@1: duke@1: /** duke@1: * Get the day and date information for today, depending upon user option. duke@1: * duke@1: * @return String Today. duke@1: * @see java.util.Calendar duke@1: * @see java.util.GregorianCalendar duke@1: * @see java.util.TimeZone duke@1: */ duke@1: public String today() { duke@1: Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); duke@1: return calendar.getTime().toString(); duke@1: } duke@1: }