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

Thu, 08 Jan 2009 16:26:59 -0800

author
bpatel
date
Thu, 08 Jan 2009 16:26:59 -0800
changeset 182
47a62d8d98b4
parent 117
24a47c3062fe
child 184
905e151a185a
permissions
-rw-r--r--

6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
Reviewed-by: jjg

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

mercurial