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

Fri, 27 Feb 2009 18:57:17 -0800

author
bpatel
date
Fri, 27 Feb 2009 18:57:17 -0800
changeset 233
5240b1120530
parent 222
d424ed561993
child 240
8c55d5b0ed71
permissions
-rw-r--r--

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

mercurial