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

Wed, 18 Feb 2009 13:47:27 -0800

author
bpatel
date
Wed, 18 Feb 2009 13:47:27 -0800
changeset 222
d424ed561993
parent 184
905e151a185a
child 229
03bcd66bd8e7
child 233
5240b1120530
permissions
-rw-r--r--

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

mercurial