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

Tue, 30 Oct 2012 10:15:19 -0700

author
jjg
date
Tue, 30 Oct 2012 10:15:19 -0700
changeset 1381
23fe1a96bc0f
parent 1373
4a1c57a1c410
child 1410
bfec2a1cc869
permissions
-rw-r--r--

8001929: fix doclint errors in langtools doc comments
Reviewed-by: darcy

duke@1 1 /*
jjg@1359 2 * Copyright (c) 1997, 2012, 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@1373 34 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
jjg@1372 35 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
jjg@1372 36 import com.sun.tools.doclets.internal.toolkit.util.DocPaths;
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
duke@1 56 /**
duke@1 57 * Constructor. Initializes the destination file name through the super
duke@1 58 * class HtmlWriter.
duke@1 59 *
duke@1 60 * @param filename String file name.
duke@1 61 */
jjg@1372 62 public HtmlDocWriter(Configuration configuration, DocPath filename)
jjg@1372 63 throws IOException {
jjg@1372 64 super(configuration, filename);
duke@1 65 configuration.message.notice("doclet.Generating_0",
jjg@1372 66 filename.resolveAgainst(configuration.destDirName));
duke@1 67 }
duke@1 68
duke@1 69 /**
duke@1 70 * Accessor for configuration.
duke@1 71 */
duke@1 72 public abstract Configuration configuration();
duke@1 73
duke@1 74 /**
duke@1 75 * Return Html Hyper Link string.
duke@1 76 *
duke@1 77 * @param link String name of the file.
duke@1 78 * @param label Tag for the link.
bpatel@182 79 * @param strong Boolean that sets label to strong.
duke@1 80 * @return String Hyper Link.
duke@1 81 */
jjg@1373 82 public String getHyperLinkString(DocPath link,
bpatel@182 83 String label, boolean strong) {
jjg@1373 84 return getHyperLinkString(link, label, strong, "", "", "");
jjg@1373 85 }
jjg@1373 86
jjg@1373 87 public String getHyperLinkString(DocLink link,
jjg@1373 88 String label, boolean strong) {
jjg@1373 89 return getHyperLinkString(link, label, strong, "", "", "");
duke@1 90 }
duke@1 91
duke@1 92 /**
duke@1 93 * Get Html Hyper Link string.
duke@1 94 *
duke@1 95 * @param link String name of the file.
duke@1 96 * @param label Tag for the link.
bpatel@182 97 * @param strong Boolean that sets label to strong.
duke@1 98 * @param stylename String style of text defined in style sheet.
duke@1 99 * @return String Hyper Link.
duke@1 100 */
jjg@1373 101 public String getHyperLinkString(DocPath link,
bpatel@182 102 String label, boolean strong,
duke@1 103 String stylename) {
jjg@1373 104 return getHyperLinkString(link, label, strong, stylename, "", "");
jjg@1373 105 }
jjg@1373 106
jjg@1373 107 public String getHyperLinkString(DocLink link,
jjg@1373 108 String label, boolean strong,
jjg@1373 109 String stylename) {
jjg@1373 110 return getHyperLinkString(link, label, strong, stylename, "", "");
bpatel@766 111 }
bpatel@766 112
bpatel@766 113 /**
bpatel@766 114 * Get Html Hyper Link string.
bpatel@766 115 *
jjg@1372 116 * @param where Position of the link in the file. Character '#' is not
jjg@1372 117 * needed.
jjg@1372 118 * @param label Tag for the link.
jjg@1372 119 * @return a content tree for the hyper link
jjg@1372 120 */
jjg@1372 121 public Content getHyperLink(String where,
jjg@1372 122 Content label) {
jjg@1373 123 return getHyperLink(DocLink.fragment(where), label, "", "");
jjg@1372 124 }
jjg@1372 125
jjg@1372 126 /**
jjg@1372 127 * Get Html Hyper Link string.
jjg@1372 128 *
bpatel@766 129 * @param link String name of the file.
bpatel@766 130 * @param label Tag for the link.
bpatel@766 131 * @return a content tree for the hyper link
bpatel@766 132 */
jjg@1373 133 public Content getHyperLink(DocPath link,
bpatel@766 134 Content label) {
jjg@1373 135 return getHyperLink(link, label, "", "");
jjg@1373 136 }
jjg@1373 137
jjg@1373 138 public Content getHyperLink(DocLink link,
jjg@1373 139 Content label) {
jjg@1373 140 return getHyperLink(link, label, "", "");
duke@1 141 }
duke@1 142
duke@1 143 /**
duke@1 144 * Get Html Hyper Link string.
duke@1 145 *
duke@1 146 * @param link String name of the file.
duke@1 147 * @param label Tag for the link.
bpatel@182 148 * @param strong Boolean that sets label to strong.
duke@1 149 * @param stylename String style of text defined in style sheet.
jjg@1373 150 * @param title String that describes the links content for accessibility.
duke@1 151 * @param target Target frame.
duke@1 152 * @return String Hyper Link.
duke@1 153 */
jjg@1373 154 public String getHyperLinkString(DocPath link,
jjg@1372 155 String label, boolean strong,
jjg@1372 156 String stylename, String title, String target) {
jjg@1373 157 return getHyperLinkString(new DocLink(link), label, strong,
jjg@1372 158 stylename, title, target);
jjg@1372 159 }
jjg@1372 160
jjg@1373 161 public String getHyperLinkString(DocLink link,
bpatel@182 162 String label, boolean strong,
duke@1 163 String stylename, String title, String target) {
jjg@1362 164 StringBuilder retlink = new StringBuilder();
jjg@1373 165 retlink.append("<a href=\"").append(link).append('"');
duke@1 166 if (title != null && title.length() != 0) {
jjg@1373 167 retlink.append(" title=\"").append(title).append('"');
duke@1 168 }
duke@1 169 if (target != null && target.length() != 0) {
jjg@1373 170 retlink.append(" target=\"").append(target).append('"');
duke@1 171 }
duke@1 172 retlink.append(">");
duke@1 173 if (stylename != null && stylename.length() != 0) {
duke@1 174 retlink.append("<FONT CLASS=\"");
duke@1 175 retlink.append(stylename);
duke@1 176 retlink.append("\">");
duke@1 177 }
bpatel@182 178 if (strong) {
bpatel@766 179 retlink.append("<span class=\"strong\">");
duke@1 180 }
duke@1 181 retlink.append(label);
bpatel@182 182 if (strong) {
bpatel@766 183 retlink.append("</span>");
duke@1 184 }
duke@1 185 if (stylename != null && stylename.length() != 0) {
duke@1 186 retlink.append("</FONT>");
duke@1 187 }
bpatel@766 188 retlink.append("</a>");
duke@1 189 return retlink.toString();
duke@1 190 }
duke@1 191
duke@1 192 /**
bpatel@766 193 * Get Html Hyper Link.
duke@1 194 *
duke@1 195 * @param link String name of the file.
duke@1 196 * @param label Tag for the link.
bpatel@766 197 * @param title String that describes the link's content for accessibility.
bpatel@766 198 * @param target Target frame.
bpatel@766 199 * @return a content tree for the hyper link.
duke@1 200 */
jjg@1373 201 public Content getHyperLink(DocPath link,
jjg@1372 202 Content label, String title, String target) {
jjg@1373 203 return getHyperLink(new DocLink(link), label, title, target);
jjg@1372 204 }
jjg@1373 205
jjg@1373 206 public Content getHyperLink(DocLink link,
bpatel@766 207 Content label, String title, String target) {
jjg@1373 208 HtmlTree anchor = HtmlTree.A(link.toString(), label);
bpatel@766 209 if (title != null && title.length() != 0) {
bpatel@766 210 anchor.addAttr(HtmlAttr.TITLE, title);
bpatel@766 211 }
bpatel@766 212 if (target != null && target.length() != 0) {
bpatel@766 213 anchor.addAttr(HtmlAttr.TARGET, target);
bpatel@766 214 }
bpatel@766 215 return anchor;
bpatel@766 216 }
bpatel@766 217
bpatel@766 218 /**
duke@1 219 * Get link string without positioning in the file.
duke@1 220 *
duke@1 221 * @param link String name of the file.
duke@1 222 * @param label Tag for the link.
duke@1 223 * @return Strign Hyper link.
duke@1 224 */
jjg@1372 225 public String getHyperLinkString(DocPath link, String label) {
jjg@1373 226 return getHyperLinkString(link, label, false);
duke@1 227 }
duke@1 228
duke@1 229 /**
duke@1 230 * Get the name of the package, this class is in.
duke@1 231 *
duke@1 232 * @param cd ClassDoc.
duke@1 233 */
duke@1 234 public String getPkgName(ClassDoc cd) {
duke@1 235 String pkgName = cd.containingPackage().name();
duke@1 236 if (pkgName.length() > 0) {
duke@1 237 pkgName += ".";
duke@1 238 return pkgName;
duke@1 239 }
duke@1 240 return "";
duke@1 241 }
duke@1 242
bpatel@233 243 public boolean getMemberDetailsListPrinted() {
bpatel@233 244 return memberDetailsListPrinted;
bpatel@233 245 }
bpatel@233 246
bpatel@233 247 /**
duke@1 248 * Print the frameset version of the Html file header.
duke@1 249 * Called only when generating an HTML frameset file.
duke@1 250 *
bpatel@766 251 * @param title Title of this HTML document
bpatel@766 252 * @param noTimeStamp If true, don't print time stamp in header
bpatel@766 253 * @param frameset the frameset to be added to the HTML document
duke@1 254 */
bpatel@766 255 public void printFramesetDocument(String title, boolean noTimeStamp,
jjg@1364 256 Content frameset) throws IOException {
bpatel@766 257 Content htmlDocType = DocType.Frameset();
bpatel@766 258 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 259 Content head = new HtmlTree(HtmlTag.HEAD);
duke@1 260 if (! noTimeStamp) {
jjg@1361 261 Content headComment = new Comment(getGeneratedByString());
bpatel@766 262 head.addContent(headComment);
duke@1 263 }
duke@1 264 if (configuration.charset.length() > 0) {
bpatel@766 265 Content meta = HtmlTree.META("Content-Type", "text/html",
bpatel@766 266 configuration.charset);
bpatel@766 267 head.addContent(meta);
duke@1 268 }
bpatel@766 269 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
bpatel@766 270 head.addContent(windowTitle);
bpatel@766 271 head.addContent(getFramesetJavaScript());
bpatel@766 272 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 273 head, frameset);
bpatel@766 274 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 275 htmlComment, htmlTree);
jjg@1365 276 write(htmlDocument);
duke@1 277 }
duke@1 278
duke@1 279 /**
duke@1 280 * Print the appropriate spaces to format the class tree in the class page.
duke@1 281 *
duke@1 282 * @param len Number of spaces.
duke@1 283 */
duke@1 284 public String spaces(int len) {
duke@1 285 String space = "";
duke@1 286
duke@1 287 for (int i = 0; i < len; i++) {
duke@1 288 space += " ";
duke@1 289 }
duke@1 290 return space;
duke@1 291 }
duke@1 292
jjg@1361 293 protected String getGeneratedByString() {
duke@1 294 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
jjg@1361 295 Date today = calendar.getTime();
jjg@1361 296 return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
duke@1 297 }
duke@1 298 }

mercurial