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

Mon, 13 Dec 2010 13:44:47 -0800

author
bpatel
date
Mon, 13 Dec 2010 13:44:47 -0800
changeset 793
ffbf2b2a8611
parent 766
90af8d87741f
child 798
4868a36f6fd8
permissions
-rw-r--r--

7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 1997, 2009, 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@197 32 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 33
duke@1 34
duke@1 35 /**
duke@1 36 * Class for the Html Format Code Generation specific to JavaDoc.
duke@1 37 * This Class contains methods related to the Html Code Generation which
duke@1 38 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
duke@1 39 * and com.sun.tools.doclets.oneone.
duke@1 40 *
duke@1 41 * @since 1.2
duke@1 42 * @author Atul M Dambalkar
duke@1 43 * @author Robert Field
duke@1 44 */
duke@1 45 public abstract class HtmlDocWriter extends HtmlWriter {
duke@1 46
duke@1 47 /**
duke@1 48 * Constructor. Initializes the destination file name through the super
duke@1 49 * class HtmlWriter.
duke@1 50 *
duke@1 51 * @param filename String file name.
duke@1 52 */
duke@1 53 public HtmlDocWriter(Configuration configuration,
duke@1 54 String filename) throws IOException {
duke@1 55 super(configuration,
duke@1 56 null, configuration.destDirName + filename,
duke@1 57 configuration.docencoding);
jjg@197 58 // use File to normalize file separators
duke@1 59 configuration.message.notice("doclet.Generating_0",
jjg@197 60 new File(configuration.destDirName, filename));
duke@1 61 }
duke@1 62
duke@1 63 public HtmlDocWriter(Configuration configuration,
duke@1 64 String path, String filename) throws IOException {
duke@1 65 super(configuration,
duke@1 66 configuration.destDirName + path, filename,
duke@1 67 configuration.docencoding);
jjg@197 68 // use File to normalize file separators
duke@1 69 configuration.message.notice("doclet.Generating_0",
jjg@197 70 new File(configuration.destDirName,
jjg@197 71 ((path.length() > 0)? path + File.separator: "") + filename));
duke@1 72 }
duke@1 73
duke@1 74 /**
duke@1 75 * Accessor for configuration.
duke@1 76 */
duke@1 77 public abstract Configuration configuration();
duke@1 78
duke@1 79 /**
duke@1 80 * Print Html Hyper Link.
duke@1 81 *
duke@1 82 * @param link String name of the file.
duke@1 83 * @param where Position of the link in the file. Character '#' is not
duke@1 84 * needed.
duke@1 85 * @param label Tag for the link.
bpatel@182 86 * @param strong Boolean that sets label to strong.
duke@1 87 */
duke@1 88 public void printHyperLink(String link, String where,
bpatel@182 89 String label, boolean strong) {
bpatel@766 90 print(getHyperLinkString(link, where, label, strong, "", "", ""));
duke@1 91 }
duke@1 92
duke@1 93 /**
duke@1 94 * Print Html Hyper Link.
duke@1 95 *
duke@1 96 * @param link String name of the file.
duke@1 97 * @param where Position of the link in the file. Character '#' is not
duke@1 98 * needed.
duke@1 99 * @param label Tag for the link.
duke@1 100 */
duke@1 101 public void printHyperLink(String link, String where, String label) {
duke@1 102 printHyperLink(link, where, label, false);
duke@1 103 }
duke@1 104
duke@1 105 /**
duke@1 106 * Print Html Hyper Link.
duke@1 107 *
duke@1 108 * @param link String name of the file.
duke@1 109 * @param where Position of the link in the file. Character '#' is not
duke@1 110 * needed.
duke@1 111 * @param label Tag for the link.
bpatel@182 112 * @param strong Boolean that sets label to strong.
duke@1 113 * @param stylename String style of text defined in style sheet.
duke@1 114 */
duke@1 115 public void printHyperLink(String link, String where,
bpatel@182 116 String label, boolean strong,
duke@1 117 String stylename) {
bpatel@766 118 print(getHyperLinkString(link, where, label, strong, stylename, "", ""));
duke@1 119 }
duke@1 120
duke@1 121 /**
duke@1 122 * Return Html Hyper Link string.
duke@1 123 *
duke@1 124 * @param link String name of the file.
duke@1 125 * @param where Position of the link in the file. Character '#' is not
duke@1 126 * needed.
duke@1 127 * @param label Tag for the link.
bpatel@182 128 * @param strong Boolean that sets label to strong.
duke@1 129 * @return String Hyper Link.
duke@1 130 */
bpatel@766 131 public String getHyperLinkString(String link, String where,
bpatel@182 132 String label, boolean strong) {
bpatel@766 133 return getHyperLinkString(link, where, label, strong, "", "", "");
duke@1 134 }
duke@1 135
duke@1 136 /**
duke@1 137 * Get Html Hyper Link string.
duke@1 138 *
duke@1 139 * @param link String name of the file.
duke@1 140 * @param where Position of the link in the file. Character '#' is not
duke@1 141 * needed.
duke@1 142 * @param label Tag for the link.
bpatel@182 143 * @param strong Boolean that sets label to strong.
duke@1 144 * @param stylename String style of text defined in style sheet.
duke@1 145 * @return String Hyper Link.
duke@1 146 */
bpatel@766 147 public String getHyperLinkString(String link, String where,
bpatel@182 148 String label, boolean strong,
duke@1 149 String stylename) {
bpatel@766 150 return getHyperLinkString(link, where, label, strong, stylename, "", "");
bpatel@766 151 }
bpatel@766 152
bpatel@766 153 /**
bpatel@766 154 * Get Html Hyper Link string.
bpatel@766 155 *
bpatel@766 156 * @param link String name of the file.
bpatel@766 157 * @param where Position of the link in the file. Character '#' is not
bpatel@766 158 * needed.
bpatel@766 159 * @param label Tag for the link.
bpatel@766 160 * @return a content tree for the hyper link
bpatel@766 161 */
bpatel@766 162 public Content getHyperLink(String link, String where,
bpatel@766 163 Content label) {
bpatel@766 164 return getHyperLink(link, where, label, "", "");
duke@1 165 }
duke@1 166
duke@1 167 /**
duke@1 168 * Get Html Hyper Link string.
duke@1 169 *
duke@1 170 * @param link String name of the file.
duke@1 171 * @param where Position of the link in the file. Character '#' is not
duke@1 172 * needed.
duke@1 173 * @param label Tag for the link.
bpatel@182 174 * @param strong Boolean that sets label to strong.
duke@1 175 * @param stylename String style of text defined in style sheet.
duke@1 176 * @param title String that describes the link's content for accessibility.
duke@1 177 * @param target Target frame.
duke@1 178 * @return String Hyper Link.
duke@1 179 */
bpatel@766 180 public String getHyperLinkString(String link, String where,
bpatel@182 181 String label, boolean strong,
duke@1 182 String stylename, String title, String target) {
duke@1 183 StringBuffer retlink = new StringBuffer();
bpatel@766 184 retlink.append("<a href=\"");
duke@1 185 retlink.append(link);
duke@1 186 if (where != null && where.length() != 0) {
duke@1 187 retlink.append("#");
duke@1 188 retlink.append(where);
duke@1 189 }
duke@1 190 retlink.append("\"");
duke@1 191 if (title != null && title.length() != 0) {
duke@1 192 retlink.append(" title=\"" + title + "\"");
duke@1 193 }
duke@1 194 if (target != null && target.length() != 0) {
duke@1 195 retlink.append(" target=\"" + target + "\"");
duke@1 196 }
duke@1 197 retlink.append(">");
duke@1 198 if (stylename != null && stylename.length() != 0) {
duke@1 199 retlink.append("<FONT CLASS=\"");
duke@1 200 retlink.append(stylename);
duke@1 201 retlink.append("\">");
duke@1 202 }
bpatel@182 203 if (strong) {
bpatel@766 204 retlink.append("<span class=\"strong\">");
duke@1 205 }
duke@1 206 retlink.append(label);
bpatel@182 207 if (strong) {
bpatel@766 208 retlink.append("</span>");
duke@1 209 }
duke@1 210 if (stylename != null && stylename.length() != 0) {
duke@1 211 retlink.append("</FONT>");
duke@1 212 }
bpatel@766 213 retlink.append("</a>");
duke@1 214 return retlink.toString();
duke@1 215 }
duke@1 216
duke@1 217 /**
bpatel@766 218 * Get Html Hyper Link.
duke@1 219 *
duke@1 220 * @param link String name of the file.
bpatel@766 221 * @param where Position of the link in the file. Character '#' is not
bpatel@766 222 * needed.
duke@1 223 * @param label Tag for the link.
bpatel@766 224 * @param title String that describes the link's content for accessibility.
bpatel@766 225 * @param target Target frame.
bpatel@766 226 * @return a content tree for the hyper link.
duke@1 227 */
bpatel@766 228 public Content getHyperLink(String link, String where,
bpatel@766 229 Content label, String title, String target) {
bpatel@766 230 if (where != null && where.length() != 0) {
bpatel@766 231 link += "#" + where;
bpatel@766 232 }
bpatel@766 233 HtmlTree anchor = HtmlTree.A(link, label);
bpatel@766 234 if (title != null && title.length() != 0) {
bpatel@766 235 anchor.addAttr(HtmlAttr.TITLE, title);
bpatel@766 236 }
bpatel@766 237 if (target != null && target.length() != 0) {
bpatel@766 238 anchor.addAttr(HtmlAttr.TARGET, target);
bpatel@766 239 }
bpatel@766 240 return anchor;
bpatel@766 241 }
bpatel@766 242
bpatel@766 243 /**
bpatel@766 244 * Get a hyperlink to a file.
bpatel@766 245 *
bpatel@766 246 * @param link String name of the file
bpatel@766 247 * @param label Label for the link
bpatel@766 248 * @return a content for the hyperlink to the file
bpatel@766 249 */
bpatel@766 250 public Content getHyperLink(String link, Content label) {
bpatel@766 251 return getHyperLink(link, "", label);
duke@1 252 }
duke@1 253
duke@1 254 /**
duke@1 255 * Get link string without positioning in the file.
duke@1 256 *
duke@1 257 * @param link String name of the file.
duke@1 258 * @param label Tag for the link.
duke@1 259 * @return Strign Hyper link.
duke@1 260 */
bpatel@766 261 public String getHyperLinkString(String link, String label) {
bpatel@766 262 return getHyperLinkString(link, "", label, false);
duke@1 263 }
duke@1 264
duke@1 265 /**
duke@1 266 * Print the name of the package, this class is in.
duke@1 267 *
duke@1 268 * @param cd ClassDoc.
duke@1 269 */
duke@1 270 public void printPkgName(ClassDoc cd) {
duke@1 271 print(getPkgName(cd));
duke@1 272 }
duke@1 273
duke@1 274 /**
duke@1 275 * Get the name of the package, this class is in.
duke@1 276 *
duke@1 277 * @param cd ClassDoc.
duke@1 278 */
duke@1 279 public String getPkgName(ClassDoc cd) {
duke@1 280 String pkgName = cd.containingPackage().name();
duke@1 281 if (pkgName.length() > 0) {
duke@1 282 pkgName += ".";
duke@1 283 return pkgName;
duke@1 284 }
duke@1 285 return "";
duke@1 286 }
duke@1 287
duke@1 288 /**
bpatel@233 289 * Keep track of member details list. Print the definition list start tag
bpatel@233 290 * if it is not printed yet.
bpatel@233 291 */
bpatel@233 292 public void printMemberDetailsListStartTag () {
bpatel@233 293 if (!getMemberDetailsListPrinted()) {
bpatel@233 294 dl();
bpatel@233 295 memberDetailsListPrinted = true;
bpatel@233 296 }
bpatel@233 297 }
bpatel@233 298
bpatel@233 299 /**
bpatel@233 300 * Print the definition list end tag if the list start tag was printed.
bpatel@233 301 */
bpatel@233 302 public void printMemberDetailsListEndTag () {
bpatel@233 303 if (getMemberDetailsListPrinted()) {
bpatel@233 304 dlEnd();
bpatel@233 305 memberDetailsListPrinted = false;
bpatel@233 306 }
bpatel@233 307 }
bpatel@233 308
bpatel@233 309 public boolean getMemberDetailsListPrinted() {
bpatel@233 310 return memberDetailsListPrinted;
bpatel@233 311 }
bpatel@233 312
bpatel@233 313 /**
duke@1 314 * Print the frameset version of the Html file header.
duke@1 315 * Called only when generating an HTML frameset file.
duke@1 316 *
bpatel@766 317 * @param title Title of this HTML document
bpatel@766 318 * @param noTimeStamp If true, don't print time stamp in header
bpatel@766 319 * @param frameset the frameset to be added to the HTML document
duke@1 320 */
bpatel@766 321 public void printFramesetDocument(String title, boolean noTimeStamp,
bpatel@766 322 Content frameset) {
bpatel@766 323 Content htmlDocType = DocType.Frameset();
bpatel@766 324 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 325 Content head = new HtmlTree(HtmlTag.HEAD);
duke@1 326 if (! noTimeStamp) {
bpatel@766 327 Content headComment = new Comment("Generated by javadoc on " + today());
bpatel@766 328 head.addContent(headComment);
duke@1 329 }
duke@1 330 if (configuration.charset.length() > 0) {
bpatel@766 331 Content meta = HtmlTree.META("Content-Type", "text/html",
bpatel@766 332 configuration.charset);
bpatel@766 333 head.addContent(meta);
duke@1 334 }
bpatel@766 335 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
bpatel@766 336 head.addContent(windowTitle);
bpatel@766 337 head.addContent(getFramesetJavaScript());
bpatel@766 338 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 339 head, frameset);
bpatel@766 340 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 341 htmlComment, htmlTree);
bpatel@766 342 print(htmlDocument.toString());
duke@1 343 }
duke@1 344
duke@1 345 /**
duke@1 346 * Print the appropriate spaces to format the class tree in the class page.
duke@1 347 *
duke@1 348 * @param len Number of spaces.
duke@1 349 */
duke@1 350 public String spaces(int len) {
duke@1 351 String space = "";
duke@1 352
duke@1 353 for (int i = 0; i < len; i++) {
duke@1 354 space += " ";
duke@1 355 }
duke@1 356 return space;
duke@1 357 }
duke@1 358
duke@1 359 /**
duke@1 360 * Print the closing &lt;/body&gt; and &lt;/html&gt; tags.
duke@1 361 */
duke@1 362 public void printBodyHtmlEnd() {
duke@1 363 println();
duke@1 364 bodyEnd();
duke@1 365 htmlEnd();
duke@1 366 }
duke@1 367
duke@1 368 /**
duke@1 369 * Calls {@link #printBodyHtmlEnd()} method.
duke@1 370 */
duke@1 371 public void printFooter() {
duke@1 372 printBodyHtmlEnd();
duke@1 373 }
duke@1 374
duke@1 375 /**
duke@1 376 * Print closing &lt;/html&gt; tag.
duke@1 377 */
duke@1 378 public void printFrameFooter() {
duke@1 379 htmlEnd();
duke@1 380 }
duke@1 381
duke@1 382 /**
duke@1 383 * Print ten non-breaking spaces("&#38;nbsp;").
duke@1 384 */
duke@1 385 public void printNbsps() {
duke@1 386 print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
duke@1 387 }
duke@1 388
duke@1 389 /**
duke@1 390 * Get the day and date information for today, depending upon user option.
duke@1 391 *
duke@1 392 * @return String Today.
duke@1 393 * @see java.util.Calendar
duke@1 394 * @see java.util.GregorianCalendar
duke@1 395 * @see java.util.TimeZone
duke@1 396 */
duke@1 397 public String today() {
duke@1 398 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
duke@1 399 return calendar.getTime().toString();
duke@1 400 }
duke@1 401 }

mercurial