duke@1: /* jjg@1737: * Copyright (c) 1997, 2013, 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@1361: import com.sun.tools.doclets.formats.html.ConfigurationImpl; jjg@197: import com.sun.tools.doclets.internal.toolkit.*; jjg@1412: import com.sun.tools.doclets.internal.toolkit.util.DocFile; jjg@1373: import com.sun.tools.doclets.internal.toolkit.util.DocLink; jjg@1372: import com.sun.tools.doclets.internal.toolkit.util.DocPath; 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: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * 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: */ jjg@1372: public HtmlDocWriter(Configuration configuration, DocPath filename) jjg@1372: throws IOException { jjg@1372: super(configuration, filename); duke@1: configuration.message.notice("doclet.Generating_0", jjg@1412: DocFile.createFileForOutput(configuration, filename).getPath()); duke@1: } duke@1: duke@1: /** duke@1: * Accessor for configuration. duke@1: */ duke@1: public abstract Configuration configuration(); duke@1: duke@1: /** jjg@1737: * Return Html hyperlink string. duke@1: * duke@1: * @param link String name of the file. duke@1: * @param label Tag for the link. duke@1: * @return String Hyper Link. duke@1: */ jjg@1737: public String getHyperLinkString(DocPath link, String label) { jjg@1737: return getHyperLinkString(link, label, false, "", "", ""); jjg@1373: } jjg@1373: jjg@1740: public Content getHyperLink(DocPath link, String label) { jjg@1740: return getHyperLink(link, new StringContent(label), false, "", "", ""); jjg@1740: } jjg@1740: jjg@1737: public String getHyperLinkString(DocLink link, String label) { jjg@1737: return getHyperLinkString(link, label, false, "", "", ""); 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 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: */ jjg@1373: public String getHyperLinkString(DocPath link, bpatel@182: String label, boolean strong, duke@1: String stylename) { jjg@1373: return getHyperLinkString(link, label, strong, stylename, "", ""); jjg@1373: } jjg@1373: jjg@1373: public String getHyperLinkString(DocLink link, jjg@1373: String label, boolean strong, jjg@1373: String stylename) { jjg@1373: return getHyperLinkString(link, label, strong, stylename, "", ""); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get Html Hyper Link string. bpatel@766: * jjg@1372: * @param where Position of the link in the file. Character '#' is not jjg@1372: * needed. jjg@1372: * @param label Tag for the link. jjg@1372: * @return a content tree for the hyper link jjg@1372: */ jjg@1372: public Content getHyperLink(String where, jjg@1372: Content label) { jjg@1373: return getHyperLink(DocLink.fragment(where), label, "", ""); jjg@1372: } jjg@1372: jjg@1372: /** jjg@1737: * Get Html hyperlink. jjg@1372: * jjg@1737: * @param link path of the file. bpatel@766: * @param label Tag for the link. bpatel@766: * @return a content tree for the hyper link bpatel@766: */ jjg@1737: public Content getHyperLink(DocPath link, Content label) { jjg@1373: return getHyperLink(link, label, "", ""); jjg@1373: } jjg@1373: jjg@1737: public Content getHyperLink(DocLink link, Content label) { jjg@1373: return getHyperLink(link, 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 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. jjg@1373: * @param title String that describes the links content for accessibility. duke@1: * @param target Target frame. duke@1: * @return String Hyper Link. duke@1: */ jjg@1373: public String getHyperLinkString(DocPath link, jjg@1372: String label, boolean strong, jjg@1372: String stylename, String title, String target) { jjg@1373: return getHyperLinkString(new DocLink(link), label, strong, jjg@1372: stylename, title, target); jjg@1372: } jjg@1372: jjg@1373: public String getHyperLinkString(DocLink link, bpatel@182: String label, boolean strong, duke@1: String stylename, String title, String target) { jjg@1362: StringBuilder retlink = new StringBuilder(); jjg@1373: 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: jjg@1740: public Content getHyperLink(DocPath link, jjg@1740: Content label, boolean strong, jjg@1740: String stylename, String title, String target) { jjg@1740: return getHyperLink(new DocLink(link), label, strong, jjg@1740: stylename, title, target); jjg@1740: } jjg@1740: jjg@1737: public Content getHyperLink(DocLink link, jjg@1737: Content label, boolean strong, jjg@1737: String stylename, String title, String target) { jjg@1737: Content body = label; jjg@1737: if (strong) { jjg@1737: body = HtmlTree.SPAN(HtmlStyle.strong, body); jjg@1737: } jjg@1737: if (stylename != null && stylename.length() != 0) { jjg@1737: HtmlTree t = new HtmlTree(HtmlTag.FONT, body); jjg@1737: t.addAttr(HtmlAttr.CLASS, stylename); jjg@1737: body = t; jjg@1737: } jjg@1737: HtmlTree l = HtmlTree.A(link.toString(), body); jjg@1737: if (title != null && title.length() != 0) { jjg@1737: l.addAttr(HtmlAttr.TITLE, title); jjg@1737: } jjg@1737: if (target != null && target.length() != 0) { jjg@1737: l.addAttr(HtmlAttr.TARGET, target); jjg@1737: } jjg@1737: return l; jjg@1737: } jjg@1737: duke@1: /** bpatel@766: * Get Html Hyper Link. duke@1: * duke@1: * @param link String name of the file. 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: */ jjg@1373: public Content getHyperLink(DocPath link, jjg@1372: Content label, String title, String target) { jjg@1373: return getHyperLink(new DocLink(link), label, title, target); jjg@1372: } jjg@1373: jjg@1373: public Content getHyperLink(DocLink link, bpatel@766: Content label, String title, String target) { jjg@1373: HtmlTree anchor = HtmlTree.A(link.toString(), 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: /** 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: 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, jjg@1364: Content frameset) throws IOException { jjg@1410: 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) { jjg@1361: Content headComment = new Comment(getGeneratedByString()); 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); jjg@1365: write(htmlDocument); duke@1: } duke@1: jjg@1361: protected String getGeneratedByString() { duke@1: Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); jjg@1361: Date today = calendar.getTime(); jjg@1361: return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today; duke@1: } duke@1: }