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

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 405
ebb6ad5a95bb
child 766
90af8d87741f
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

duke@1 1 /*
ohair@554 2 * Copyright (c) 1998, 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;
duke@1 27
duke@1 28 import java.io.*;
duke@1 29 import java.text.SimpleDateFormat;
duke@1 30 import java.util.*;
duke@1 31
bpatel@233 32 import com.sun.javadoc.*;
bpatel@233 33 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@233 34 import com.sun.tools.doclets.internal.toolkit.*;
bpatel@233 35 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@233 36 import com.sun.tools.doclets.internal.toolkit.taglets.*;
duke@1 37
duke@1 38 /**
duke@1 39 * Class for the Html Format Code Generation specific to JavaDoc.
duke@1 40 * This Class contains methods related to the Html Code Generation which
duke@1 41 * are used extensively while generating the entire documentation.
duke@1 42 *
duke@1 43 * @since 1.2
duke@1 44 * @author Atul M Dambalkar
duke@1 45 * @author Robert Field
bpatel@233 46 * @author Bhavesh Patel (Modified)
duke@1 47 */
duke@1 48 public class HtmlDocletWriter extends HtmlDocWriter {
duke@1 49
duke@1 50 /**
duke@1 51 * Relative path from the file getting generated to the destination
duke@1 52 * directory. For example, if the file getting generated is
duke@1 53 * "java/lang/Object.html", then the relative path string is "../../".
duke@1 54 * This string can be empty if the file getting generated is in
duke@1 55 * the destination directory.
duke@1 56 */
duke@1 57 public String relativePath = "";
duke@1 58
duke@1 59 /**
duke@1 60 * Same as relativepath, but normalized to never be empty or
duke@1 61 * end with a slash.
duke@1 62 */
duke@1 63 public String relativepathNoSlash = "";
duke@1 64
duke@1 65 /**
duke@1 66 * Platform-dependent directory path from the current or the
duke@1 67 * destination directory to the file getting generated.
duke@1 68 * Used when creating the file.
duke@1 69 * For example, if the file getting generated is
duke@1 70 * "java/lang/Object.html", then the path string is "java/lang".
duke@1 71 */
duke@1 72 public String path = "";
duke@1 73
duke@1 74 /**
duke@1 75 * Name of the file getting generated. If the file getting generated is
duke@1 76 * "java/lang/Object.html", then the filename is "Object.html".
duke@1 77 */
duke@1 78 public String filename = "";
duke@1 79
duke@1 80 /**
duke@1 81 * The display length used for indentation while generating the class page.
duke@1 82 */
duke@1 83 public int displayLength = 0;
duke@1 84
duke@1 85 /**
duke@1 86 * The global configuration information for this run.
duke@1 87 */
duke@1 88 public ConfigurationImpl configuration;
duke@1 89
duke@1 90 /**
duke@1 91 * Constructor to construct the HtmlStandardWriter object.
duke@1 92 *
duke@1 93 * @param filename File to be generated.
duke@1 94 */
duke@1 95 public HtmlDocletWriter(ConfigurationImpl configuration,
duke@1 96 String filename) throws IOException {
duke@1 97 super(configuration, filename);
duke@1 98 this.configuration = configuration;
duke@1 99 this.filename = filename;
duke@1 100 }
duke@1 101
duke@1 102 /**
duke@1 103 * Constructor to construct the HtmlStandardWriter object.
duke@1 104 *
duke@1 105 * @param path Platform-dependent {@link #path} used when
duke@1 106 * creating file.
duke@1 107 * @param filename Name of file to be generated.
duke@1 108 * @param relativePath Value for the variable {@link #relativePath}.
duke@1 109 */
duke@1 110 public HtmlDocletWriter(ConfigurationImpl configuration,
duke@1 111 String path, String filename,
duke@1 112 String relativePath) throws IOException {
duke@1 113 super(configuration, path, filename);
duke@1 114 this.configuration = configuration;
duke@1 115 this.path = path;
duke@1 116 this.relativePath = relativePath;
duke@1 117 this.relativepathNoSlash =
duke@1 118 DirectoryManager.getPathNoTrailingSlash(this.relativePath);
duke@1 119 this.filename = filename;
duke@1 120 }
duke@1 121
duke@1 122 /**
duke@1 123 * Replace {@docRoot} tag used in options that accept HTML text, such
duke@1 124 * as -header, -footer, -top and -bottom, and when converting a relative
duke@1 125 * HREF where commentTagsToString inserts a {@docRoot} where one was
duke@1 126 * missing. (Also see DocRootTaglet for {@docRoot} tags in doc
duke@1 127 * comments.)
duke@1 128 * <p>
duke@1 129 * Replace {&#064;docRoot} tag in htmlstr with the relative path to the
duke@1 130 * destination directory from the directory where the file is being
duke@1 131 * written, looping to handle all such tags in htmlstr.
duke@1 132 * <p>
duke@1 133 * For example, for "-d docs" and -header containing {&#064;docRoot}, when
duke@1 134 * the HTML page for source file p/C1.java is being generated, the
duke@1 135 * {&#064;docRoot} tag would be inserted into the header as "../",
duke@1 136 * the relative path from docs/p/ to docs/ (the document root).
duke@1 137 * <p>
duke@1 138 * Note: This doc comment was written with '&amp;#064;' representing '@'
duke@1 139 * to prevent the inline tag from being interpreted.
duke@1 140 */
duke@1 141 public String replaceDocRootDir(String htmlstr) {
duke@1 142 // Return if no inline tags exist
duke@1 143 int index = htmlstr.indexOf("{@");
duke@1 144 if (index < 0) {
duke@1 145 return htmlstr;
duke@1 146 }
duke@1 147 String lowerHtml = htmlstr.toLowerCase();
duke@1 148 // Return index of first occurrence of {@docroot}
duke@1 149 // Note: {@docRoot} is not case sensitive when passed in w/command line option
duke@1 150 index = lowerHtml.indexOf("{@docroot}", index);
duke@1 151 if (index < 0) {
duke@1 152 return htmlstr;
duke@1 153 }
duke@1 154 StringBuffer buf = new StringBuffer();
duke@1 155 int previndex = 0;
duke@1 156 while (true) {
duke@1 157 // Search for lowercase version of {@docRoot}
duke@1 158 index = lowerHtml.indexOf("{@docroot}", previndex);
duke@1 159 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
duke@1 160 if (index < 0) {
duke@1 161 buf.append(htmlstr.substring(previndex));
duke@1 162 break;
duke@1 163 }
duke@1 164 // If next {@docroot} tag found, append htmlstr up to start of tag
duke@1 165 buf.append(htmlstr.substring(previndex, index));
duke@1 166 previndex = index + 10; // length for {@docroot} string
duke@1 167 // Insert relative path where {@docRoot} was located
duke@1 168 buf.append(relativepathNoSlash);
duke@1 169 // Append slash if next character is not a slash
duke@1 170 if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length()
duke@1 171 && htmlstr.charAt(previndex) != '/') {
duke@1 172 buf.append(DirectoryManager.URL_FILE_SEPERATOR);
duke@1 173 }
duke@1 174 }
duke@1 175 return buf.toString();
duke@1 176 }
duke@1 177
duke@1 178 /**
duke@1 179 * Print Html Hyper Link, with target frame. This
duke@1 180 * link will only appear if page is not in a frame.
duke@1 181 *
duke@1 182 * @param link String name of the file.
duke@1 183 * @param where Position in the file
duke@1 184 * @param target Name of the target frame.
duke@1 185 * @param label Tag for the link.
bpatel@182 186 * @param strong Whether the label should be strong or not?
duke@1 187 */
duke@1 188 public void printNoFramesTargetHyperLink(String link, String where,
duke@1 189 String target, String label,
bpatel@182 190 boolean strong) {
duke@1 191 script();
duke@1 192 println(" <!--");
duke@1 193 println(" if(window==top) {");
duke@1 194 println(" document.writeln('"
bpatel@182 195 + getHyperLink(link, where, label, strong, "", "", target) + "');");
duke@1 196 println(" }");
duke@1 197 println(" //-->");
duke@1 198 scriptEnd();
duke@1 199 noScript();
bpatel@182 200 println(" " + getHyperLink(link, where, label, strong, "", "", target));
duke@1 201 noScriptEnd();
duke@1 202 println(DocletConstants.NL);
duke@1 203 }
duke@1 204
duke@1 205 private void printMethodInfo(MethodDoc method) {
duke@1 206 ClassDoc[] intfacs = method.containingClass().interfaces();
duke@1 207 MethodDoc overriddenMethod = method.overriddenMethod();
bpatel@233 208 // Check whether there is any implementation or overridden info to be
bpatel@233 209 // printed. If no overridden or implementation info needs to be
bpatel@233 210 // printed, do not print this section.
bpatel@233 211 if ((intfacs.length > 0 &&
bpatel@233 212 new ImplementedMethods(method, this.configuration).build().length > 0) ||
bpatel@233 213 overriddenMethod != null) {
bpatel@233 214 printMemberDetailsListStartTag();
duke@1 215 dd();
duke@1 216 printTagsInfoHeader();
duke@1 217 MethodWriterImpl.printImplementsInfo(this, method);
duke@1 218 if (overriddenMethod != null) {
duke@1 219 MethodWriterImpl.printOverridden(this,
duke@1 220 method.overriddenType(), overriddenMethod);
duke@1 221 }
duke@1 222 printTagsInfoFooter();
duke@1 223 ddEnd();
duke@1 224 }
duke@1 225 }
duke@1 226
duke@1 227 protected void printTags(Doc doc) {
duke@1 228 if(configuration.nocomment){
duke@1 229 return;
duke@1 230 }
duke@1 231 if (doc instanceof MethodDoc) {
duke@1 232 printMethodInfo((MethodDoc) doc);
duke@1 233 }
duke@1 234 TagletOutputImpl output = new TagletOutputImpl("");
duke@1 235 TagletWriter.genTagOuput(configuration.tagletManager, doc,
duke@1 236 configuration.tagletManager.getCustomTags(doc),
duke@1 237 getTagletWriterInstance(false), output);
bpatel@233 238 String outputString = output.toString().trim();
bpatel@244 239 // For RootDoc, ClassDoc and PackageDoc, this section is not the
bpatel@244 240 // definition description but the start of definition list.
bpatel@233 241 if (!outputString.isEmpty()) {
bpatel@244 242 if (!(doc instanceof RootDoc || doc instanceof ClassDoc ||
bpatel@244 243 doc instanceof PackageDoc)) {
bpatel@233 244 printMemberDetailsListStartTag();
bpatel@233 245 dd();
bpatel@233 246 }
duke@1 247 printTagsInfoHeader();
bpatel@233 248 print(outputString);
duke@1 249 printTagsInfoFooter();
bpatel@244 250 if (!(doc instanceof RootDoc || doc instanceof ClassDoc ||
bpatel@244 251 doc instanceof PackageDoc))
bpatel@233 252 ddEnd();
duke@1 253 }
duke@1 254 }
duke@1 255
duke@1 256 /**
bpatel@233 257 * Check whether there are any tags for Serialization Overview
bpatel@233 258 * section to be printed.
bpatel@222 259 *
bpatel@233 260 * @param field the FieldDoc object to check for tags.
bpatel@222 261 * @return true if there are tags to be printed else return false.
bpatel@222 262 */
bpatel@233 263 protected boolean hasSerializationOverviewTags(FieldDoc field) {
bpatel@222 264 TagletOutputImpl output = new TagletOutputImpl("");
bpatel@233 265 TagletWriter.genTagOuput(configuration.tagletManager, field,
bpatel@233 266 configuration.tagletManager.getCustomTags(field),
bpatel@222 267 getTagletWriterInstance(false), output);
bpatel@233 268 return (!output.toString().trim().isEmpty());
bpatel@222 269 }
bpatel@222 270
bpatel@222 271 /**
duke@1 272 * Returns a TagletWriter that knows how to write HTML.
duke@1 273 *
duke@1 274 * @return a TagletWriter that knows how to write HTML.
duke@1 275 */
duke@1 276 public TagletWriter getTagletWriterInstance(boolean isFirstSentence) {
duke@1 277 return new TagletWriterImpl(this, isFirstSentence);
duke@1 278 }
duke@1 279
duke@1 280 protected void printTagsInfoHeader() {
duke@1 281 dl();
duke@1 282 }
duke@1 283
duke@1 284 protected void printTagsInfoFooter() {
duke@1 285 dlEnd();
duke@1 286 }
duke@1 287
duke@1 288 /**
duke@1 289 * Print Package link, with target frame.
duke@1 290 *
duke@1 291 * @param pd The link will be to the "package-summary.html" page for this
duke@1 292 * package.
duke@1 293 * @param target Name of the target frame.
duke@1 294 * @param label Tag for the link.
duke@1 295 */
duke@1 296 public void printTargetPackageLink(PackageDoc pd, String target,
duke@1 297 String label) {
duke@1 298 print(getHyperLink(pathString(pd, "package-summary.html"), "", label,
duke@1 299 false, "", "", target));
duke@1 300 }
duke@1 301
duke@1 302 /**
duke@1 303 * Print the html file header. Also print Html page title and stylesheet
duke@1 304 * default properties.
duke@1 305 *
duke@1 306 * @param title String window title to go in the &lt;TITLE&gt; tag
duke@1 307 * @param metakeywords Array of String keywords for META tag. Each element
duke@1 308 * of the array is assigned to a separate META tag.
duke@1 309 * Pass in null for no array.
duke@1 310 * @param includeScript boolean true if printing windowtitle script.
duke@1 311 * False for files that appear in the left-hand frames.
duke@1 312 */
duke@1 313 public void printHtmlHeader(String title, String[] metakeywords,
duke@1 314 boolean includeScript) {
duke@1 315 println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
duke@1 316 "Transitional//EN\" " +
duke@1 317 "\"http://www.w3.org/TR/html4/loose.dtd\">");
duke@1 318 println("<!--NewPage-->");
duke@1 319 html();
duke@1 320 head();
duke@1 321 if (! configuration.notimestamp) {
duke@1 322 print("<!-- Generated by javadoc (build " + ConfigurationImpl.BUILD_DATE + ") on ");
duke@1 323 print(today());
duke@1 324 println(" -->");
duke@1 325 }
duke@1 326 if (configuration.charset.length() > 0) {
duke@1 327 println("<META http-equiv=\"Content-Type\" content=\"text/html; "
duke@1 328 + "charset=" + configuration.charset + "\">");
duke@1 329 }
duke@1 330 if ( configuration.windowtitle.length() > 0 ) {
duke@1 331 title += " (" + configuration.windowtitle + ")";
duke@1 332 }
duke@1 333 title(title);
duke@1 334 println(title);
duke@1 335 titleEnd();
duke@1 336 println("");
duke@1 337 if (! configuration.notimestamp) {
duke@1 338 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
duke@1 339 println("<META NAME=\"date\" "
duke@1 340 + "CONTENT=\"" + dateFormat.format(new Date()) + "\">");
duke@1 341 }
duke@1 342 if ( metakeywords != null ) {
duke@1 343 for ( int i=0; i < metakeywords.length; i++ ) {
duke@1 344 println("<META NAME=\"keywords\" "
duke@1 345 + "CONTENT=\"" + metakeywords[i] + "\">");
duke@1 346 }
duke@1 347 }
duke@1 348 println("");
duke@1 349 printStyleSheetProperties();
duke@1 350 println("");
duke@1 351 // Don't print windowtitle script for overview-frame, allclasses-frame
duke@1 352 // and package-frame
duke@1 353 if (includeScript) {
duke@1 354 printWinTitleScript(title);
duke@1 355 }
duke@1 356 println("");
duke@1 357 headEnd();
duke@1 358 println("");
duke@1 359 body("white", includeScript);
duke@1 360 }
duke@1 361
duke@1 362 /**
duke@1 363 * Print user specified header and the footer.
duke@1 364 *
duke@1 365 * @param header if true print the user provided header else print the
duke@1 366 * user provided footer.
duke@1 367 */
duke@1 368 public void printUserHeaderFooter(boolean header) {
duke@1 369 em();
duke@1 370 if (header) {
duke@1 371 print(replaceDocRootDir(configuration.header));
duke@1 372 } else {
duke@1 373 if (configuration.footer.length() != 0) {
duke@1 374 print(replaceDocRootDir(configuration.footer));
duke@1 375 } else {
duke@1 376 print(replaceDocRootDir(configuration.header));
duke@1 377 }
duke@1 378 }
duke@1 379 emEnd();
duke@1 380 }
duke@1 381
duke@1 382 /**
duke@1 383 * Print the user specified top.
duke@1 384 */
duke@1 385 public void printTop() {
duke@1 386 print(replaceDocRootDir(configuration.top));
duke@1 387 hr();
duke@1 388 }
duke@1 389
duke@1 390 /**
duke@1 391 * Print the user specified bottom.
duke@1 392 */
duke@1 393 public void printBottom() {
duke@1 394 hr();
duke@1 395 print(replaceDocRootDir(configuration.bottom));
duke@1 396 }
duke@1 397
duke@1 398 /**
duke@1 399 * Print the navigation bar for the Html page at the top and and the bottom.
duke@1 400 *
duke@1 401 * @param header If true print navigation bar at the top of the page else
duke@1 402 * print the nevigation bar at the bottom.
duke@1 403 */
duke@1 404 protected void navLinks(boolean header) {
duke@1 405 println("");
duke@1 406 if (!configuration.nonavbar) {
duke@1 407 if (header) {
duke@1 408 println(DocletConstants.NL + "<!-- ========= START OF TOP NAVBAR ======= -->");
duke@1 409 anchor("navbar_top");
duke@1 410 println();
duke@1 411 print(getHyperLink("", "skip-navbar_top", "", false, "",
duke@1 412 configuration.getText("doclet.Skip_navigation_links"), ""));
duke@1 413 } else {
duke@1 414 println(DocletConstants.NL + "<!-- ======= START OF BOTTOM NAVBAR ====== -->");
duke@1 415 anchor("navbar_bottom");
duke@1 416 println();
duke@1 417 print(getHyperLink("", "skip-navbar_bottom", "", false, "",
duke@1 418 configuration.getText("doclet.Skip_navigation_links"), ""));
duke@1 419 }
duke@1 420 table(0, "100%", 1, 0);
duke@1 421 tr();
duke@1 422 tdColspanBgcolorStyle(2, "#EEEEFF", "NavBarCell1");
duke@1 423 println("");
duke@1 424 if (header) {
duke@1 425 anchor("navbar_top_firstrow");
duke@1 426 } else {
duke@1 427 anchor("navbar_bottom_firstrow");
duke@1 428 }
duke@1 429 table(0, 0, 3);
duke@1 430 print(" ");
duke@1 431 trAlignVAlign("center", "top");
duke@1 432
duke@1 433 if (configuration.createoverview) {
duke@1 434 navLinkContents();
duke@1 435 }
duke@1 436
duke@1 437 if (configuration.packages.length == 1) {
duke@1 438 navLinkPackage(configuration.packages[0]);
duke@1 439 } else if (configuration.packages.length > 1) {
duke@1 440 navLinkPackage();
duke@1 441 }
duke@1 442
duke@1 443 navLinkClass();
duke@1 444
duke@1 445 if(configuration.classuse) {
duke@1 446 navLinkClassUse();
duke@1 447 }
duke@1 448 if(configuration.createtree) {
duke@1 449 navLinkTree();
duke@1 450 }
duke@1 451 if(!(configuration.nodeprecated ||
duke@1 452 configuration.nodeprecatedlist)) {
duke@1 453 navLinkDeprecated();
duke@1 454 }
duke@1 455 if(configuration.createindex) {
duke@1 456 navLinkIndex();
duke@1 457 }
duke@1 458 if (!configuration.nohelp) {
duke@1 459 navLinkHelp();
duke@1 460 }
duke@1 461 print(" ");
duke@1 462 trEnd();
duke@1 463 tableEnd();
duke@1 464 tdEnd();
duke@1 465
duke@1 466 tdAlignVAlignRowspan("right", "top", 3);
duke@1 467
duke@1 468 printUserHeaderFooter(header);
duke@1 469 tdEnd();
duke@1 470 trEnd();
duke@1 471 println("");
duke@1 472
duke@1 473 tr();
duke@1 474 tdBgcolorStyle("white", "NavBarCell2");
duke@1 475 font("-2");
duke@1 476 space();
duke@1 477 navLinkPrevious();
duke@1 478 space();
duke@1 479 println("");
duke@1 480 space();
duke@1 481 navLinkNext();
duke@1 482 fontEnd();
duke@1 483 tdEnd();
duke@1 484
duke@1 485 tdBgcolorStyle("white", "NavBarCell2");
duke@1 486 font("-2");
duke@1 487 print(" ");
duke@1 488 navShowLists();
duke@1 489 print(" ");
duke@1 490 space();
duke@1 491 println("");
duke@1 492 space();
duke@1 493 navHideLists(filename);
duke@1 494 print(" ");
duke@1 495 space();
duke@1 496 println("");
duke@1 497 space();
duke@1 498 navLinkClassIndex();
duke@1 499 fontEnd();
duke@1 500 tdEnd();
duke@1 501
duke@1 502 trEnd();
duke@1 503
duke@1 504 printSummaryDetailLinks();
duke@1 505
duke@1 506 tableEnd();
duke@1 507 if (header) {
duke@1 508 aName("skip-navbar_top");
duke@1 509 aEnd();
duke@1 510 println(DocletConstants.NL + "<!-- ========= END OF TOP NAVBAR ========= -->");
duke@1 511 } else {
duke@1 512 aName("skip-navbar_bottom");
duke@1 513 aEnd();
duke@1 514 println(DocletConstants.NL + "<!-- ======== END OF BOTTOM NAVBAR ======= -->");
duke@1 515 }
duke@1 516 println("");
duke@1 517 }
duke@1 518 }
duke@1 519
duke@1 520 /**
duke@1 521 * Print the word "NEXT" to indicate that no link is available. Override
duke@1 522 * this method to customize next link.
duke@1 523 */
duke@1 524 protected void navLinkNext() {
duke@1 525 navLinkNext(null);
duke@1 526 }
duke@1 527
duke@1 528 /**
duke@1 529 * Print the word "PREV" to indicate that no link is available. Override
duke@1 530 * this method to customize prev link.
duke@1 531 */
duke@1 532 protected void navLinkPrevious() {
duke@1 533 navLinkPrevious(null);
duke@1 534 }
duke@1 535
duke@1 536 /**
duke@1 537 * Do nothing. This is the default method.
duke@1 538 */
duke@1 539 protected void printSummaryDetailLinks() {
duke@1 540 }
duke@1 541
duke@1 542 /**
duke@1 543 * Print link to the "overview-summary.html" page.
duke@1 544 */
duke@1 545 protected void navLinkContents() {
duke@1 546 navCellStart();
duke@1 547 printHyperLink(relativePath + "overview-summary.html", "",
duke@1 548 configuration.getText("doclet.Overview"), true, "NavBarFont1");
duke@1 549 navCellEnd();
duke@1 550 }
duke@1 551
duke@1 552 /**
duke@1 553 * Description for a cell in the navigation bar.
duke@1 554 */
duke@1 555 protected void navCellStart() {
duke@1 556 print(" ");
duke@1 557 tdBgcolorStyle("#EEEEFF", "NavBarCell1");
duke@1 558 print(" ");
duke@1 559 }
duke@1 560
duke@1 561 /**
duke@1 562 * Description for a cell in the navigation bar, but with reverse
duke@1 563 * high-light effect.
duke@1 564 */
duke@1 565 protected void navCellRevStart() {
duke@1 566 print(" ");
duke@1 567 tdBgcolorStyle("#FFFFFF", "NavBarCell1Rev");
duke@1 568 print(" ");
duke@1 569 space();
duke@1 570 }
duke@1 571
duke@1 572 /**
duke@1 573 * Closing tag for navigation bar cell.
duke@1 574 */
duke@1 575 protected void navCellEnd() {
duke@1 576 space();
duke@1 577 tdEnd();
duke@1 578 }
duke@1 579
duke@1 580 /**
duke@1 581 * Print link to the "package-summary.html" page for the package passed.
duke@1 582 *
duke@1 583 * @param pkg Package to which link will be generated.
duke@1 584 */
duke@1 585 protected void navLinkPackage(PackageDoc pkg) {
duke@1 586 navCellStart();
duke@1 587 printPackageLink(pkg, configuration.getText("doclet.Package"), true,
duke@1 588 "NavBarFont1");
duke@1 589 navCellEnd();
duke@1 590 }
duke@1 591
duke@1 592 /**
duke@1 593 * Print the word "Package" in the navigation bar cell, to indicate that
duke@1 594 * link is not available here.
duke@1 595 */
duke@1 596 protected void navLinkPackage() {
duke@1 597 navCellStart();
duke@1 598 fontStyle("NavBarFont1");
duke@1 599 printText("doclet.Package");
duke@1 600 fontEnd();
duke@1 601 navCellEnd();
duke@1 602 }
duke@1 603
duke@1 604 /**
duke@1 605 * Print the word "Use" in the navigation bar cell, to indicate that link
duke@1 606 * is not available.
duke@1 607 */
duke@1 608 protected void navLinkClassUse() {
duke@1 609 navCellStart();
duke@1 610 fontStyle("NavBarFont1");
duke@1 611 printText("doclet.navClassUse");
duke@1 612 fontEnd();
duke@1 613 navCellEnd();
duke@1 614 }
duke@1 615
duke@1 616 /**
duke@1 617 * Print link for previous file.
duke@1 618 *
duke@1 619 * @param prev File name for the prev link.
duke@1 620 */
duke@1 621 public void navLinkPrevious(String prev) {
duke@1 622 String tag = configuration.getText("doclet.Prev");
duke@1 623 if (prev != null) {
duke@1 624 printHyperLink(prev, "", tag, true) ;
duke@1 625 } else {
duke@1 626 print(tag);
duke@1 627 }
duke@1 628 }
duke@1 629
duke@1 630 /**
duke@1 631 * Print link for next file. If next is null, just print the label
duke@1 632 * without linking it anywhere.
duke@1 633 *
duke@1 634 * @param next File name for the next link.
duke@1 635 */
duke@1 636 public void navLinkNext(String next) {
duke@1 637 String tag = configuration.getText("doclet.Next");
duke@1 638 if (next != null) {
duke@1 639 printHyperLink(next, "", tag, true);
duke@1 640 } else {
duke@1 641 print(tag);
duke@1 642 }
duke@1 643 }
duke@1 644
duke@1 645 /**
duke@1 646 * Print "FRAMES" link, to switch to the frame version of the output.
duke@1 647 *
duke@1 648 * @param link File to be linked, "index.html".
duke@1 649 */
duke@1 650 protected void navShowLists(String link) {
duke@1 651 print(getHyperLink(link + "?" + path + filename, "",
duke@1 652 configuration.getText("doclet.FRAMES"), true, "", "", "_top"));
duke@1 653 }
duke@1 654
duke@1 655 /**
duke@1 656 * Print "FRAMES" link, to switch to the frame version of the output.
duke@1 657 */
duke@1 658 protected void navShowLists() {
duke@1 659 navShowLists(relativePath + "index.html");
duke@1 660 }
duke@1 661
duke@1 662 /**
duke@1 663 * Print "NO FRAMES" link, to switch to the non-frame version of the output.
duke@1 664 *
duke@1 665 * @param link File to be linked.
duke@1 666 */
duke@1 667 protected void navHideLists(String link) {
duke@1 668 print(getHyperLink(link, "", configuration.getText("doclet.NO_FRAMES"),
duke@1 669 true, "", "", "_top"));
duke@1 670 }
duke@1 671
duke@1 672 /**
duke@1 673 * Print "Tree" link in the navigation bar. If there is only one package
duke@1 674 * specified on the command line, then the "Tree" link will be to the
duke@1 675 * only "package-tree.html" file otherwise it will be to the
duke@1 676 * "overview-tree.html" file.
duke@1 677 */
duke@1 678 protected void navLinkTree() {
duke@1 679 navCellStart();
duke@1 680 PackageDoc[] packages = configuration.root.specifiedPackages();
duke@1 681 if (packages.length == 1 && configuration.root.specifiedClasses().length == 0) {
duke@1 682 printHyperLink(pathString(packages[0], "package-tree.html"), "",
duke@1 683 configuration.getText("doclet.Tree"), true, "NavBarFont1");
duke@1 684 } else {
duke@1 685 printHyperLink(relativePath + "overview-tree.html", "",
duke@1 686 configuration.getText("doclet.Tree"), true, "NavBarFont1");
duke@1 687 }
duke@1 688 navCellEnd();
duke@1 689 }
duke@1 690
duke@1 691 /**
duke@1 692 * Print "Tree" link to the "overview-tree.html" file.
duke@1 693 */
duke@1 694 protected void navLinkMainTree(String label) {
duke@1 695 printHyperLink(relativePath + "overview-tree.html", label);
duke@1 696 }
duke@1 697
duke@1 698 /**
duke@1 699 * Print the word "Class" in the navigation bar cell, to indicate that
duke@1 700 * class link is not available.
duke@1 701 */
duke@1 702 protected void navLinkClass() {
duke@1 703 navCellStart();
duke@1 704 fontStyle("NavBarFont1");
duke@1 705 printText("doclet.Class");
duke@1 706 fontEnd();
duke@1 707 navCellEnd();
duke@1 708 }
duke@1 709
duke@1 710 /**
duke@1 711 * Print "Deprecated" API link in the navigation bar.
duke@1 712 */
duke@1 713 protected void navLinkDeprecated() {
duke@1 714 navCellStart();
duke@1 715 printHyperLink(relativePath + "deprecated-list.html", "",
duke@1 716 configuration.getText("doclet.navDeprecated"), true, "NavBarFont1");
duke@1 717 navCellEnd();
duke@1 718 }
duke@1 719
duke@1 720 /**
duke@1 721 * Print link for generated index. If the user has used "-splitindex"
duke@1 722 * command line option, then link to file "index-files/index-1.html" is
duke@1 723 * generated otherwise link to file "index-all.html" is generated.
duke@1 724 */
duke@1 725 protected void navLinkClassIndex() {
duke@1 726 printNoFramesTargetHyperLink(relativePath +
duke@1 727 AllClassesFrameWriter.OUTPUT_FILE_NAME_NOFRAMES,
duke@1 728 "", "", configuration.getText("doclet.All_Classes"), true);
duke@1 729 }
duke@1 730 /**
duke@1 731 * Print link for generated class index.
duke@1 732 */
duke@1 733 protected void navLinkIndex() {
duke@1 734 navCellStart();
duke@1 735 printHyperLink(relativePath +
duke@1 736 (configuration.splitindex?
duke@1 737 DirectoryManager.getPath("index-files") +
duke@1 738 fileseparator: "") +
duke@1 739 (configuration.splitindex?
duke@1 740 "index-1.html" : "index-all.html"), "",
duke@1 741 configuration.getText("doclet.Index"), true, "NavBarFont1");
duke@1 742 navCellEnd();
duke@1 743 }
duke@1 744
duke@1 745 /**
duke@1 746 * Print help file link. If user has provided a help file, then generate a
duke@1 747 * link to the user given file, which is already copied to current or
duke@1 748 * destination directory.
duke@1 749 */
duke@1 750 protected void navLinkHelp() {
duke@1 751 String helpfilenm = configuration.helpfile;
duke@1 752 if (helpfilenm.equals("")) {
duke@1 753 helpfilenm = "help-doc.html";
duke@1 754 } else {
duke@1 755 int lastsep;
duke@1 756 if ((lastsep = helpfilenm.lastIndexOf(File.separatorChar)) != -1) {
duke@1 757 helpfilenm = helpfilenm.substring(lastsep + 1);
duke@1 758 }
duke@1 759 }
duke@1 760 navCellStart();
duke@1 761 printHyperLink(relativePath + helpfilenm, "",
duke@1 762 configuration.getText("doclet.Help"), true, "NavBarFont1");
duke@1 763 navCellEnd();
duke@1 764 }
duke@1 765
duke@1 766 /**
duke@1 767 * Print the word "Detail" in the navigation bar. No link is available.
duke@1 768 */
duke@1 769 protected void navDetail() {
duke@1 770 printText("doclet.Detail");
duke@1 771 }
duke@1 772
duke@1 773 /**
duke@1 774 * Print the word "Summary" in the navigation bar. No link is available.
duke@1 775 */
duke@1 776 protected void navSummary() {
duke@1 777 printText("doclet.Summary");
duke@1 778 }
duke@1 779
duke@1 780 /**
duke@1 781 * Print the Html table tag for the index summary tables. The table tag
duke@1 782 * printed is
duke@1 783 * &lt;TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
duke@1 784 */
duke@1 785 public void tableIndexSummary() {
duke@1 786 table(1, "100%", 3, 0);
duke@1 787 }
duke@1 788
duke@1 789 /**
bpatel@243 790 * Print the Html table tag for the index summary tables.
bpatel@243 791 *
bpatel@243 792 * @param summary the summary for the table tag summary attribute.
bpatel@243 793 */
bpatel@243 794 public void tableIndexSummary(String summary) {
bpatel@243 795 table(1, "100%", 3, 0, summary);
bpatel@243 796 }
bpatel@243 797
bpatel@243 798 /**
duke@1 799 * Same as {@link #tableIndexSummary()}.
duke@1 800 */
duke@1 801 public void tableIndexDetail() {
duke@1 802 table(1, "100%", 3, 0);
duke@1 803 }
duke@1 804
duke@1 805 /**
duke@1 806 * Print Html tag for table elements. The tag printed is
duke@1 807 * &lt;TD ALIGN="right" VALIGN="top" WIDTH="1%"&gt;.
duke@1 808 */
duke@1 809 public void tdIndex() {
duke@1 810 print("<TD ALIGN=\"right\" VALIGN=\"top\" WIDTH=\"1%\">");
duke@1 811 }
duke@1 812
duke@1 813 /**
bpatel@243 814 * Print table caption.
bpatel@243 815 */
bpatel@243 816 public void tableCaptionStart() {
bpatel@243 817 captionStyle("TableCaption");
bpatel@243 818 }
bpatel@243 819
bpatel@243 820 /**
bpatel@243 821 * Print table sub-caption.
bpatel@243 822 */
bpatel@243 823 public void tableSubCaptionStart() {
bpatel@243 824 captionStyle("TableSubCaption");
bpatel@243 825 }
bpatel@243 826
bpatel@243 827 /**
bpatel@243 828 * Print table caption end tags.
bpatel@243 829 */
bpatel@243 830 public void tableCaptionEnd() {
bpatel@243 831 captionEnd();
bpatel@243 832 }
bpatel@243 833
bpatel@243 834 /**
bpatel@243 835 * Print summary table header.
bpatel@243 836 */
bpatel@243 837 public void summaryTableHeader(String[] header, String scope) {
bpatel@243 838 tr();
bpatel@243 839 for ( int i=0; i < header.length; i++ ) {
bpatel@243 840 thScopeNoWrap("TableHeader", scope);
bpatel@243 841 print(header[i]);
bpatel@243 842 thEnd();
bpatel@243 843 }
bpatel@243 844 trEnd();
bpatel@243 845 }
bpatel@243 846
bpatel@243 847 /**
duke@1 848 * Prine table header information about color, column span and the font.
duke@1 849 *
duke@1 850 * @param color Background color.
duke@1 851 * @param span Column span.
duke@1 852 */
duke@1 853 public void tableHeaderStart(String color, int span) {
duke@1 854 trBgcolorStyle(color, "TableHeadingColor");
duke@1 855 thAlignColspan("left", span);
duke@1 856 font("+2");
duke@1 857 }
duke@1 858
duke@1 859 /**
duke@1 860 * Print table header for the inherited members summary tables. Print the
duke@1 861 * background color information.
duke@1 862 *
duke@1 863 * @param color Background color.
duke@1 864 */
duke@1 865 public void tableInheritedHeaderStart(String color) {
duke@1 866 trBgcolorStyle(color, "TableSubHeadingColor");
duke@1 867 thAlign("left");
duke@1 868 }
duke@1 869
duke@1 870 /**
duke@1 871 * Print "Use" table header. Print the background color and the column span.
duke@1 872 *
duke@1 873 * @param color Background color.
duke@1 874 */
duke@1 875 public void tableUseInfoHeaderStart(String color) {
duke@1 876 trBgcolorStyle(color, "TableSubHeadingColor");
duke@1 877 thAlignColspan("left", 2);
duke@1 878 }
duke@1 879
duke@1 880 /**
duke@1 881 * Print table header with the background color with default column span 2.
duke@1 882 *
duke@1 883 * @param color Background color.
duke@1 884 */
duke@1 885 public void tableHeaderStart(String color) {
duke@1 886 tableHeaderStart(color, 2);
duke@1 887 }
duke@1 888
duke@1 889 /**
duke@1 890 * Print table header with the column span, with the default color #CCCCFF.
duke@1 891 *
duke@1 892 * @param span Column span.
duke@1 893 */
duke@1 894 public void tableHeaderStart(int span) {
duke@1 895 tableHeaderStart("#CCCCFF", span);
duke@1 896 }
duke@1 897
duke@1 898 /**
duke@1 899 * Print table header with default column span 2 and default color #CCCCFF.
duke@1 900 */
duke@1 901 public void tableHeaderStart() {
duke@1 902 tableHeaderStart(2);
duke@1 903 }
duke@1 904
duke@1 905 /**
duke@1 906 * Print table header end tags for font, column and row.
duke@1 907 */
duke@1 908 public void tableHeaderEnd() {
duke@1 909 fontEnd();
duke@1 910 thEnd();
duke@1 911 trEnd();
duke@1 912 }
duke@1 913
duke@1 914 /**
duke@1 915 * Print table header end tags in inherited tables for column and row.
duke@1 916 */
duke@1 917 public void tableInheritedHeaderEnd() {
duke@1 918 thEnd();
duke@1 919 trEnd();
duke@1 920 }
duke@1 921
duke@1 922 /**
duke@1 923 * Print the summary table row cell attribute width.
duke@1 924 *
duke@1 925 * @param width Width of the table cell.
duke@1 926 */
duke@1 927 public void summaryRow(int width) {
duke@1 928 if (width != 0) {
duke@1 929 tdWidth(width + "%");
duke@1 930 } else {
duke@1 931 td();
duke@1 932 }
duke@1 933 }
duke@1 934
duke@1 935 /**
duke@1 936 * Print the summary table row cell end tag.
duke@1 937 */
duke@1 938 public void summaryRowEnd() {
duke@1 939 tdEnd();
duke@1 940 }
duke@1 941
duke@1 942 /**
duke@1 943 * Print the heading in Html &lt;H2> format.
duke@1 944 *
duke@1 945 * @param str The Header string.
duke@1 946 */
duke@1 947 public void printIndexHeading(String str) {
duke@1 948 h2();
duke@1 949 print(str);
duke@1 950 h2End();
duke@1 951 }
duke@1 952
duke@1 953 /**
duke@1 954 * Print Html tag &lt;FRAMESET=arg&gt;.
duke@1 955 *
duke@1 956 * @param arg Argument for the tag.
duke@1 957 */
duke@1 958 public void frameSet(String arg) {
duke@1 959 println("<FRAMESET " + arg + ">");
duke@1 960 }
duke@1 961
duke@1 962 /**
duke@1 963 * Print Html closing tag &lt;/FRAMESET&gt;.
duke@1 964 */
duke@1 965 public void frameSetEnd() {
duke@1 966 println("</FRAMESET>");
duke@1 967 }
duke@1 968
duke@1 969 /**
duke@1 970 * Print Html tag &lt;FRAME=arg&gt;.
duke@1 971 *
duke@1 972 * @param arg Argument for the tag.
duke@1 973 */
duke@1 974 public void frame(String arg) {
duke@1 975 println("<FRAME " + arg + ">");
duke@1 976 }
duke@1 977
duke@1 978 /**
duke@1 979 * Print Html closing tag &lt;/FRAME&gt;.
duke@1 980 */
duke@1 981 public void frameEnd() {
duke@1 982 println("</FRAME>");
duke@1 983 }
duke@1 984
duke@1 985 /**
duke@1 986 * Return path to the class page for a classdoc. For example, the class
duke@1 987 * name is "java.lang.Object" and if the current file getting generated is
duke@1 988 * "java/io/File.html", then the path string to the class, returned is
duke@1 989 * "../../java/lang.Object.html".
duke@1 990 *
duke@1 991 * @param cd Class to which the path is requested.
duke@1 992 */
duke@1 993 protected String pathToClass(ClassDoc cd) {
duke@1 994 return pathString(cd.containingPackage(), cd.name() + ".html");
duke@1 995 }
duke@1 996
duke@1 997 /**
duke@1 998 * Return the path to the class page for a classdoc. Works same as
duke@1 999 * {@link #pathToClass(ClassDoc)}.
duke@1 1000 *
duke@1 1001 * @param cd Class to which the path is requested.
duke@1 1002 * @param name Name of the file(doesn't include path).
duke@1 1003 */
duke@1 1004 protected String pathString(ClassDoc cd, String name) {
duke@1 1005 return pathString(cd.containingPackage(), name);
duke@1 1006 }
duke@1 1007
duke@1 1008 /**
duke@1 1009 * Return path to the given file name in the given package. So if the name
duke@1 1010 * passed is "Object.html" and the name of the package is "java.lang", and
duke@1 1011 * if the relative path is "../.." then returned string will be
duke@1 1012 * "../../java/lang/Object.html"
duke@1 1013 *
duke@1 1014 * @param pd Package in which the file name is assumed to be.
duke@1 1015 * @param name File name, to which path string is.
duke@1 1016 */
duke@1 1017 protected String pathString(PackageDoc pd, String name) {
duke@1 1018 StringBuffer buf = new StringBuffer(relativePath);
duke@1 1019 buf.append(DirectoryManager.getPathToPackage(pd, name));
duke@1 1020 return buf.toString();
duke@1 1021 }
duke@1 1022
duke@1 1023 /**
duke@1 1024 * Print the link to the given package.
duke@1 1025 *
duke@1 1026 * @param pkg the package to link to.
duke@1 1027 * @param label the label for the link.
bpatel@182 1028 * @param isStrong true if the label should be strong.
duke@1 1029 */
bpatel@182 1030 public void printPackageLink(PackageDoc pkg, String label, boolean isStrong) {
bpatel@182 1031 print(getPackageLink(pkg, label, isStrong));
duke@1 1032 }
duke@1 1033
duke@1 1034 /**
duke@1 1035 * Print the link to the given package.
duke@1 1036 *
duke@1 1037 * @param pkg the package to link to.
duke@1 1038 * @param label the label for the link.
bpatel@182 1039 * @param isStrong true if the label should be strong.
duke@1 1040 * @param style the font of the package link label.
duke@1 1041 */
bpatel@182 1042 public void printPackageLink(PackageDoc pkg, String label, boolean isStrong,
duke@1 1043 String style) {
bpatel@182 1044 print(getPackageLink(pkg, label, isStrong, style));
duke@1 1045 }
duke@1 1046
duke@1 1047 /**
duke@1 1048 * Return the link to the given package.
duke@1 1049 *
duke@1 1050 * @param pkg the package to link to.
duke@1 1051 * @param label the label for the link.
bpatel@182 1052 * @param isStrong true if the label should be strong.
duke@1 1053 * @return the link to the given package.
duke@1 1054 */
duke@1 1055 public String getPackageLink(PackageDoc pkg, String label,
bpatel@182 1056 boolean isStrong) {
bpatel@182 1057 return getPackageLink(pkg, label, isStrong, "");
duke@1 1058 }
duke@1 1059
duke@1 1060 /**
duke@1 1061 * Return the link to the given package.
duke@1 1062 *
duke@1 1063 * @param pkg the package to link to.
duke@1 1064 * @param label the label for the link.
bpatel@182 1065 * @param isStrong true if the label should be strong.
duke@1 1066 * @param style the font of the package link label.
duke@1 1067 * @return the link to the given package.
duke@1 1068 */
bpatel@182 1069 public String getPackageLink(PackageDoc pkg, String label, boolean isStrong,
duke@1 1070 String style) {
duke@1 1071 boolean included = pkg != null && pkg.isIncluded();
duke@1 1072 if (! included) {
duke@1 1073 PackageDoc[] packages = configuration.packages;
duke@1 1074 for (int i = 0; i < packages.length; i++) {
duke@1 1075 if (packages[i].equals(pkg)) {
duke@1 1076 included = true;
duke@1 1077 break;
duke@1 1078 }
duke@1 1079 }
duke@1 1080 }
duke@1 1081 if (included || pkg == null) {
duke@1 1082 return getHyperLink(pathString(pkg, "package-summary.html"),
bpatel@182 1083 "", label, isStrong, style);
duke@1 1084 } else {
duke@1 1085 String crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
duke@1 1086 if (crossPkgLink != null) {
bpatel@182 1087 return getHyperLink(crossPkgLink, "", label, isStrong, style);
duke@1 1088 } else {
duke@1 1089 return label;
duke@1 1090 }
duke@1 1091 }
duke@1 1092 }
duke@1 1093
duke@1 1094 public String italicsClassName(ClassDoc cd, boolean qual) {
duke@1 1095 String name = (qual)? cd.qualifiedName(): cd.name();
duke@1 1096 return (cd.isInterface())? italicsText(name): name;
duke@1 1097 }
duke@1 1098
duke@1 1099 public void printSrcLink(ProgramElementDoc d, String label) {
duke@1 1100 if (d == null) {
duke@1 1101 return;
duke@1 1102 }
duke@1 1103 ClassDoc cd = d.containingClass();
duke@1 1104 if (cd == null) {
duke@1 1105 //d must be a class doc since in has no containing class.
duke@1 1106 cd = (ClassDoc) d;
duke@1 1107 }
duke@1 1108 String href = relativePath + DocletConstants.SOURCE_OUTPUT_DIR_NAME
duke@1 1109 + DirectoryManager.getDirectoryPath(cd.containingPackage())
duke@1 1110 + cd.name() + ".html#" + SourceToHTMLConverter.getAnchorName(d);
duke@1 1111 printHyperLink(href, "", label, true);
duke@1 1112 }
duke@1 1113
duke@1 1114 /**
duke@1 1115 * Return the link to the given class.
duke@1 1116 *
duke@1 1117 * @param linkInfo the information about the link.
duke@1 1118 *
duke@1 1119 * @return the link for the given class.
duke@1 1120 */
duke@1 1121 public String getLink(LinkInfoImpl linkInfo) {
duke@1 1122 LinkFactoryImpl factory = new LinkFactoryImpl(this);
duke@1 1123 String link = ((LinkOutputImpl) factory.getLinkOutput(linkInfo)).toString();
duke@1 1124 displayLength += linkInfo.displayLength;
duke@1 1125 return link;
duke@1 1126 }
duke@1 1127
duke@1 1128 /**
duke@1 1129 * Return the type parameters for the given class.
duke@1 1130 *
duke@1 1131 * @param linkInfo the information about the link.
duke@1 1132 * @return the type for the given class.
duke@1 1133 */
duke@1 1134 public String getTypeParameterLinks(LinkInfoImpl linkInfo) {
duke@1 1135 LinkFactoryImpl factory = new LinkFactoryImpl(this);
duke@1 1136 return ((LinkOutputImpl)
duke@1 1137 factory.getTypeParameterLinks(linkInfo, false)).toString();
duke@1 1138 }
duke@1 1139
duke@1 1140 /**
duke@1 1141 * Print the link to the given class.
duke@1 1142 */
duke@1 1143 public void printLink(LinkInfoImpl linkInfo) {
duke@1 1144 print(getLink(linkInfo));
duke@1 1145 }
duke@1 1146
duke@1 1147 /*************************************************************
duke@1 1148 * Return a class cross link to external class documentation.
duke@1 1149 * The name must be fully qualified to determine which package
duke@1 1150 * the class is in. The -link option does not allow users to
duke@1 1151 * link to external classes in the "default" package.
duke@1 1152 *
duke@1 1153 * @param qualifiedClassName the qualified name of the external class.
duke@1 1154 * @param refMemName the name of the member being referenced. This should
duke@1 1155 * be null or empty string if no member is being referenced.
duke@1 1156 * @param label the label for the external link.
bpatel@182 1157 * @param strong true if the link should be strong.
duke@1 1158 * @param style the style of the link.
duke@1 1159 * @param code true if the label should be code font.
duke@1 1160 */
duke@1 1161 public String getCrossClassLink(String qualifiedClassName, String refMemName,
bpatel@182 1162 String label, boolean strong, String style,
duke@1 1163 boolean code) {
duke@1 1164 String className = "",
duke@1 1165 packageName = qualifiedClassName == null ? "" : qualifiedClassName;
duke@1 1166 int periodIndex;
duke@1 1167 while((periodIndex = packageName.lastIndexOf('.')) != -1) {
duke@1 1168 className = packageName.substring(periodIndex + 1, packageName.length()) +
duke@1 1169 (className.length() > 0 ? "." + className : "");
duke@1 1170 String defaultLabel = code ? getCode() + className + getCodeEnd() : className;
duke@1 1171 packageName = packageName.substring(0, periodIndex);
duke@1 1172 if (getCrossPackageLink(packageName) != null) {
duke@1 1173 //The package exists in external documentation, so link to the external
duke@1 1174 //class (assuming that it exists). This is definitely a limitation of
duke@1 1175 //the -link option. There are ways to determine if an external package
duke@1 1176 //exists, but no way to determine if the external class exists. We just
duke@1 1177 //have to assume that it does.
duke@1 1178 return getHyperLink(
duke@1 1179 configuration.extern.getExternalLink(packageName, relativePath,
duke@1 1180 className + ".html?is-external=true"),
duke@1 1181 refMemName == null ? "" : refMemName,
duke@1 1182 label == null || label.length() == 0 ? defaultLabel : label,
bpatel@182 1183 strong, style,
duke@1 1184 configuration.getText("doclet.Href_Class_Or_Interface_Title", packageName),
duke@1 1185 "");
duke@1 1186 }
duke@1 1187 }
duke@1 1188 return null;
duke@1 1189 }
duke@1 1190
duke@1 1191 public boolean isClassLinkable(ClassDoc cd) {
duke@1 1192 if (cd.isIncluded()) {
duke@1 1193 return configuration.isGeneratedDoc(cd);
duke@1 1194 }
duke@1 1195 return configuration.extern.isExternal(cd);
duke@1 1196 }
duke@1 1197
duke@1 1198 public String getCrossPackageLink(String pkgName) {
duke@1 1199 return configuration.extern.getExternalLink(pkgName, relativePath,
duke@1 1200 "package-summary.html?is-external=true");
duke@1 1201 }
duke@1 1202
duke@1 1203 public void printQualifiedClassLink(int context, ClassDoc cd) {
duke@1 1204 printLink(new LinkInfoImpl(context, cd,
duke@1 1205 configuration.getClassName(cd), ""));
duke@1 1206 }
duke@1 1207
duke@1 1208 /**
duke@1 1209 * Print Class link, with only class name as the link and prefixing
duke@1 1210 * plain package name.
duke@1 1211 */
duke@1 1212 public void printPreQualifiedClassLink(int context, ClassDoc cd) {
duke@1 1213 print(getPreQualifiedClassLink(context, cd, false));
duke@1 1214 }
duke@1 1215
duke@1 1216 /**
duke@1 1217 * Retrieve the class link with the package portion of the label in
duke@1 1218 * plain text. If the qualifier is excluded, it willnot be included in the
duke@1 1219 * link label.
duke@1 1220 *
duke@1 1221 * @param cd the class to link to.
bpatel@182 1222 * @param isStrong true if the link should be strong.
duke@1 1223 * @return the link with the package portion of the label in plain text.
duke@1 1224 */
duke@1 1225 public String getPreQualifiedClassLink(int context,
bpatel@182 1226 ClassDoc cd, boolean isStrong) {
duke@1 1227 String classlink = "";
duke@1 1228 PackageDoc pd = cd.containingPackage();
duke@1 1229 if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
duke@1 1230 classlink = getPkgName(cd);
duke@1 1231 }
bpatel@182 1232 classlink += getLink(new LinkInfoImpl(context, cd, cd.name(), isStrong));
duke@1 1233 return classlink;
duke@1 1234 }
duke@1 1235
duke@1 1236
duke@1 1237 /**
bpatel@182 1238 * Print Class link, with only class name as the strong link and prefixing
duke@1 1239 * plain package name.
duke@1 1240 */
bpatel@182 1241 public void printPreQualifiedStrongClassLink(int context, ClassDoc cd) {
duke@1 1242 print(getPreQualifiedClassLink(context, cd, true));
duke@1 1243 }
duke@1 1244
duke@1 1245 public void printText(String key) {
duke@1 1246 print(configuration.getText(key));
duke@1 1247 }
duke@1 1248
duke@1 1249 public void printText(String key, String a1) {
duke@1 1250 print(configuration.getText(key, a1));
duke@1 1251 }
duke@1 1252
duke@1 1253 public void printText(String key, String a1, String a2) {
duke@1 1254 print(configuration.getText(key, a1, a2));
duke@1 1255 }
duke@1 1256
bpatel@182 1257 public void strongText(String key) {
bpatel@182 1258 strong(configuration.getText(key));
duke@1 1259 }
duke@1 1260
bpatel@182 1261 public void strongText(String key, String a1) {
bpatel@182 1262 strong(configuration.getText(key, a1));
duke@1 1263 }
duke@1 1264
bpatel@182 1265 public void strongText(String key, String a1, String a2) {
bpatel@182 1266 strong(configuration.getText(key, a1, a2));
duke@1 1267 }
duke@1 1268
duke@1 1269 /**
duke@1 1270 * Print the link for the given member.
duke@1 1271 *
duke@1 1272 * @param context the id of the context where the link will be printed.
duke@1 1273 * @param doc the member being linked to.
duke@1 1274 * @param label the label for the link.
bpatel@182 1275 * @param strong true if the link should be strong.
duke@1 1276 */
duke@1 1277 public void printDocLink(int context, MemberDoc doc, String label,
bpatel@182 1278 boolean strong) {
bpatel@182 1279 print(getDocLink(context, doc, label, strong));
duke@1 1280 }
duke@1 1281
duke@1 1282 /**
duke@1 1283 * Print the link for the given member.
duke@1 1284 *
duke@1 1285 * @param context the id of the context where the link will be printed.
duke@1 1286 * @param classDoc the classDoc that we should link to. This is not
duke@1 1287 * necessarily equal to doc.containingClass(). We may be
duke@1 1288 * inheriting comments.
duke@1 1289 * @param doc the member being linked to.
duke@1 1290 * @param label the label for the link.
bpatel@182 1291 * @param strong true if the link should be strong.
duke@1 1292 */
duke@1 1293 public void printDocLink(int context, ClassDoc classDoc, MemberDoc doc,
bpatel@182 1294 String label, boolean strong) {
bpatel@182 1295 print(getDocLink(context, classDoc, doc, label, strong));
duke@1 1296 }
duke@1 1297
duke@1 1298 /**
duke@1 1299 * Return the link for the given member.
duke@1 1300 *
duke@1 1301 * @param context the id of the context where the link will be printed.
duke@1 1302 * @param doc the member being linked to.
duke@1 1303 * @param label the label for the link.
bpatel@182 1304 * @param strong true if the link should be strong.
duke@1 1305 * @return the link for the given member.
duke@1 1306 */
duke@1 1307 public String getDocLink(int context, MemberDoc doc, String label,
bpatel@182 1308 boolean strong) {
bpatel@182 1309 return getDocLink(context, doc.containingClass(), doc, label, strong);
duke@1 1310 }
duke@1 1311
duke@1 1312 /**
duke@1 1313 * Return the link for the given member.
duke@1 1314 *
duke@1 1315 * @param context the id of the context where the link will be printed.
duke@1 1316 * @param classDoc the classDoc that we should link to. This is not
duke@1 1317 * necessarily equal to doc.containingClass(). We may be
duke@1 1318 * inheriting comments.
duke@1 1319 * @param doc the member being linked to.
duke@1 1320 * @param label the label for the link.
bpatel@182 1321 * @param strong true if the link should be strong.
duke@1 1322 * @return the link for the given member.
duke@1 1323 */
duke@1 1324 public String getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
bpatel@182 1325 String label, boolean strong) {
duke@1 1326 if (! (doc.isIncluded() ||
duke@1 1327 Util.isLinkable(classDoc, configuration()))) {
duke@1 1328 return label;
duke@1 1329 } else if (doc instanceof ExecutableMemberDoc) {
duke@1 1330 ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
duke@1 1331 return getLink(new LinkInfoImpl(context, classDoc,
bpatel@182 1332 getAnchor(emd), label, strong));
duke@1 1333 } else if (doc instanceof MemberDoc) {
duke@1 1334 return getLink(new LinkInfoImpl(context, classDoc,
bpatel@182 1335 doc.name(), label, strong));
duke@1 1336 } else {
duke@1 1337 return label;
duke@1 1338 }
duke@1 1339 }
duke@1 1340
duke@1 1341 public void anchor(ExecutableMemberDoc emd) {
duke@1 1342 anchor(getAnchor(emd));
duke@1 1343 }
duke@1 1344
duke@1 1345 public String getAnchor(ExecutableMemberDoc emd) {
duke@1 1346 StringBuilder signature = new StringBuilder(emd.signature());
duke@1 1347 StringBuilder signatureParsed = new StringBuilder();
duke@1 1348 int counter = 0;
duke@1 1349 for (int i = 0; i < signature.length(); i++) {
duke@1 1350 char c = signature.charAt(i);
duke@1 1351 if (c == '<') {
duke@1 1352 counter++;
duke@1 1353 } else if (c == '>') {
duke@1 1354 counter--;
duke@1 1355 } else if (counter == 0) {
duke@1 1356 signatureParsed.append(c);
duke@1 1357 }
duke@1 1358 }
duke@1 1359 return emd.name() + signatureParsed.toString();
duke@1 1360 }
duke@1 1361
duke@1 1362 public String seeTagToString(SeeTag see) {
duke@1 1363 String tagName = see.name();
duke@1 1364 if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
duke@1 1365 return "";
duke@1 1366 }
duke@1 1367 StringBuffer result = new StringBuffer();
duke@1 1368 boolean isplaintext = tagName.toLowerCase().equals("@linkplain");
duke@1 1369 String label = see.label();
duke@1 1370 label = (label.length() > 0)?
duke@1 1371 ((isplaintext) ? label :
duke@1 1372 getCode() + label + getCodeEnd()):"";
duke@1 1373 String seetext = replaceDocRootDir(see.text());
duke@1 1374
duke@1 1375 //Check if @see is an href or "string"
duke@1 1376 if (seetext.startsWith("<") || seetext.startsWith("\"")) {
duke@1 1377 result.append(seetext);
duke@1 1378 return result.toString();
duke@1 1379 }
duke@1 1380
duke@1 1381 //The text from the @see tag. We will output this text when a label is not specified.
duke@1 1382 String text = (isplaintext) ? seetext : getCode() + seetext + getCodeEnd();
duke@1 1383
duke@1 1384 ClassDoc refClass = see.referencedClass();
duke@1 1385 String refClassName = see.referencedClassName();
duke@1 1386 MemberDoc refMem = see.referencedMember();
duke@1 1387 String refMemName = see.referencedMemberName();
duke@1 1388 if (refClass == null) {
duke@1 1389 //@see is not referencing an included class
duke@1 1390 PackageDoc refPackage = see.referencedPackage();
duke@1 1391 if (refPackage != null && refPackage.isIncluded()) {
duke@1 1392 //@see is referencing an included package
duke@1 1393 String packageName = isplaintext ? refPackage.name() :
duke@1 1394 getCode() + refPackage.name() + getCodeEnd();
duke@1 1395 result.append(getPackageLink(refPackage,
duke@1 1396 label.length() == 0 ? packageName : label, false));
duke@1 1397 } else {
duke@1 1398 //@see is not referencing an included class or package. Check for cross links.
duke@1 1399 String classCrossLink, packageCrossLink = getCrossPackageLink(refClassName);
duke@1 1400 if (packageCrossLink != null) {
duke@1 1401 //Package cross link found
duke@1 1402 result.append(getHyperLink(packageCrossLink, "",
duke@1 1403 (label.length() == 0)? text : label, false));
duke@1 1404 } else if ((classCrossLink = getCrossClassLink(refClassName,
duke@1 1405 refMemName, label, false, "", ! isplaintext)) != null) {
duke@1 1406 //Class cross link found (possiblly to a member in the class)
duke@1 1407 result.append(classCrossLink);
duke@1 1408 } else {
duke@1 1409 //No cross link found so print warning
duke@1 1410 configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
duke@1 1411 tagName, seetext);
duke@1 1412 result.append((label.length() == 0)? text: label);
duke@1 1413 }
duke@1 1414 }
duke@1 1415 } else if (refMemName == null) {
duke@1 1416 // Must be a class reference since refClass is not null and refMemName is null.
duke@1 1417 if (label.length() == 0) {
duke@1 1418 label = (isplaintext) ? refClass.name() : getCode() + refClass.name() + getCodeEnd();
duke@1 1419 result.append(getLink(new LinkInfoImpl(refClass, label)));
duke@1 1420 } else {
duke@1 1421 result.append(getLink(new LinkInfoImpl(refClass, label)));
duke@1 1422 }
duke@1 1423 } else if (refMem == null) {
duke@1 1424 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 1425 // However, refMem is null, so this referenced member does not exist.
duke@1 1426 result.append((label.length() == 0)? text: label);
duke@1 1427 } else {
duke@1 1428 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 1429 // refMem is not null, so this @see tag must be referencing a valid member.
duke@1 1430 ClassDoc containing = refMem.containingClass();
duke@1 1431 if (see.text().trim().startsWith("#") &&
duke@1 1432 ! (containing.isPublic() ||
duke@1 1433 Util.isLinkable(containing, configuration()))) {
duke@1 1434 // Since the link is relative and the holder is not even being
duke@1 1435 // documented, this must be an inherited link. Redirect it.
duke@1 1436 // The current class either overrides the referenced member or
duke@1 1437 // inherits it automatically.
jjg@405 1438 if (this instanceof ClassWriterImpl) {
jjg@405 1439 containing = ((ClassWriterImpl) this).getClassDoc();
jjg@405 1440 } else if (!containing.isPublic()){
jjg@405 1441 configuration.getDocletSpecificMsg().warning(
jjg@405 1442 see.position(), "doclet.see.class_or_package_not_accessible",
jjg@405 1443 tagName, containing.qualifiedName());
jjg@405 1444 } else {
jjg@405 1445 configuration.getDocletSpecificMsg().warning(
jjg@405 1446 see.position(), "doclet.see.class_or_package_not_found",
jjg@405 1447 tagName, seetext);
jjg@405 1448 }
duke@1 1449 }
duke@1 1450 if (configuration.currentcd != containing) {
duke@1 1451 refMemName = containing.name() + "." + refMemName;
duke@1 1452 }
duke@1 1453 if (refMem instanceof ExecutableMemberDoc) {
duke@1 1454 if (refMemName.indexOf('(') < 0) {
duke@1 1455 refMemName += ((ExecutableMemberDoc)refMem).signature();
duke@1 1456 }
duke@1 1457 }
duke@1 1458 text = (isplaintext) ?
duke@1 1459 refMemName : getCode() + refMemName + getCodeEnd();
duke@1 1460
duke@1 1461 result.append(getDocLink(LinkInfoImpl.CONTEXT_SEE_TAG, containing,
duke@1 1462 refMem, (label.length() == 0)? text: label, false));
duke@1 1463 }
duke@1 1464 return result.toString();
duke@1 1465 }
duke@1 1466
duke@1 1467 public void printInlineComment(Doc doc, Tag tag) {
duke@1 1468 printCommentTags(doc, tag.inlineTags(), false, false);
duke@1 1469 }
duke@1 1470
duke@1 1471 public void printInlineDeprecatedComment(Doc doc, Tag tag) {
duke@1 1472 printCommentTags(doc, tag.inlineTags(), true, false);
duke@1 1473 }
duke@1 1474
duke@1 1475 public void printSummaryComment(Doc doc) {
duke@1 1476 printSummaryComment(doc, doc.firstSentenceTags());
duke@1 1477 }
duke@1 1478
duke@1 1479 public void printSummaryComment(Doc doc, Tag[] firstSentenceTags) {
duke@1 1480 printCommentTags(doc, firstSentenceTags, false, true);
duke@1 1481 }
duke@1 1482
duke@1 1483 public void printSummaryDeprecatedComment(Doc doc) {
duke@1 1484 printCommentTags(doc, doc.firstSentenceTags(), true, true);
duke@1 1485 }
duke@1 1486
duke@1 1487 public void printSummaryDeprecatedComment(Doc doc, Tag tag) {
duke@1 1488 printCommentTags(doc, tag.firstSentenceTags(), true, true);
duke@1 1489 }
duke@1 1490
duke@1 1491 public void printInlineComment(Doc doc) {
duke@1 1492 printCommentTags(doc, doc.inlineTags(), false, false);
duke@1 1493 p();
duke@1 1494 }
duke@1 1495
duke@1 1496 public void printInlineDeprecatedComment(Doc doc) {
duke@1 1497 printCommentTags(doc, doc.inlineTags(), true, false);
duke@1 1498 }
duke@1 1499
duke@1 1500 private void printCommentTags(Doc doc, Tag[] tags, boolean depr, boolean first) {
duke@1 1501 if(configuration.nocomment){
duke@1 1502 return;
duke@1 1503 }
duke@1 1504 if (depr) {
duke@1 1505 italic();
duke@1 1506 }
duke@1 1507 String result = commentTagsToString(null, doc, tags, first);
duke@1 1508 print(result);
duke@1 1509 if (depr) {
duke@1 1510 italicEnd();
duke@1 1511 }
duke@1 1512 if (tags.length == 0) {
duke@1 1513 space();
duke@1 1514 }
duke@1 1515 }
duke@1 1516
duke@1 1517 /**
duke@1 1518 * Converts inline tags and text to text strings, expanding the
duke@1 1519 * inline tags along the way. Called wherever text can contain
duke@1 1520 * an inline tag, such as in comments or in free-form text arguments
duke@1 1521 * to non-inline tags.
duke@1 1522 *
duke@1 1523 * @param holderTag specific tag where comment resides
duke@1 1524 * @param doc specific doc where comment resides
duke@1 1525 * @param tags array of text tags and inline tags (often alternating)
duke@1 1526 * present in the text of interest for this doc
duke@1 1527 * @param isFirstSentence true if text is first sentence
duke@1 1528 */
duke@1 1529 public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
duke@1 1530 boolean isFirstSentence) {
duke@1 1531 StringBuffer result = new StringBuffer();
duke@1 1532 // Array of all possible inline tags for this javadoc run
duke@1 1533 configuration.tagletManager.checkTags(doc, tags, true);
duke@1 1534 for (int i = 0; i < tags.length; i++) {
duke@1 1535 Tag tagelem = tags[i];
duke@1 1536 String tagName = tagelem.name();
duke@1 1537 if (tagelem instanceof SeeTag) {
duke@1 1538 result.append(seeTagToString((SeeTag)tagelem));
duke@1 1539 } else if (! tagName.equals("Text")) {
duke@1 1540 int originalLength = result.length();
duke@1 1541 TagletOutput output = TagletWriter.getInlineTagOuput(
duke@1 1542 configuration.tagletManager, holderTag,
jjg@74 1543 tagelem, getTagletWriterInstance(isFirstSentence));
duke@1 1544 result.append(output == null ? "" : output.toString());
duke@1 1545 if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
duke@1 1546 break;
duke@1 1547 } else {
duke@1 1548 continue;
duke@1 1549 }
duke@1 1550 } else {
duke@1 1551 //This is just a regular text tag. The text may contain html links (<a>)
duke@1 1552 //or inline tag {@docRoot}, which will be handled as special cases.
duke@1 1553 String text = redirectRelativeLinks(tagelem.holder(), tagelem.text());
duke@1 1554
duke@1 1555 // Replace @docRoot only if not represented by an instance of DocRootTaglet,
duke@1 1556 // that is, only if it was not present in a source file doc comment.
duke@1 1557 // This happens when inserted by the doclet (a few lines
duke@1 1558 // above in this method). [It might also happen when passed in on the command
duke@1 1559 // line as a text argument to an option (like -header).]
duke@1 1560 text = replaceDocRootDir(text);
duke@1 1561 if (isFirstSentence) {
duke@1 1562 text = removeNonInlineHtmlTags(text);
duke@1 1563 }
duke@1 1564 StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
duke@1 1565 StringBuffer textBuff = new StringBuffer();
duke@1 1566 while (lines.hasMoreTokens()) {
duke@1 1567 StringBuffer line = new StringBuffer(lines.nextToken());
duke@1 1568 Util.replaceTabs(configuration.sourcetab, line);
duke@1 1569 textBuff.append(line.toString());
duke@1 1570 }
duke@1 1571 result.append(textBuff);
duke@1 1572 }
duke@1 1573 }
duke@1 1574 return result.toString();
duke@1 1575 }
duke@1 1576
duke@1 1577 /**
duke@1 1578 * Return true if relative links should not be redirected.
duke@1 1579 *
duke@1 1580 * @return Return true if a relative link should not be redirected.
duke@1 1581 */
duke@1 1582 private boolean shouldNotRedirectRelativeLinks() {
duke@1 1583 return this instanceof AnnotationTypeWriter ||
duke@1 1584 this instanceof ClassWriter ||
duke@1 1585 this instanceof PackageSummaryWriter;
duke@1 1586 }
duke@1 1587
duke@1 1588 /**
duke@1 1589 * Suppose a piece of documentation has a relative link. When you copy
duke@1 1590 * that documetation to another place such as the index or class-use page,
duke@1 1591 * that relative link will no longer work. We should redirect those links
duke@1 1592 * so that they will work again.
duke@1 1593 * <p>
duke@1 1594 * Here is the algorithm used to fix the link:
duke@1 1595 * <p>
duke@1 1596 * &lt;relative link&gt; => docRoot + &lt;relative path to file&gt; + &lt;relative link&gt;
duke@1 1597 * <p>
duke@1 1598 * For example, suppose com.sun.javadoc.RootDoc has this link:
duke@1 1599 * &lt;a href="package-summary.html"&gt;The package Page&lt;/a&gt;
duke@1 1600 * <p>
duke@1 1601 * If this link appeared in the index, we would redirect
duke@1 1602 * the link like this:
duke@1 1603 *
duke@1 1604 * &lt;a href="./com/sun/javadoc/package-summary.html"&gt;The package Page&lt;/a&gt;
duke@1 1605 *
duke@1 1606 * @param doc the Doc object whose documentation is being written.
duke@1 1607 * @param text the text being written.
duke@1 1608 *
duke@1 1609 * @return the text, with all the relative links redirected to work.
duke@1 1610 */
duke@1 1611 private String redirectRelativeLinks(Doc doc, String text) {
duke@1 1612 if (doc == null || shouldNotRedirectRelativeLinks()) {
duke@1 1613 return text;
duke@1 1614 }
duke@1 1615
duke@1 1616 String redirectPathFromRoot;
duke@1 1617 if (doc instanceof ClassDoc) {
duke@1 1618 redirectPathFromRoot = DirectoryManager.getDirectoryPath(((ClassDoc) doc).containingPackage());
duke@1 1619 } else if (doc instanceof MemberDoc) {
duke@1 1620 redirectPathFromRoot = DirectoryManager.getDirectoryPath(((MemberDoc) doc).containingPackage());
duke@1 1621 } else if (doc instanceof PackageDoc) {
duke@1 1622 redirectPathFromRoot = DirectoryManager.getDirectoryPath((PackageDoc) doc);
duke@1 1623 } else {
duke@1 1624 return text;
duke@1 1625 }
duke@1 1626
duke@1 1627 if (! redirectPathFromRoot.endsWith(DirectoryManager.URL_FILE_SEPERATOR)) {
duke@1 1628 redirectPathFromRoot += DirectoryManager.URL_FILE_SEPERATOR;
duke@1 1629 }
duke@1 1630
duke@1 1631 //Redirect all relative links.
duke@1 1632 int end, begin = text.toLowerCase().indexOf("<a");
duke@1 1633 if(begin >= 0){
duke@1 1634 StringBuffer textBuff = new StringBuffer(text);
duke@1 1635
duke@1 1636 while(begin >=0){
duke@1 1637 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
duke@1 1638 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 1639 continue;
duke@1 1640 }
duke@1 1641
duke@1 1642 begin = textBuff.indexOf("=", begin) + 1;
duke@1 1643 end = textBuff.indexOf(">", begin +1);
duke@1 1644 if(begin == 0){
duke@1 1645 //Link has no equal symbol.
duke@1 1646 configuration.root.printWarning(
duke@1 1647 doc.position(),
duke@1 1648 configuration.getText("doclet.malformed_html_link_tag", text));
duke@1 1649 break;
duke@1 1650 }
duke@1 1651 if (end == -1) {
duke@1 1652 //Break without warning. This <a> tag is not necessarily malformed. The text
duke@1 1653 //might be missing '>' character because the href has an inline tag.
duke@1 1654 break;
duke@1 1655 }
duke@1 1656 if(textBuff.substring(begin, end).indexOf("\"") != -1){
duke@1 1657 begin = textBuff.indexOf("\"", begin) + 1;
duke@1 1658 end = textBuff.indexOf("\"", begin +1);
duke@1 1659 if(begin == 0 || end == -1){
duke@1 1660 //Link is missing a quote.
duke@1 1661 break;
duke@1 1662 }
duke@1 1663 }
duke@1 1664 String relativeLink = textBuff.substring(begin, end);
duke@1 1665 if(!(relativeLink.toLowerCase().startsWith("mailto:") ||
duke@1 1666 relativeLink.toLowerCase().startsWith("http:") ||
duke@1 1667 relativeLink.toLowerCase().startsWith("https:") ||
duke@1 1668 relativeLink.toLowerCase().startsWith("file:"))){
duke@1 1669 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}"
duke@1 1670 + redirectPathFromRoot
duke@1 1671 + relativeLink;
duke@1 1672 textBuff.replace(begin, end, relativeLink);
duke@1 1673 }
duke@1 1674 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 1675 }
duke@1 1676 return textBuff.toString();
duke@1 1677 }
duke@1 1678 return text;
duke@1 1679 }
duke@1 1680
duke@1 1681 public String removeNonInlineHtmlTags(String text) {
duke@1 1682 if (text.indexOf('<') < 0) {
duke@1 1683 return text;
duke@1 1684 }
duke@1 1685 String noninlinetags[] = { "<ul>", "</ul>", "<ol>", "</ol>",
duke@1 1686 "<dl>", "</dl>", "<table>", "</table>",
duke@1 1687 "<tr>", "</tr>", "<td>", "</td>",
duke@1 1688 "<th>", "</th>", "<p>", "</p>",
duke@1 1689 "<li>", "</li>", "<dd>", "</dd>",
duke@1 1690 "<dir>", "</dir>", "<dt>", "</dt>",
duke@1 1691 "<h1>", "</h1>", "<h2>", "</h2>",
duke@1 1692 "<h3>", "</h3>", "<h4>", "</h4>",
duke@1 1693 "<h5>", "</h5>", "<h6>", "</h6>",
duke@1 1694 "<pre>", "</pre>", "<menu>", "</menu>",
duke@1 1695 "<listing>", "</listing>", "<hr>",
duke@1 1696 "<blockquote>", "</blockquote>",
duke@1 1697 "<center>", "</center>",
duke@1 1698 "<UL>", "</UL>", "<OL>", "</OL>",
duke@1 1699 "<DL>", "</DL>", "<TABLE>", "</TABLE>",
duke@1 1700 "<TR>", "</TR>", "<TD>", "</TD>",
duke@1 1701 "<TH>", "</TH>", "<P>", "</P>",
duke@1 1702 "<LI>", "</LI>", "<DD>", "</DD>",
duke@1 1703 "<DIR>", "</DIR>", "<DT>", "</DT>",
duke@1 1704 "<H1>", "</H1>", "<H2>", "</H2>",
duke@1 1705 "<H3>", "</H3>", "<H4>", "</H4>",
duke@1 1706 "<H5>", "</H5>", "<H6>", "</H6>",
duke@1 1707 "<PRE>", "</PRE>", "<MENU>", "</MENU>",
duke@1 1708 "<LISTING>", "</LISTING>", "<HR>",
duke@1 1709 "<BLOCKQUOTE>", "</BLOCKQUOTE>",
duke@1 1710 "<CENTER>", "</CENTER>"
duke@1 1711 };
duke@1 1712 for (int i = 0; i < noninlinetags.length; i++) {
duke@1 1713 text = replace(text, noninlinetags[i], "");
duke@1 1714 }
duke@1 1715 return text;
duke@1 1716 }
duke@1 1717
duke@1 1718 public String replace(String text, String tobe, String by) {
duke@1 1719 while (true) {
duke@1 1720 int startindex = text.indexOf(tobe);
duke@1 1721 if (startindex < 0) {
duke@1 1722 return text;
duke@1 1723 }
duke@1 1724 int endindex = startindex + tobe.length();
duke@1 1725 StringBuffer replaced = new StringBuffer();
duke@1 1726 if (startindex > 0) {
duke@1 1727 replaced.append(text.substring(0, startindex));
duke@1 1728 }
duke@1 1729 replaced.append(by);
duke@1 1730 if (text.length() > endindex) {
duke@1 1731 replaced.append(text.substring(endindex));
duke@1 1732 }
duke@1 1733 text = replaced.toString();
duke@1 1734 }
duke@1 1735 }
duke@1 1736
duke@1 1737 public void printStyleSheetProperties() {
duke@1 1738 String filename = configuration.stylesheetfile;
duke@1 1739 if (filename.length() > 0) {
duke@1 1740 File stylefile = new File(filename);
duke@1 1741 String parent = stylefile.getParent();
duke@1 1742 filename = (parent == null)?
duke@1 1743 filename:
duke@1 1744 filename.substring(parent.length() + 1);
duke@1 1745 } else {
duke@1 1746 filename = "stylesheet.css";
duke@1 1747 }
duke@1 1748 filename = relativePath + filename;
duke@1 1749 link("REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"" +
duke@1 1750 filename + "\" " + "TITLE=\"Style\"");
duke@1 1751 }
duke@1 1752
duke@1 1753 /**
duke@1 1754 * According to the Java Language Specifications, all the outer classes
duke@1 1755 * and static nested classes are core classes.
duke@1 1756 */
duke@1 1757 public boolean isCoreClass(ClassDoc cd) {
duke@1 1758 return cd.containingClass() == null || cd.isStatic();
duke@1 1759 }
duke@1 1760
duke@1 1761 /**
duke@1 1762 * Write the annotatation types for the given packageDoc.
duke@1 1763 *
duke@1 1764 * @param packageDoc the package to write annotations for.
duke@1 1765 */
duke@1 1766 public void writeAnnotationInfo(PackageDoc packageDoc) {
duke@1 1767 writeAnnotationInfo(packageDoc, packageDoc.annotations());
duke@1 1768 }
duke@1 1769
duke@1 1770 /**
duke@1 1771 * Write the annotatation types for the given doc.
duke@1 1772 *
duke@1 1773 * @param doc the doc to write annotations for.
duke@1 1774 */
duke@1 1775 public void writeAnnotationInfo(ProgramElementDoc doc) {
duke@1 1776 writeAnnotationInfo(doc, doc.annotations());
duke@1 1777 }
duke@1 1778
duke@1 1779 /**
duke@1 1780 * Write the annotatation types for the given doc and parameter.
duke@1 1781 *
duke@1 1782 * @param indent the number of spaced to indent the parameters.
duke@1 1783 * @param doc the doc to write annotations for.
duke@1 1784 * @param param the parameter to write annotations for.
duke@1 1785 */
duke@1 1786 public boolean writeAnnotationInfo(int indent, Doc doc, Parameter param) {
duke@1 1787 return writeAnnotationInfo(indent, doc, param.annotations(), false);
duke@1 1788 }
duke@1 1789
duke@1 1790 /**
duke@1 1791 * Write the annotatation types for the given doc.
duke@1 1792 *
duke@1 1793 * @param doc the doc to write annotations for.
duke@1 1794 * @param descList the array of {@link AnnotationDesc}.
duke@1 1795 */
duke@1 1796 private void writeAnnotationInfo(Doc doc, AnnotationDesc[] descList) {
duke@1 1797 writeAnnotationInfo(0, doc, descList, true);
duke@1 1798 }
duke@1 1799
duke@1 1800 /**
duke@1 1801 * Write the annotatation types for the given doc.
duke@1 1802 *
duke@1 1803 * @param indent the number of extra spaces to indent the annotations.
duke@1 1804 * @param doc the doc to write annotations for.
duke@1 1805 * @param descList the array of {@link AnnotationDesc}.
duke@1 1806 */
duke@1 1807 private boolean writeAnnotationInfo(int indent, Doc doc, AnnotationDesc[] descList, boolean lineBreak) {
mcimadamore@184 1808 List<String> annotations = getAnnotations(indent, descList, lineBreak);
duke@1 1809 if (annotations.size() == 0) {
duke@1 1810 return false;
duke@1 1811 }
duke@1 1812 fontNoNewLine("-1");
mcimadamore@184 1813 for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
mcimadamore@184 1814 print(iter.next());
duke@1 1815 }
duke@1 1816 fontEnd();
duke@1 1817 return true;
duke@1 1818 }
duke@1 1819
duke@1 1820 /**
duke@1 1821 * Return the string representations of the annotation types for
duke@1 1822 * the given doc.
duke@1 1823 *
duke@1 1824 * @param indent the number of extra spaces to indent the annotations.
duke@1 1825 * @param descList the array of {@link AnnotationDesc}.
duke@1 1826 * @param linkBreak if true, add new line between each member value.
duke@1 1827 * @return an array of strings representing the annotations being
duke@1 1828 * documented.
duke@1 1829 */
jjg@74 1830 private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
jjg@74 1831 List<String> results = new ArrayList<String>();
duke@1 1832 StringBuffer annotation;
duke@1 1833 for (int i = 0; i < descList.length; i++) {
duke@1 1834 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
duke@1 1835 if (! Util.isDocumentedAnnotation(annotationDoc)){
duke@1 1836 continue;
duke@1 1837 }
duke@1 1838 annotation = new StringBuffer();
duke@1 1839 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 1840 LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc);
duke@1 1841 linkInfo.label = "@" + annotationDoc.name();
duke@1 1842 annotation.append(getLink(linkInfo));
duke@1 1843 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
duke@1 1844 if (pairs.length > 0) {
duke@1 1845 annotation.append('(');
duke@1 1846 for (int j = 0; j < pairs.length; j++) {
duke@1 1847 if (j > 0) {
duke@1 1848 annotation.append(",");
duke@1 1849 if (linkBreak) {
duke@1 1850 annotation.append(DocletConstants.NL);
duke@1 1851 int spaces = annotationDoc.name().length() + 2;
duke@1 1852 for (int k = 0; k < (spaces + indent); k++) {
duke@1 1853 annotation.append(' ');
duke@1 1854 }
duke@1 1855 }
duke@1 1856 }
duke@1 1857 annotation.append(getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
duke@1 1858 pairs[j].element(), pairs[j].element().name(), false));
duke@1 1859 annotation.append('=');
duke@1 1860 AnnotationValue annotationValue = pairs[j].value();
jjg@74 1861 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
duke@1 1862 if (annotationValue.value() instanceof AnnotationValue[]) {
duke@1 1863 AnnotationValue[] annotationArray =
duke@1 1864 (AnnotationValue[]) annotationValue.value();
duke@1 1865 for (int k = 0; k < annotationArray.length; k++) {
duke@1 1866 annotationTypeValues.add(annotationArray[k]);
duke@1 1867 }
duke@1 1868 } else {
duke@1 1869 annotationTypeValues.add(annotationValue);
duke@1 1870 }
duke@1 1871 annotation.append(annotationTypeValues.size() == 1 ? "" : "{");
mcimadamore@184 1872 for (Iterator<AnnotationValue> iter = annotationTypeValues.iterator(); iter.hasNext(); ) {
mcimadamore@184 1873 annotation.append(annotationValueToString(iter.next()));
duke@1 1874 annotation.append(iter.hasNext() ? "," : "");
duke@1 1875 }
duke@1 1876 annotation.append(annotationTypeValues.size() == 1 ? "" : "}");
duke@1 1877 }
duke@1 1878 annotation.append(")");
duke@1 1879 }
duke@1 1880 annotation.append(linkBreak ? DocletConstants.NL : "");
duke@1 1881 results.add(annotation.toString());
duke@1 1882 }
duke@1 1883 return results;
duke@1 1884 }
duke@1 1885
duke@1 1886 private String annotationValueToString(AnnotationValue annotationValue) {
duke@1 1887 if (annotationValue.value() instanceof Type) {
duke@1 1888 Type type = (Type) annotationValue.value();
duke@1 1889 if (type.asClassDoc() != null) {
duke@1 1890 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 1891 LinkInfoImpl.CONTEXT_ANNOTATION, type);
duke@1 1892 linkInfo.label = (type.asClassDoc().isIncluded() ?
duke@1 1893 type.typeName() :
duke@1 1894 type.qualifiedTypeName()) + type.dimension() + ".class";
duke@1 1895 return getLink(linkInfo);
duke@1 1896 } else {
duke@1 1897 return type.typeName() + type.dimension() + ".class";
duke@1 1898 }
duke@1 1899 } else if (annotationValue.value() instanceof AnnotationDesc) {
mcimadamore@184 1900 List<String> list = getAnnotations(0,
duke@1 1901 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
duke@1 1902 false);
duke@1 1903 StringBuffer buf = new StringBuffer();
mcimadamore@184 1904 for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
duke@1 1905 buf.append(iter.next());
duke@1 1906 }
duke@1 1907 return buf.toString();
duke@1 1908 } else if (annotationValue.value() instanceof MemberDoc) {
duke@1 1909 return getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
duke@1 1910 (MemberDoc) annotationValue.value(),
duke@1 1911 ((MemberDoc) annotationValue.value()).name(), false);
duke@1 1912 } else {
duke@1 1913 return annotationValue.toString();
duke@1 1914 }
duke@1 1915 }
duke@1 1916
duke@1 1917 /**
duke@1 1918 * Return the configuation for this doclet.
duke@1 1919 *
duke@1 1920 * @return the configuration for this doclet.
duke@1 1921 */
duke@1 1922 public Configuration configuration() {
duke@1 1923 return configuration;
duke@1 1924 }
duke@1 1925 }

mercurial