src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java

Wed, 04 Sep 2013 14:44:05 -0700

author
jjg
date
Wed, 04 Sep 2013 14:44:05 -0700
changeset 2006
044721d4d359
parent 1981
7fb27bc201cc
child 2101
933ba3f81a87
permissions
-rw-r--r--

8024288: javadoc generated-by comment should always be present
Reviewed-by: bpatel

duke@1 1 /*
jjg@1737 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html.markup;
duke@1 27
jjg@197 28 import java.io.*;
jjg@197 29 import java.util.*;
duke@1 30
duke@1 31 import com.sun.javadoc.*;
jjg@1361 32 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
jjg@197 33 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1412 34 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
jjg@1373 35 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
jjg@1372 36 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
duke@1 37
duke@1 38
duke@1 39 /**
duke@1 40 * Class for the Html Format Code Generation specific to JavaDoc.
duke@1 41 * This Class contains methods related to the Html Code Generation which
duke@1 42 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
duke@1 43 * and com.sun.tools.doclets.oneone.
duke@1 44 *
jjg@1359 45 * <p><b>This is NOT part of any supported API.
jjg@1359 46 * If you write code that depends on this, you do so at your own risk.
jjg@1359 47 * This code and its internal interfaces are subject to change or
jjg@1359 48 * deletion without notice.</b>
jjg@1359 49 *
duke@1 50 * @since 1.2
duke@1 51 * @author Atul M Dambalkar
duke@1 52 * @author Robert Field
duke@1 53 */
duke@1 54 public abstract class HtmlDocWriter extends HtmlWriter {
duke@1 55
bpatel@1981 56 public static final String CONTENT_TYPE = "text/html";
bpatel@1981 57
duke@1 58 /**
duke@1 59 * Constructor. Initializes the destination file name through the super
duke@1 60 * class HtmlWriter.
duke@1 61 *
duke@1 62 * @param filename String file name.
duke@1 63 */
jjg@1372 64 public HtmlDocWriter(Configuration configuration, DocPath filename)
jjg@1372 65 throws IOException {
jjg@1372 66 super(configuration, filename);
duke@1 67 configuration.message.notice("doclet.Generating_0",
jjg@1412 68 DocFile.createFileForOutput(configuration, filename).getPath());
duke@1 69 }
duke@1 70
duke@1 71 /**
duke@1 72 * Accessor for configuration.
duke@1 73 */
duke@1 74 public abstract Configuration configuration();
duke@1 75
jjg@1740 76 public Content getHyperLink(DocPath link, String label) {
jjg@1740 77 return getHyperLink(link, new StringContent(label), false, "", "", "");
jjg@1740 78 }
jjg@1740 79
duke@1 80 /**
duke@1 81 * Get Html Hyper Link string.
duke@1 82 *
jjg@1372 83 * @param where Position of the link in the file. Character '#' is not
jjg@1372 84 * needed.
jjg@1372 85 * @param label Tag for the link.
jjg@1372 86 * @return a content tree for the hyper link
jjg@1372 87 */
jjg@1372 88 public Content getHyperLink(String where,
jjg@1372 89 Content label) {
jjg@1373 90 return getHyperLink(DocLink.fragment(where), label, "", "");
jjg@1372 91 }
jjg@1372 92
jjg@1372 93 /**
jjg@1737 94 * Get Html hyperlink.
jjg@1372 95 *
jjg@1737 96 * @param link path of the file.
bpatel@766 97 * @param label Tag for the link.
bpatel@766 98 * @return a content tree for the hyper link
bpatel@766 99 */
jjg@1737 100 public Content getHyperLink(DocPath link, Content label) {
jjg@1373 101 return getHyperLink(link, label, "", "");
jjg@1373 102 }
jjg@1373 103
jjg@1737 104 public Content getHyperLink(DocLink link, Content label) {
jjg@1373 105 return getHyperLink(link, label, "", "");
duke@1 106 }
duke@1 107
jjg@1740 108 public Content getHyperLink(DocPath link,
jjg@1740 109 Content label, boolean strong,
jjg@1740 110 String stylename, String title, String target) {
jjg@1740 111 return getHyperLink(new DocLink(link), label, strong,
jjg@1740 112 stylename, title, target);
jjg@1740 113 }
jjg@1740 114
jjg@1737 115 public Content getHyperLink(DocLink link,
jjg@1737 116 Content label, boolean strong,
jjg@1737 117 String stylename, String title, String target) {
jjg@1737 118 Content body = label;
jjg@1737 119 if (strong) {
jjg@1737 120 body = HtmlTree.SPAN(HtmlStyle.strong, body);
jjg@1737 121 }
jjg@1737 122 if (stylename != null && stylename.length() != 0) {
jjg@1737 123 HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
jjg@1737 124 t.addAttr(HtmlAttr.CLASS, stylename);
jjg@1737 125 body = t;
jjg@1737 126 }
jjg@1737 127 HtmlTree l = HtmlTree.A(link.toString(), body);
jjg@1737 128 if (title != null && title.length() != 0) {
jjg@1737 129 l.addAttr(HtmlAttr.TITLE, title);
jjg@1737 130 }
jjg@1737 131 if (target != null && target.length() != 0) {
jjg@1737 132 l.addAttr(HtmlAttr.TARGET, target);
jjg@1737 133 }
jjg@1737 134 return l;
jjg@1737 135 }
jjg@1737 136
duke@1 137 /**
bpatel@766 138 * Get Html Hyper Link.
duke@1 139 *
duke@1 140 * @param link String name of the file.
duke@1 141 * @param label Tag for the link.
bpatel@766 142 * @param title String that describes the link's content for accessibility.
bpatel@766 143 * @param target Target frame.
bpatel@766 144 * @return a content tree for the hyper link.
duke@1 145 */
jjg@1373 146 public Content getHyperLink(DocPath link,
jjg@1372 147 Content label, String title, String target) {
jjg@1373 148 return getHyperLink(new DocLink(link), label, title, target);
jjg@1372 149 }
jjg@1373 150
jjg@1373 151 public Content getHyperLink(DocLink link,
bpatel@766 152 Content label, String title, String target) {
jjg@1373 153 HtmlTree anchor = HtmlTree.A(link.toString(), label);
bpatel@766 154 if (title != null && title.length() != 0) {
bpatel@766 155 anchor.addAttr(HtmlAttr.TITLE, title);
bpatel@766 156 }
bpatel@766 157 if (target != null && target.length() != 0) {
bpatel@766 158 anchor.addAttr(HtmlAttr.TARGET, target);
bpatel@766 159 }
bpatel@766 160 return anchor;
bpatel@766 161 }
bpatel@766 162
bpatel@766 163 /**
duke@1 164 * Get the name of the package, this class is in.
duke@1 165 *
duke@1 166 * @param cd ClassDoc.
duke@1 167 */
duke@1 168 public String getPkgName(ClassDoc cd) {
duke@1 169 String pkgName = cd.containingPackage().name();
duke@1 170 if (pkgName.length() > 0) {
duke@1 171 pkgName += ".";
duke@1 172 return pkgName;
duke@1 173 }
duke@1 174 return "";
duke@1 175 }
duke@1 176
bpatel@233 177 public boolean getMemberDetailsListPrinted() {
bpatel@233 178 return memberDetailsListPrinted;
bpatel@233 179 }
bpatel@233 180
bpatel@233 181 /**
duke@1 182 * Print the frameset version of the Html file header.
duke@1 183 * Called only when generating an HTML frameset file.
duke@1 184 *
bpatel@766 185 * @param title Title of this HTML document
bpatel@766 186 * @param noTimeStamp If true, don't print time stamp in header
bpatel@766 187 * @param frameset the frameset to be added to the HTML document
duke@1 188 */
bpatel@766 189 public void printFramesetDocument(String title, boolean noTimeStamp,
jjg@1364 190 Content frameset) throws IOException {
jjg@1410 191 Content htmlDocType = DocType.FRAMESET;
bpatel@766 192 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 193 Content head = new HtmlTree(HtmlTag.HEAD);
jjg@2006 194 head.addContent(getGeneratedBy(!noTimeStamp));
duke@1 195 if (configuration.charset.length() > 0) {
bpatel@1981 196 Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
bpatel@766 197 configuration.charset);
bpatel@766 198 head.addContent(meta);
duke@1 199 }
bpatel@766 200 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
bpatel@766 201 head.addContent(windowTitle);
bpatel@766 202 head.addContent(getFramesetJavaScript());
bpatel@766 203 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 204 head, frameset);
bpatel@766 205 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 206 htmlComment, htmlTree);
jjg@1365 207 write(htmlDocument);
duke@1 208 }
duke@1 209
jjg@2006 210 protected Comment getGeneratedBy(boolean timestamp) {
jjg@2006 211 String text = "Generated by javadoc"; // marker string, deliberately not localized
jjg@2006 212 if (timestamp) {
jjg@2006 213 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
jjg@2006 214 Date today = calendar.getTime();
jjg@2006 215 text += " ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
jjg@2006 216 }
jjg@2006 217 return new Comment(text);
duke@1 218 }
duke@1 219 }

mercurial