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

Tue, 23 Oct 2012 13:58:56 -0700

author
jjg
date
Tue, 23 Oct 2012 13:58:56 -0700
changeset 1373
4a1c57a1c410
parent 1372
78962d89f283
child 1381
23fe1a96bc0f
permissions
-rw-r--r--

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

mercurial