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

Wed, 10 Oct 2012 18:34:46 -0700

author
jjg
date
Wed, 10 Oct 2012 18:34:46 -0700
changeset 1361
6517bf8e50d0
parent 1359
25e14ad23cef
child 1362
c46e0c9940d6
permissions
-rw-r--r--

8000418: javadoc should used a standard "generated by javadoc" string
Reviewed-by: bpatel

duke@1 1 /*
jjg@1326 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
duke@1 28 import java.io.*;
duke@1 29 import java.text.SimpleDateFormat;
duke@1 30 import java.util.*;
duke@1 31
bpatel@233 32 import com.sun.javadoc.*;
bpatel@233 33 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@233 34 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1357 35 import com.sun.tools.doclets.internal.toolkit.taglets.*;
bpatel@233 36 import com.sun.tools.doclets.internal.toolkit.util.*;
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 *
jjg@1359 43 * <p><b>This is NOT part of any supported API.
jjg@1359 44 * If you write code that depends on this, you do so at your own risk.
jjg@1359 45 * This code and its internal interfaces are subject to change or
jjg@1359 46 * deletion without notice.</b>
jjg@1359 47 *
duke@1 48 * @since 1.2
duke@1 49 * @author Atul M Dambalkar
duke@1 50 * @author Robert Field
bpatel@233 51 * @author Bhavesh Patel (Modified)
duke@1 52 */
duke@1 53 public class HtmlDocletWriter extends HtmlDocWriter {
duke@1 54
duke@1 55 /**
duke@1 56 * Relative path from the file getting generated to the destination
duke@1 57 * directory. For example, if the file getting generated is
duke@1 58 * "java/lang/Object.html", then the relative path string is "../../".
duke@1 59 * This string can be empty if the file getting generated is in
duke@1 60 * the destination directory.
duke@1 61 */
duke@1 62 public String relativePath = "";
duke@1 63
duke@1 64 /**
duke@1 65 * Same as relativepath, but normalized to never be empty or
duke@1 66 * end with a slash.
duke@1 67 */
duke@1 68 public String relativepathNoSlash = "";
duke@1 69
duke@1 70 /**
duke@1 71 * Platform-dependent directory path from the current or the
duke@1 72 * destination directory to the file getting generated.
duke@1 73 * Used when creating the file.
duke@1 74 * For example, if the file getting generated is
duke@1 75 * "java/lang/Object.html", then the path string is "java/lang".
duke@1 76 */
duke@1 77 public String path = "";
duke@1 78
duke@1 79 /**
duke@1 80 * Name of the file getting generated. If the file getting generated is
duke@1 81 * "java/lang/Object.html", then the filename is "Object.html".
duke@1 82 */
duke@1 83 public String filename = "";
duke@1 84
duke@1 85 /**
duke@1 86 * The display length used for indentation while generating the class page.
duke@1 87 */
duke@1 88 public int displayLength = 0;
duke@1 89
duke@1 90 /**
duke@1 91 * The global configuration information for this run.
duke@1 92 */
duke@1 93 public ConfigurationImpl configuration;
duke@1 94
duke@1 95 /**
bpatel@766 96 * To check whether annotation heading is printed or not.
bpatel@766 97 */
bpatel@766 98 protected boolean printedAnnotationHeading = false;
bpatel@766 99
bpatel@766 100 /**
duke@1 101 * Constructor to construct the HtmlStandardWriter object.
duke@1 102 *
duke@1 103 * @param filename File to be generated.
duke@1 104 */
duke@1 105 public HtmlDocletWriter(ConfigurationImpl configuration,
duke@1 106 String filename) throws IOException {
duke@1 107 super(configuration, filename);
duke@1 108 this.configuration = configuration;
duke@1 109 this.filename = filename;
duke@1 110 }
duke@1 111
duke@1 112 /**
duke@1 113 * Constructor to construct the HtmlStandardWriter object.
duke@1 114 *
duke@1 115 * @param path Platform-dependent {@link #path} used when
duke@1 116 * creating file.
duke@1 117 * @param filename Name of file to be generated.
duke@1 118 * @param relativePath Value for the variable {@link #relativePath}.
duke@1 119 */
duke@1 120 public HtmlDocletWriter(ConfigurationImpl configuration,
duke@1 121 String path, String filename,
duke@1 122 String relativePath) throws IOException {
duke@1 123 super(configuration, path, filename);
duke@1 124 this.configuration = configuration;
duke@1 125 this.path = path;
duke@1 126 this.relativePath = relativePath;
duke@1 127 this.relativepathNoSlash =
duke@1 128 DirectoryManager.getPathNoTrailingSlash(this.relativePath);
duke@1 129 this.filename = filename;
duke@1 130 }
duke@1 131
duke@1 132 /**
duke@1 133 * Replace {&#064;docRoot} tag used in options that accept HTML text, such
duke@1 134 * as -header, -footer, -top and -bottom, and when converting a relative
duke@1 135 * HREF where commentTagsToString inserts a {&#064;docRoot} where one was
duke@1 136 * missing. (Also see DocRootTaglet for {&#064;docRoot} tags in doc
duke@1 137 * comments.)
duke@1 138 * <p>
duke@1 139 * Replace {&#064;docRoot} tag in htmlstr with the relative path to the
duke@1 140 * destination directory from the directory where the file is being
duke@1 141 * written, looping to handle all such tags in htmlstr.
duke@1 142 * <p>
duke@1 143 * For example, for "-d docs" and -header containing {&#064;docRoot}, when
duke@1 144 * the HTML page for source file p/C1.java is being generated, the
duke@1 145 * {&#064;docRoot} tag would be inserted into the header as "../",
duke@1 146 * the relative path from docs/p/ to docs/ (the document root).
duke@1 147 * <p>
duke@1 148 * Note: This doc comment was written with '&amp;#064;' representing '@'
duke@1 149 * to prevent the inline tag from being interpreted.
duke@1 150 */
duke@1 151 public String replaceDocRootDir(String htmlstr) {
duke@1 152 // Return if no inline tags exist
duke@1 153 int index = htmlstr.indexOf("{@");
duke@1 154 if (index < 0) {
duke@1 155 return htmlstr;
duke@1 156 }
duke@1 157 String lowerHtml = htmlstr.toLowerCase();
duke@1 158 // Return index of first occurrence of {@docroot}
duke@1 159 // Note: {@docRoot} is not case sensitive when passed in w/command line option
duke@1 160 index = lowerHtml.indexOf("{@docroot}", index);
duke@1 161 if (index < 0) {
duke@1 162 return htmlstr;
duke@1 163 }
jjg@910 164 StringBuilder buf = new StringBuilder();
duke@1 165 int previndex = 0;
duke@1 166 while (true) {
bpatel@997 167 if (configuration.docrootparent.length() > 0) {
bpatel@997 168 // Search for lowercase version of {@docRoot}/..
bpatel@997 169 index = lowerHtml.indexOf("{@docroot}/..", previndex);
bpatel@997 170 // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
bpatel@997 171 if (index < 0) {
bpatel@997 172 buf.append(htmlstr.substring(previndex));
bpatel@997 173 break;
bpatel@997 174 }
bpatel@997 175 // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
bpatel@997 176 buf.append(htmlstr.substring(previndex, index));
bpatel@997 177 previndex = index + 13; // length for {@docroot}/.. string
bpatel@997 178 // Insert docrootparent absolute path where {@docRoot}/.. was located
bpatel@997 179
bpatel@997 180 buf.append(configuration.docrootparent);
bpatel@997 181 // Append slash if next character is not a slash
bpatel@997 182 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
bpatel@997 183 buf.append(DirectoryManager.URL_FILE_SEPARATOR);
bpatel@997 184 }
bpatel@997 185 } else {
bpatel@997 186 // Search for lowercase version of {@docRoot}
bpatel@997 187 index = lowerHtml.indexOf("{@docroot}", previndex);
bpatel@997 188 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
bpatel@997 189 if (index < 0) {
bpatel@997 190 buf.append(htmlstr.substring(previndex));
bpatel@997 191 break;
bpatel@997 192 }
bpatel@997 193 // If next {@docroot} tag found, append htmlstr up to start of tag
bpatel@997 194 buf.append(htmlstr.substring(previndex, index));
bpatel@997 195 previndex = index + 10; // length for {@docroot} string
bpatel@997 196 // Insert relative path where {@docRoot} was located
bpatel@997 197 buf.append(relativepathNoSlash);
bpatel@997 198 // Append slash if next character is not a slash
bpatel@997 199 if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length() &&
bpatel@997 200 htmlstr.charAt(previndex) != '/') {
bpatel@997 201 buf.append(DirectoryManager.URL_FILE_SEPARATOR);
bpatel@997 202 }
duke@1 203 }
duke@1 204 }
duke@1 205 return buf.toString();
duke@1 206 }
duke@1 207
duke@1 208 /**
duke@1 209 * Print Html Hyper Link, with target frame. This
duke@1 210 * link will only appear if page is not in a frame.
duke@1 211 *
duke@1 212 * @param link String name of the file.
duke@1 213 * @param where Position in the file
duke@1 214 * @param target Name of the target frame.
duke@1 215 * @param label Tag for the link.
bpatel@182 216 * @param strong Whether the label should be strong or not?
duke@1 217 */
duke@1 218 public void printNoFramesTargetHyperLink(String link, String where,
duke@1 219 String target, String label,
bpatel@182 220 boolean strong) {
duke@1 221 script();
duke@1 222 println(" <!--");
duke@1 223 println(" if(window==top) {");
duke@1 224 println(" document.writeln('"
bpatel@766 225 + getHyperLinkString(link, where, label, strong, "", "", target) + "');");
duke@1 226 println(" }");
duke@1 227 println(" //-->");
duke@1 228 scriptEnd();
duke@1 229 noScript();
bpatel@766 230 println(" " + getHyperLinkString(link, where, label, strong, "", "", target));
duke@1 231 noScriptEnd();
duke@1 232 println(DocletConstants.NL);
duke@1 233 }
duke@1 234
bpatel@766 235 /**
bpatel@766 236 * Get the script to show or hide the All classes link.
bpatel@766 237 *
bpatel@766 238 * @param id id of the element to show or hide
bpatel@766 239 * @return a content tree for the script
bpatel@766 240 */
bpatel@766 241 public Content getAllClassesLinkScript(String id) {
bpatel@766 242 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
bpatel@766 243 script.addAttr(HtmlAttr.TYPE, "text/javascript");
bpatel@793 244 String scriptCode = "<!--" + DocletConstants.NL +
bpatel@793 245 " allClassesLink = document.getElementById(\"" + id + "\");" + DocletConstants.NL +
bpatel@793 246 " if(window==top) {" + DocletConstants.NL +
bpatel@793 247 " allClassesLink.style.display = \"block\";" + DocletConstants.NL +
bpatel@793 248 " }" + DocletConstants.NL +
bpatel@793 249 " else {" + DocletConstants.NL +
bpatel@793 250 " allClassesLink.style.display = \"none\";" + DocletConstants.NL +
bpatel@793 251 " }" + DocletConstants.NL +
bpatel@793 252 " //-->" + DocletConstants.NL;
bpatel@766 253 Content scriptContent = new RawHtml(scriptCode);
bpatel@766 254 script.addContent(scriptContent);
bpatel@766 255 Content div = HtmlTree.DIV(script);
bpatel@766 256 return div;
bpatel@766 257 }
bpatel@766 258
bpatel@766 259 /**
bpatel@766 260 * Add method information.
bpatel@766 261 *
bpatel@766 262 * @param method the method to be documented
bpatel@766 263 * @param dl the content tree to which the method information will be added
bpatel@766 264 */
bpatel@766 265 private void addMethodInfo(MethodDoc method, Content dl) {
duke@1 266 ClassDoc[] intfacs = method.containingClass().interfaces();
duke@1 267 MethodDoc overriddenMethod = method.overriddenMethod();
bpatel@233 268 // Check whether there is any implementation or overridden info to be
bpatel@233 269 // printed. If no overridden or implementation info needs to be
bpatel@233 270 // printed, do not print this section.
bpatel@233 271 if ((intfacs.length > 0 &&
bpatel@233 272 new ImplementedMethods(method, this.configuration).build().length > 0) ||
bpatel@233 273 overriddenMethod != null) {
bpatel@766 274 MethodWriterImpl.addImplementsInfo(this, method, dl);
duke@1 275 if (overriddenMethod != null) {
bpatel@766 276 MethodWriterImpl.addOverridden(this,
bpatel@766 277 method.overriddenType(), overriddenMethod, dl);
duke@1 278 }
duke@1 279 }
duke@1 280 }
duke@1 281
bpatel@766 282 /**
bpatel@766 283 * Adds the tags information.
bpatel@766 284 *
bpatel@766 285 * @param doc the doc for which the tags will be generated
bpatel@766 286 * @param htmltree the documentation tree to which the tags will be added
bpatel@766 287 */
bpatel@766 288 protected void addTagsInfo(Doc doc, Content htmltree) {
bpatel@766 289 if (configuration.nocomment) {
duke@1 290 return;
duke@1 291 }
bpatel@766 292 Content dl = new HtmlTree(HtmlTag.DL);
duke@1 293 if (doc instanceof MethodDoc) {
bpatel@766 294 addMethodInfo((MethodDoc) doc, dl);
duke@1 295 }
duke@1 296 TagletOutputImpl output = new TagletOutputImpl("");
duke@1 297 TagletWriter.genTagOuput(configuration.tagletManager, doc,
duke@1 298 configuration.tagletManager.getCustomTags(doc),
duke@1 299 getTagletWriterInstance(false), output);
bpatel@233 300 String outputString = output.toString().trim();
bpatel@233 301 if (!outputString.isEmpty()) {
bpatel@766 302 Content resultString = new RawHtml(outputString);
bpatel@766 303 dl.addContent(resultString);
duke@1 304 }
bpatel@766 305 htmltree.addContent(dl);
duke@1 306 }
duke@1 307
duke@1 308 /**
bpatel@233 309 * Check whether there are any tags for Serialization Overview
bpatel@233 310 * section to be printed.
bpatel@222 311 *
bpatel@233 312 * @param field the FieldDoc object to check for tags.
bpatel@222 313 * @return true if there are tags to be printed else return false.
bpatel@222 314 */
bpatel@233 315 protected boolean hasSerializationOverviewTags(FieldDoc field) {
bpatel@222 316 TagletOutputImpl output = new TagletOutputImpl("");
bpatel@233 317 TagletWriter.genTagOuput(configuration.tagletManager, field,
bpatel@233 318 configuration.tagletManager.getCustomTags(field),
bpatel@222 319 getTagletWriterInstance(false), output);
bpatel@233 320 return (!output.toString().trim().isEmpty());
bpatel@222 321 }
bpatel@222 322
bpatel@222 323 /**
duke@1 324 * Returns a TagletWriter that knows how to write HTML.
duke@1 325 *
duke@1 326 * @return a TagletWriter that knows how to write HTML.
duke@1 327 */
duke@1 328 public TagletWriter getTagletWriterInstance(boolean isFirstSentence) {
duke@1 329 return new TagletWriterImpl(this, isFirstSentence);
duke@1 330 }
duke@1 331
duke@1 332 protected void printTagsInfoHeader() {
duke@1 333 dl();
duke@1 334 }
duke@1 335
duke@1 336 protected void printTagsInfoFooter() {
duke@1 337 dlEnd();
duke@1 338 }
duke@1 339
duke@1 340 /**
bpatel@766 341 * Get Package link, with target frame.
duke@1 342 *
bpatel@766 343 * @param pd The link will be to the "package-summary.html" page for this package
bpatel@766 344 * @param target name of the target frame
bpatel@766 345 * @param label tag for the link
bpatel@766 346 * @return a content for the target package link
duke@1 347 */
bpatel@766 348 public Content getTargetPackageLink(PackageDoc pd, String target,
bpatel@766 349 Content label) {
bpatel@766 350 return getHyperLink(pathString(pd, "package-summary.html"), "", label, "", target);
duke@1 351 }
duke@1 352
duke@1 353 /**
bpatel@766 354 * Generates the HTML document tree and prints it out.
bpatel@766 355 *
bpatel@766 356 * @param metakeywords Array of String keywords for META tag. Each element
bpatel@766 357 * of the array is assigned to a separate META tag.
bpatel@766 358 * Pass in null for no array
bpatel@766 359 * @param includeScript true if printing windowtitle script
bpatel@766 360 * false for files that appear in the left-hand frames
bpatel@766 361 * @param body the body htmltree to be included in the document
bpatel@766 362 */
bpatel@766 363 public void printHtmlDocument(String[] metakeywords, boolean includeScript,
bpatel@766 364 Content body) {
bpatel@766 365 Content htmlDocType = DocType.Transitional();
bpatel@766 366 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 367 Content head = new HtmlTree(HtmlTag.HEAD);
bpatel@766 368 if (!configuration.notimestamp) {
jjg@1361 369 Content headComment = new Comment(getGeneratedByString());
bpatel@766 370 head.addContent(headComment);
bpatel@766 371 }
bpatel@766 372 if (configuration.charset.length() > 0) {
bpatel@766 373 Content meta = HtmlTree.META("Content-Type", "text/html",
bpatel@766 374 configuration.charset);
bpatel@766 375 head.addContent(meta);
bpatel@766 376 }
bpatel@766 377 head.addContent(getTitle());
bpatel@766 378 if (!configuration.notimestamp) {
bpatel@766 379 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
bpatel@766 380 Content meta = HtmlTree.META("date", dateFormat.format(new Date()));
bpatel@766 381 head.addContent(meta);
bpatel@766 382 }
bpatel@766 383 if (metakeywords != null) {
bpatel@766 384 for (int i=0; i < metakeywords.length; i++) {
bpatel@766 385 Content meta = HtmlTree.META("keywords", metakeywords[i]);
bpatel@766 386 head.addContent(meta);
bpatel@766 387 }
bpatel@766 388 }
bpatel@766 389 head.addContent(getStyleSheetProperties());
bpatel@766 390 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 391 head, body);
bpatel@766 392 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 393 htmlComment, htmlTree);
bpatel@766 394 print(htmlDocument.toString());
bpatel@766 395 }
bpatel@766 396
bpatel@766 397 /**
bpatel@766 398 * Get the window title.
bpatel@766 399 *
bpatel@766 400 * @param title the title string to construct the complete window title
bpatel@766 401 * @return the window title string
bpatel@766 402 */
bpatel@766 403 public String getWindowTitle(String title) {
bpatel@766 404 if (configuration.windowtitle.length() > 0) {
bpatel@766 405 title += " (" + configuration.windowtitle + ")";
bpatel@766 406 }
bpatel@766 407 return title;
bpatel@766 408 }
bpatel@766 409
bpatel@766 410 /**
duke@1 411 * Print user specified header and the footer.
duke@1 412 *
duke@1 413 * @param header if true print the user provided header else print the
duke@1 414 * user provided footer.
duke@1 415 */
duke@1 416 public void printUserHeaderFooter(boolean header) {
duke@1 417 em();
duke@1 418 if (header) {
duke@1 419 print(replaceDocRootDir(configuration.header));
duke@1 420 } else {
duke@1 421 if (configuration.footer.length() != 0) {
duke@1 422 print(replaceDocRootDir(configuration.footer));
duke@1 423 } else {
duke@1 424 print(replaceDocRootDir(configuration.header));
duke@1 425 }
duke@1 426 }
duke@1 427 emEnd();
duke@1 428 }
duke@1 429
duke@1 430 /**
bpatel@766 431 * Get user specified header and the footer.
bpatel@766 432 *
bpatel@766 433 * @param header if true print the user provided header else print the
bpatel@766 434 * user provided footer.
bpatel@766 435 */
bpatel@766 436 public Content getUserHeaderFooter(boolean header) {
bpatel@766 437 String content;
bpatel@766 438 if (header) {
bpatel@766 439 content = replaceDocRootDir(configuration.header);
bpatel@766 440 } else {
bpatel@766 441 if (configuration.footer.length() != 0) {
bpatel@766 442 content = replaceDocRootDir(configuration.footer);
bpatel@766 443 } else {
bpatel@766 444 content = replaceDocRootDir(configuration.header);
bpatel@766 445 }
bpatel@766 446 }
bpatel@766 447 Content rawContent = new RawHtml(content);
bpatel@766 448 Content em = HtmlTree.EM(rawContent);
bpatel@766 449 return em;
bpatel@766 450 }
bpatel@766 451
bpatel@766 452 /**
duke@1 453 * Print the user specified top.
duke@1 454 */
duke@1 455 public void printTop() {
duke@1 456 print(replaceDocRootDir(configuration.top));
duke@1 457 hr();
duke@1 458 }
duke@1 459
duke@1 460 /**
bpatel@766 461 * Adds the user specified top.
bpatel@766 462 *
bpatel@766 463 * @param body the content tree to which user specified top will be added
bpatel@766 464 */
bpatel@766 465 public void addTop(Content body) {
bpatel@766 466 Content top = new RawHtml(replaceDocRootDir(configuration.top));
bpatel@766 467 body.addContent(top);
bpatel@766 468 }
bpatel@766 469
bpatel@766 470 /**
duke@1 471 * Print the user specified bottom.
duke@1 472 */
duke@1 473 public void printBottom() {
duke@1 474 hr();
duke@1 475 print(replaceDocRootDir(configuration.bottom));
duke@1 476 }
duke@1 477
duke@1 478 /**
bpatel@766 479 * Adds the user specified bottom.
bpatel@766 480 *
bpatel@766 481 * @param body the content tree to which user specified bottom will be added
bpatel@766 482 */
bpatel@766 483 public void addBottom(Content body) {
bpatel@766 484 Content bottom = new RawHtml(replaceDocRootDir(configuration.bottom));
bpatel@766 485 Content small = HtmlTree.SMALL(bottom);
bpatel@766 486 Content p = HtmlTree.P(HtmlStyle.legalCopy, small);
bpatel@766 487 body.addContent(p);
bpatel@766 488 }
bpatel@766 489
bpatel@766 490 /**
duke@1 491 * Print the navigation bar for the Html page at the top and and the bottom.
duke@1 492 *
duke@1 493 * @param header If true print navigation bar at the top of the page else
duke@1 494 * print the nevigation bar at the bottom.
duke@1 495 */
duke@1 496 protected void navLinks(boolean header) {
duke@1 497 println("");
duke@1 498 if (!configuration.nonavbar) {
duke@1 499 if (header) {
duke@1 500 println(DocletConstants.NL + "<!-- ========= START OF TOP NAVBAR ======= -->");
duke@1 501 anchor("navbar_top");
duke@1 502 println();
bpatel@766 503 print(getHyperLinkString("", "skip-navbar_top", "", false, "",
duke@1 504 configuration.getText("doclet.Skip_navigation_links"), ""));
duke@1 505 } else {
duke@1 506 println(DocletConstants.NL + "<!-- ======= START OF BOTTOM NAVBAR ====== -->");
duke@1 507 anchor("navbar_bottom");
duke@1 508 println();
bpatel@766 509 print(getHyperLinkString("", "skip-navbar_bottom", "", false, "",
duke@1 510 configuration.getText("doclet.Skip_navigation_links"), ""));
duke@1 511 }
duke@1 512 table(0, "100%", 1, 0);
duke@1 513 tr();
duke@1 514 tdColspanBgcolorStyle(2, "#EEEEFF", "NavBarCell1");
duke@1 515 println("");
duke@1 516 if (header) {
duke@1 517 anchor("navbar_top_firstrow");
duke@1 518 } else {
duke@1 519 anchor("navbar_bottom_firstrow");
duke@1 520 }
duke@1 521 table(0, 0, 3);
duke@1 522 print(" ");
duke@1 523 trAlignVAlign("center", "top");
duke@1 524
duke@1 525 if (configuration.createoverview) {
duke@1 526 navLinkContents();
duke@1 527 }
duke@1 528
duke@1 529 if (configuration.packages.length == 1) {
duke@1 530 navLinkPackage(configuration.packages[0]);
duke@1 531 } else if (configuration.packages.length > 1) {
duke@1 532 navLinkPackage();
duke@1 533 }
duke@1 534
duke@1 535 navLinkClass();
duke@1 536
duke@1 537 if(configuration.classuse) {
duke@1 538 navLinkClassUse();
duke@1 539 }
duke@1 540 if(configuration.createtree) {
duke@1 541 navLinkTree();
duke@1 542 }
duke@1 543 if(!(configuration.nodeprecated ||
duke@1 544 configuration.nodeprecatedlist)) {
duke@1 545 navLinkDeprecated();
duke@1 546 }
duke@1 547 if(configuration.createindex) {
duke@1 548 navLinkIndex();
duke@1 549 }
duke@1 550 if (!configuration.nohelp) {
duke@1 551 navLinkHelp();
duke@1 552 }
duke@1 553 print(" ");
duke@1 554 trEnd();
duke@1 555 tableEnd();
duke@1 556 tdEnd();
duke@1 557
duke@1 558 tdAlignVAlignRowspan("right", "top", 3);
duke@1 559
duke@1 560 printUserHeaderFooter(header);
duke@1 561 tdEnd();
duke@1 562 trEnd();
duke@1 563 println("");
duke@1 564
duke@1 565 tr();
duke@1 566 tdBgcolorStyle("white", "NavBarCell2");
duke@1 567 font("-2");
duke@1 568 space();
duke@1 569 navLinkPrevious();
duke@1 570 space();
duke@1 571 println("");
duke@1 572 space();
duke@1 573 navLinkNext();
duke@1 574 fontEnd();
duke@1 575 tdEnd();
duke@1 576
duke@1 577 tdBgcolorStyle("white", "NavBarCell2");
duke@1 578 font("-2");
duke@1 579 print(" ");
duke@1 580 navShowLists();
duke@1 581 print(" ");
duke@1 582 space();
duke@1 583 println("");
duke@1 584 space();
duke@1 585 navHideLists(filename);
duke@1 586 print(" ");
duke@1 587 space();
duke@1 588 println("");
duke@1 589 space();
duke@1 590 navLinkClassIndex();
duke@1 591 fontEnd();
duke@1 592 tdEnd();
duke@1 593
duke@1 594 trEnd();
duke@1 595
duke@1 596 printSummaryDetailLinks();
duke@1 597
duke@1 598 tableEnd();
duke@1 599 if (header) {
duke@1 600 aName("skip-navbar_top");
duke@1 601 aEnd();
duke@1 602 println(DocletConstants.NL + "<!-- ========= END OF TOP NAVBAR ========= -->");
duke@1 603 } else {
duke@1 604 aName("skip-navbar_bottom");
duke@1 605 aEnd();
duke@1 606 println(DocletConstants.NL + "<!-- ======== END OF BOTTOM NAVBAR ======= -->");
duke@1 607 }
duke@1 608 println("");
duke@1 609 }
duke@1 610 }
duke@1 611
duke@1 612 /**
bpatel@766 613 * Adds the navigation bar for the Html page at the top and and the bottom.
bpatel@766 614 *
bpatel@766 615 * @param header If true print navigation bar at the top of the page else
bpatel@766 616 * @param body the HtmlTree to which the nav links will be added
bpatel@766 617 */
bpatel@766 618 protected void addNavLinks(boolean header, Content body) {
bpatel@766 619 if (!configuration.nonavbar) {
bpatel@766 620 String allClassesId = "allclasses_";
bpatel@766 621 HtmlTree navDiv = new HtmlTree(HtmlTag.DIV);
bpatel@766 622 if (header) {
bpatel@766 623 body.addContent(HtmlConstants.START_OF_TOP_NAVBAR);
bpatel@766 624 navDiv.addStyle(HtmlStyle.topNav);
bpatel@766 625 allClassesId += "navbar_top";
bpatel@766 626 Content a = getMarkerAnchor("navbar_top");
bpatel@766 627 navDiv.addContent(a);
bpatel@766 628 Content skipLinkContent = getHyperLink("",
bpatel@766 629 "skip-navbar_top", HtmlTree.EMPTY, configuration.getText(
bpatel@766 630 "doclet.Skip_navigation_links"), "");
bpatel@766 631 navDiv.addContent(skipLinkContent);
bpatel@766 632 } else {
bpatel@766 633 body.addContent(HtmlConstants.START_OF_BOTTOM_NAVBAR);
bpatel@766 634 navDiv.addStyle(HtmlStyle.bottomNav);
bpatel@766 635 allClassesId += "navbar_bottom";
bpatel@766 636 Content a = getMarkerAnchor("navbar_bottom");
bpatel@766 637 navDiv.addContent(a);
bpatel@766 638 Content skipLinkContent = getHyperLink("",
bpatel@766 639 "skip-navbar_bottom", HtmlTree.EMPTY, configuration.getText(
bpatel@766 640 "doclet.Skip_navigation_links"), "");
bpatel@766 641 navDiv.addContent(skipLinkContent);
bpatel@766 642 }
bpatel@766 643 if (header) {
bpatel@766 644 navDiv.addContent(getMarkerAnchor("navbar_top_firstrow"));
bpatel@766 645 } else {
bpatel@766 646 navDiv.addContent(getMarkerAnchor("navbar_bottom_firstrow"));
bpatel@766 647 }
bpatel@766 648 HtmlTree navList = new HtmlTree(HtmlTag.UL);
bpatel@766 649 navList.addStyle(HtmlStyle.navList);
bpatel@766 650 navList.addAttr(HtmlAttr.TITLE, "Navigation");
bpatel@766 651 if (configuration.createoverview) {
bpatel@766 652 navList.addContent(getNavLinkContents());
bpatel@766 653 }
bpatel@766 654 if (configuration.packages.length == 1) {
bpatel@766 655 navList.addContent(getNavLinkPackage(configuration.packages[0]));
bpatel@766 656 } else if (configuration.packages.length > 1) {
bpatel@766 657 navList.addContent(getNavLinkPackage());
bpatel@766 658 }
bpatel@766 659 navList.addContent(getNavLinkClass());
bpatel@766 660 if(configuration.classuse) {
bpatel@766 661 navList.addContent(getNavLinkClassUse());
bpatel@766 662 }
bpatel@766 663 if(configuration.createtree) {
bpatel@766 664 navList.addContent(getNavLinkTree());
bpatel@766 665 }
bpatel@766 666 if(!(configuration.nodeprecated ||
bpatel@766 667 configuration.nodeprecatedlist)) {
bpatel@766 668 navList.addContent(getNavLinkDeprecated());
bpatel@766 669 }
bpatel@766 670 if(configuration.createindex) {
bpatel@766 671 navList.addContent(getNavLinkIndex());
bpatel@766 672 }
bpatel@766 673 if (!configuration.nohelp) {
bpatel@766 674 navList.addContent(getNavLinkHelp());
bpatel@766 675 }
bpatel@766 676 navDiv.addContent(navList);
bpatel@766 677 Content aboutDiv = HtmlTree.DIV(HtmlStyle.aboutLanguage, getUserHeaderFooter(header));
bpatel@766 678 navDiv.addContent(aboutDiv);
bpatel@766 679 body.addContent(navDiv);
bpatel@766 680 Content ulNav = HtmlTree.UL(HtmlStyle.navList, getNavLinkPrevious());
bpatel@766 681 ulNav.addContent(getNavLinkNext());
bpatel@766 682 Content subDiv = HtmlTree.DIV(HtmlStyle.subNav, ulNav);
bpatel@766 683 Content ulFrames = HtmlTree.UL(HtmlStyle.navList, getNavShowLists());
bpatel@766 684 ulFrames.addContent(getNavHideLists(filename));
bpatel@766 685 subDiv.addContent(ulFrames);
bpatel@766 686 HtmlTree ulAllClasses = HtmlTree.UL(HtmlStyle.navList, getNavLinkClassIndex());
bpatel@766 687 ulAllClasses.addAttr(HtmlAttr.ID, allClassesId.toString());
bpatel@766 688 subDiv.addContent(ulAllClasses);
bpatel@766 689 subDiv.addContent(getAllClassesLinkScript(allClassesId.toString()));
bpatel@766 690 addSummaryDetailLinks(subDiv);
bpatel@766 691 if (header) {
bpatel@766 692 subDiv.addContent(getMarkerAnchor("skip-navbar_top"));
bpatel@766 693 body.addContent(subDiv);
bpatel@766 694 body.addContent(HtmlConstants.END_OF_TOP_NAVBAR);
bpatel@766 695 } else {
bpatel@766 696 subDiv.addContent(getMarkerAnchor("skip-navbar_bottom"));
bpatel@766 697 body.addContent(subDiv);
bpatel@766 698 body.addContent(HtmlConstants.END_OF_BOTTOM_NAVBAR);
bpatel@766 699 }
bpatel@766 700 }
bpatel@766 701 }
bpatel@766 702
bpatel@766 703 /**
duke@1 704 * Print the word "NEXT" to indicate that no link is available. Override
duke@1 705 * this method to customize next link.
duke@1 706 */
duke@1 707 protected void navLinkNext() {
duke@1 708 navLinkNext(null);
duke@1 709 }
duke@1 710
duke@1 711 /**
bpatel@766 712 * Get the word "NEXT" to indicate that no link is available. Override
bpatel@766 713 * this method to customize next link.
bpatel@766 714 *
bpatel@766 715 * @return a content tree for the link
bpatel@766 716 */
bpatel@766 717 protected Content getNavLinkNext() {
bpatel@766 718 return getNavLinkNext(null);
bpatel@766 719 }
bpatel@766 720
bpatel@766 721 /**
duke@1 722 * Print the word "PREV" to indicate that no link is available. Override
duke@1 723 * this method to customize prev link.
duke@1 724 */
duke@1 725 protected void navLinkPrevious() {
duke@1 726 navLinkPrevious(null);
duke@1 727 }
duke@1 728
duke@1 729 /**
bpatel@766 730 * Get the word "PREV" to indicate that no link is available. Override
bpatel@766 731 * this method to customize prev link.
bpatel@766 732 *
bpatel@766 733 * @return a content tree for the link
bpatel@766 734 */
bpatel@766 735 protected Content getNavLinkPrevious() {
bpatel@766 736 return getNavLinkPrevious(null);
bpatel@766 737 }
bpatel@766 738
bpatel@766 739 /**
duke@1 740 * Do nothing. This is the default method.
duke@1 741 */
duke@1 742 protected void printSummaryDetailLinks() {
duke@1 743 }
duke@1 744
duke@1 745 /**
bpatel@766 746 * Do nothing. This is the default method.
bpatel@766 747 */
bpatel@766 748 protected void addSummaryDetailLinks(Content navDiv) {
bpatel@766 749 }
bpatel@766 750
bpatel@766 751 /**
duke@1 752 * Print link to the "overview-summary.html" page.
duke@1 753 */
duke@1 754 protected void navLinkContents() {
duke@1 755 navCellStart();
duke@1 756 printHyperLink(relativePath + "overview-summary.html", "",
duke@1 757 configuration.getText("doclet.Overview"), true, "NavBarFont1");
duke@1 758 navCellEnd();
duke@1 759 }
duke@1 760
duke@1 761 /**
bpatel@766 762 * Get link to the "overview-summary.html" page.
bpatel@766 763 *
bpatel@766 764 * @return a content tree for the link
bpatel@766 765 */
bpatel@766 766 protected Content getNavLinkContents() {
bpatel@766 767 Content linkContent = getHyperLink(relativePath +
bpatel@766 768 "overview-summary.html", "", overviewLabel, "", "");
bpatel@766 769 Content li = HtmlTree.LI(linkContent);
bpatel@766 770 return li;
bpatel@766 771 }
bpatel@766 772
bpatel@766 773 /**
duke@1 774 * Description for a cell in the navigation bar.
duke@1 775 */
duke@1 776 protected void navCellStart() {
duke@1 777 print(" ");
duke@1 778 tdBgcolorStyle("#EEEEFF", "NavBarCell1");
duke@1 779 print(" ");
duke@1 780 }
duke@1 781
duke@1 782 /**
duke@1 783 * Description for a cell in the navigation bar, but with reverse
duke@1 784 * high-light effect.
duke@1 785 */
duke@1 786 protected void navCellRevStart() {
duke@1 787 print(" ");
duke@1 788 tdBgcolorStyle("#FFFFFF", "NavBarCell1Rev");
duke@1 789 print(" ");
duke@1 790 space();
duke@1 791 }
duke@1 792
duke@1 793 /**
duke@1 794 * Closing tag for navigation bar cell.
duke@1 795 */
duke@1 796 protected void navCellEnd() {
duke@1 797 space();
duke@1 798 tdEnd();
duke@1 799 }
duke@1 800
duke@1 801 /**
duke@1 802 * Print link to the "package-summary.html" page for the package passed.
duke@1 803 *
duke@1 804 * @param pkg Package to which link will be generated.
duke@1 805 */
duke@1 806 protected void navLinkPackage(PackageDoc pkg) {
duke@1 807 navCellStart();
duke@1 808 printPackageLink(pkg, configuration.getText("doclet.Package"), true,
duke@1 809 "NavBarFont1");
duke@1 810 navCellEnd();
duke@1 811 }
duke@1 812
duke@1 813 /**
bpatel@766 814 * Get link to the "package-summary.html" page for the package passed.
bpatel@766 815 *
bpatel@766 816 * @param pkg Package to which link will be generated
bpatel@766 817 * @return a content tree for the link
bpatel@766 818 */
bpatel@766 819 protected Content getNavLinkPackage(PackageDoc pkg) {
bpatel@766 820 Content linkContent = getPackageLink(pkg,
bpatel@766 821 packageLabel);
bpatel@766 822 Content li = HtmlTree.LI(linkContent);
bpatel@766 823 return li;
bpatel@766 824 }
bpatel@766 825
bpatel@766 826 /**
duke@1 827 * Print the word "Package" in the navigation bar cell, to indicate that
duke@1 828 * link is not available here.
duke@1 829 */
duke@1 830 protected void navLinkPackage() {
duke@1 831 navCellStart();
duke@1 832 fontStyle("NavBarFont1");
duke@1 833 printText("doclet.Package");
duke@1 834 fontEnd();
duke@1 835 navCellEnd();
duke@1 836 }
duke@1 837
duke@1 838 /**
bpatel@766 839 * Get the word "Package" , to indicate that link is not available here.
bpatel@766 840 *
bpatel@766 841 * @return a content tree for the link
bpatel@766 842 */
bpatel@766 843 protected Content getNavLinkPackage() {
bpatel@766 844 Content li = HtmlTree.LI(packageLabel);
bpatel@766 845 return li;
bpatel@766 846 }
bpatel@766 847
bpatel@766 848 /**
duke@1 849 * Print the word "Use" in the navigation bar cell, to indicate that link
duke@1 850 * is not available.
duke@1 851 */
duke@1 852 protected void navLinkClassUse() {
duke@1 853 navCellStart();
duke@1 854 fontStyle("NavBarFont1");
duke@1 855 printText("doclet.navClassUse");
duke@1 856 fontEnd();
duke@1 857 navCellEnd();
duke@1 858 }
duke@1 859
duke@1 860 /**
bpatel@766 861 * Get the word "Use", to indicate that link is not available.
bpatel@766 862 *
bpatel@766 863 * @return a content tree for the link
bpatel@766 864 */
bpatel@766 865 protected Content getNavLinkClassUse() {
bpatel@766 866 Content li = HtmlTree.LI(useLabel);
bpatel@766 867 return li;
bpatel@766 868 }
bpatel@766 869
bpatel@766 870 /**
duke@1 871 * Print link for previous file.
duke@1 872 *
duke@1 873 * @param prev File name for the prev link.
duke@1 874 */
duke@1 875 public void navLinkPrevious(String prev) {
duke@1 876 String tag = configuration.getText("doclet.Prev");
duke@1 877 if (prev != null) {
duke@1 878 printHyperLink(prev, "", tag, true) ;
duke@1 879 } else {
duke@1 880 print(tag);
duke@1 881 }
duke@1 882 }
duke@1 883
duke@1 884 /**
bpatel@766 885 * Get link for previous file.
bpatel@766 886 *
bpatel@766 887 * @param prev File name for the prev link
bpatel@766 888 * @return a content tree for the link
bpatel@766 889 */
bpatel@766 890 public Content getNavLinkPrevious(String prev) {
bpatel@766 891 Content li;
bpatel@766 892 if (prev != null) {
bpatel@766 893 li = HtmlTree.LI(getHyperLink(prev, "", prevLabel, "", ""));
bpatel@766 894 }
bpatel@766 895 else
bpatel@766 896 li = HtmlTree.LI(prevLabel);
bpatel@766 897 return li;
bpatel@766 898 }
bpatel@766 899
bpatel@766 900 /**
duke@1 901 * Print link for next file. If next is null, just print the label
duke@1 902 * without linking it anywhere.
duke@1 903 *
duke@1 904 * @param next File name for the next link.
duke@1 905 */
duke@1 906 public void navLinkNext(String next) {
duke@1 907 String tag = configuration.getText("doclet.Next");
duke@1 908 if (next != null) {
duke@1 909 printHyperLink(next, "", tag, true);
duke@1 910 } else {
duke@1 911 print(tag);
duke@1 912 }
duke@1 913 }
duke@1 914
duke@1 915 /**
bpatel@766 916 * Get link for next file. If next is null, just print the label
bpatel@766 917 * without linking it anywhere.
bpatel@766 918 *
bpatel@766 919 * @param next File name for the next link
bpatel@766 920 * @return a content tree for the link
bpatel@766 921 */
bpatel@766 922 public Content getNavLinkNext(String next) {
bpatel@766 923 Content li;
bpatel@766 924 if (next != null) {
bpatel@766 925 li = HtmlTree.LI(getHyperLink(next, "", nextLabel, "", ""));
bpatel@766 926 }
bpatel@766 927 else
bpatel@766 928 li = HtmlTree.LI(nextLabel);
bpatel@766 929 return li;
bpatel@766 930 }
bpatel@766 931
bpatel@766 932 /**
duke@1 933 * Print "FRAMES" link, to switch to the frame version of the output.
duke@1 934 *
duke@1 935 * @param link File to be linked, "index.html".
duke@1 936 */
duke@1 937 protected void navShowLists(String link) {
bpatel@766 938 print(getHyperLinkString(link + "?" + path + filename, "",
duke@1 939 configuration.getText("doclet.FRAMES"), true, "", "", "_top"));
duke@1 940 }
duke@1 941
duke@1 942 /**
bpatel@766 943 * Get "FRAMES" link, to switch to the frame version of the output.
bpatel@766 944 *
bpatel@766 945 * @param link File to be linked, "index.html"
bpatel@766 946 * @return a content tree for the link
bpatel@766 947 */
bpatel@766 948 protected Content getNavShowLists(String link) {
bpatel@766 949 Content framesContent = getHyperLink(link + "?" + path +
bpatel@766 950 filename, "", framesLabel, "", "_top");
bpatel@766 951 Content li = HtmlTree.LI(framesContent);
bpatel@766 952 return li;
bpatel@766 953 }
bpatel@766 954
bpatel@766 955 /**
duke@1 956 * Print "FRAMES" link, to switch to the frame version of the output.
duke@1 957 */
duke@1 958 protected void navShowLists() {
duke@1 959 navShowLists(relativePath + "index.html");
duke@1 960 }
duke@1 961
duke@1 962 /**
bpatel@766 963 * Get "FRAMES" link, to switch to the frame version of the output.
bpatel@766 964 *
bpatel@766 965 * @return a content tree for the link
bpatel@766 966 */
bpatel@766 967 protected Content getNavShowLists() {
bpatel@766 968 return getNavShowLists(relativePath + "index.html");
bpatel@766 969 }
bpatel@766 970
bpatel@766 971 /**
duke@1 972 * Print "NO FRAMES" link, to switch to the non-frame version of the output.
duke@1 973 *
duke@1 974 * @param link File to be linked.
duke@1 975 */
duke@1 976 protected void navHideLists(String link) {
bpatel@766 977 print(getHyperLinkString(link, "", configuration.getText("doclet.NO_FRAMES"),
duke@1 978 true, "", "", "_top"));
duke@1 979 }
duke@1 980
duke@1 981 /**
bpatel@766 982 * Get "NO FRAMES" link, to switch to the non-frame version of the output.
bpatel@766 983 *
bpatel@766 984 * @param link File to be linked
bpatel@766 985 * @return a content tree for the link
bpatel@766 986 */
bpatel@766 987 protected Content getNavHideLists(String link) {
bpatel@766 988 Content noFramesContent = getHyperLink(link, "", noframesLabel, "", "_top");
bpatel@766 989 Content li = HtmlTree.LI(noFramesContent);
bpatel@766 990 return li;
bpatel@766 991 }
bpatel@766 992
bpatel@766 993 /**
duke@1 994 * Print "Tree" link in the navigation bar. If there is only one package
duke@1 995 * specified on the command line, then the "Tree" link will be to the
duke@1 996 * only "package-tree.html" file otherwise it will be to the
duke@1 997 * "overview-tree.html" file.
duke@1 998 */
duke@1 999 protected void navLinkTree() {
duke@1 1000 navCellStart();
duke@1 1001 PackageDoc[] packages = configuration.root.specifiedPackages();
duke@1 1002 if (packages.length == 1 && configuration.root.specifiedClasses().length == 0) {
duke@1 1003 printHyperLink(pathString(packages[0], "package-tree.html"), "",
duke@1 1004 configuration.getText("doclet.Tree"), true, "NavBarFont1");
duke@1 1005 } else {
duke@1 1006 printHyperLink(relativePath + "overview-tree.html", "",
duke@1 1007 configuration.getText("doclet.Tree"), true, "NavBarFont1");
duke@1 1008 }
duke@1 1009 navCellEnd();
duke@1 1010 }
duke@1 1011
duke@1 1012 /**
bpatel@766 1013 * Get "Tree" link in the navigation bar. If there is only one package
bpatel@766 1014 * specified on the command line, then the "Tree" link will be to the
bpatel@766 1015 * only "package-tree.html" file otherwise it will be to the
bpatel@766 1016 * "overview-tree.html" file.
bpatel@766 1017 *
bpatel@766 1018 * @return a content tree for the link
duke@1 1019 */
bpatel@766 1020 protected Content getNavLinkTree() {
bpatel@766 1021 Content treeLinkContent;
bpatel@766 1022 PackageDoc[] packages = configuration.root.specifiedPackages();
bpatel@766 1023 if (packages.length == 1 && configuration.root.specifiedClasses().length == 0) {
bpatel@766 1024 treeLinkContent = getHyperLink(pathString(packages[0],
bpatel@766 1025 "package-tree.html"), "", treeLabel,
bpatel@766 1026 "", "");
bpatel@766 1027 } else {
bpatel@766 1028 treeLinkContent = getHyperLink(relativePath + "overview-tree.html",
bpatel@766 1029 "", treeLabel, "", "");
bpatel@766 1030 }
bpatel@766 1031 Content li = HtmlTree.LI(treeLinkContent);
bpatel@766 1032 return li;
bpatel@766 1033 }
bpatel@766 1034
bpatel@766 1035 /**
bpatel@766 1036 * Get the overview tree link for the main tree.
bpatel@766 1037 *
bpatel@766 1038 * @param label the label for the link
bpatel@766 1039 * @return a content tree for the link
bpatel@766 1040 */
bpatel@766 1041 protected Content getNavLinkMainTree(String label) {
bpatel@766 1042 Content mainTreeContent = getHyperLink(relativePath + "overview-tree.html",
bpatel@766 1043 new StringContent(label));
bpatel@766 1044 Content li = HtmlTree.LI(mainTreeContent);
bpatel@766 1045 return li;
duke@1 1046 }
duke@1 1047
duke@1 1048 /**
duke@1 1049 * Print the word "Class" in the navigation bar cell, to indicate that
duke@1 1050 * class link is not available.
duke@1 1051 */
duke@1 1052 protected void navLinkClass() {
duke@1 1053 navCellStart();
duke@1 1054 fontStyle("NavBarFont1");
duke@1 1055 printText("doclet.Class");
duke@1 1056 fontEnd();
duke@1 1057 navCellEnd();
duke@1 1058 }
duke@1 1059
duke@1 1060 /**
bpatel@766 1061 * Get the word "Class", to indicate that class link is not available.
bpatel@766 1062 *
bpatel@766 1063 * @return a content tree for the link
bpatel@766 1064 */
bpatel@766 1065 protected Content getNavLinkClass() {
bpatel@766 1066 Content li = HtmlTree.LI(classLabel);
bpatel@766 1067 return li;
bpatel@766 1068 }
bpatel@766 1069
bpatel@766 1070 /**
duke@1 1071 * Print "Deprecated" API link in the navigation bar.
duke@1 1072 */
duke@1 1073 protected void navLinkDeprecated() {
duke@1 1074 navCellStart();
duke@1 1075 printHyperLink(relativePath + "deprecated-list.html", "",
duke@1 1076 configuration.getText("doclet.navDeprecated"), true, "NavBarFont1");
duke@1 1077 navCellEnd();
duke@1 1078 }
duke@1 1079
duke@1 1080 /**
bpatel@766 1081 * Get "Deprecated" API link in the navigation bar.
bpatel@766 1082 *
bpatel@766 1083 * @return a content tree for the link
bpatel@766 1084 */
bpatel@766 1085 protected Content getNavLinkDeprecated() {
bpatel@766 1086 Content linkContent = getHyperLink(relativePath +
bpatel@766 1087 "deprecated-list.html", "", deprecatedLabel, "", "");
bpatel@766 1088 Content li = HtmlTree.LI(linkContent);
bpatel@766 1089 return li;
bpatel@766 1090 }
bpatel@766 1091
bpatel@766 1092 /**
duke@1 1093 * Print link for generated index. If the user has used "-splitindex"
duke@1 1094 * command line option, then link to file "index-files/index-1.html" is
duke@1 1095 * generated otherwise link to file "index-all.html" is generated.
duke@1 1096 */
duke@1 1097 protected void navLinkClassIndex() {
duke@1 1098 printNoFramesTargetHyperLink(relativePath +
duke@1 1099 AllClassesFrameWriter.OUTPUT_FILE_NAME_NOFRAMES,
duke@1 1100 "", "", configuration.getText("doclet.All_Classes"), true);
duke@1 1101 }
bpatel@766 1102
bpatel@766 1103 /**
bpatel@766 1104 * Get link for generated index. If the user has used "-splitindex"
bpatel@766 1105 * command line option, then link to file "index-files/index-1.html" is
bpatel@766 1106 * generated otherwise link to file "index-all.html" is generated.
bpatel@766 1107 *
bpatel@766 1108 * @return a content tree for the link
bpatel@766 1109 */
bpatel@766 1110 protected Content getNavLinkClassIndex() {
bpatel@766 1111 Content allClassesContent = getHyperLink(relativePath +
bpatel@766 1112 AllClassesFrameWriter.OUTPUT_FILE_NAME_NOFRAMES, "",
bpatel@766 1113 allclassesLabel, "", "");
bpatel@766 1114 Content li = HtmlTree.LI(allClassesContent);
bpatel@766 1115 return li;
bpatel@766 1116 }
duke@1 1117 /**
duke@1 1118 * Print link for generated class index.
duke@1 1119 */
duke@1 1120 protected void navLinkIndex() {
duke@1 1121 navCellStart();
duke@1 1122 printHyperLink(relativePath +
duke@1 1123 (configuration.splitindex?
duke@1 1124 DirectoryManager.getPath("index-files") +
duke@1 1125 fileseparator: "") +
duke@1 1126 (configuration.splitindex?
duke@1 1127 "index-1.html" : "index-all.html"), "",
duke@1 1128 configuration.getText("doclet.Index"), true, "NavBarFont1");
duke@1 1129 navCellEnd();
duke@1 1130 }
duke@1 1131
duke@1 1132 /**
bpatel@766 1133 * Get link for generated class index.
bpatel@766 1134 *
bpatel@766 1135 * @return a content tree for the link
bpatel@766 1136 */
bpatel@766 1137 protected Content getNavLinkIndex() {
bpatel@766 1138 Content linkContent = getHyperLink(relativePath +(configuration.splitindex?
bpatel@766 1139 DirectoryManager.getPath("index-files") + fileseparator: "") +
bpatel@766 1140 (configuration.splitindex?"index-1.html" : "index-all.html"), "",
bpatel@766 1141 indexLabel, "", "");
bpatel@766 1142 Content li = HtmlTree.LI(linkContent);
bpatel@766 1143 return li;
bpatel@766 1144 }
bpatel@766 1145
bpatel@766 1146 /**
duke@1 1147 * Print help file link. If user has provided a help file, then generate a
duke@1 1148 * link to the user given file, which is already copied to current or
duke@1 1149 * destination directory.
duke@1 1150 */
duke@1 1151 protected void navLinkHelp() {
duke@1 1152 String helpfilenm = configuration.helpfile;
duke@1 1153 if (helpfilenm.equals("")) {
duke@1 1154 helpfilenm = "help-doc.html";
duke@1 1155 } else {
duke@1 1156 int lastsep;
duke@1 1157 if ((lastsep = helpfilenm.lastIndexOf(File.separatorChar)) != -1) {
duke@1 1158 helpfilenm = helpfilenm.substring(lastsep + 1);
duke@1 1159 }
duke@1 1160 }
duke@1 1161 navCellStart();
duke@1 1162 printHyperLink(relativePath + helpfilenm, "",
duke@1 1163 configuration.getText("doclet.Help"), true, "NavBarFont1");
duke@1 1164 navCellEnd();
duke@1 1165 }
duke@1 1166
duke@1 1167 /**
bpatel@766 1168 * Get help file link. If user has provided a help file, then generate a
bpatel@766 1169 * link to the user given file, which is already copied to current or
bpatel@766 1170 * destination directory.
bpatel@766 1171 *
bpatel@766 1172 * @return a content tree for the link
bpatel@766 1173 */
bpatel@766 1174 protected Content getNavLinkHelp() {
bpatel@766 1175 String helpfilenm = configuration.helpfile;
bpatel@766 1176 if (helpfilenm.equals("")) {
bpatel@766 1177 helpfilenm = "help-doc.html";
bpatel@766 1178 } else {
bpatel@766 1179 int lastsep;
bpatel@766 1180 if ((lastsep = helpfilenm.lastIndexOf(File.separatorChar)) != -1) {
bpatel@766 1181 helpfilenm = helpfilenm.substring(lastsep + 1);
bpatel@766 1182 }
bpatel@766 1183 }
bpatel@766 1184 Content linkContent = getHyperLink(relativePath + helpfilenm, "",
bpatel@766 1185 helpLabel, "", "");
bpatel@766 1186 Content li = HtmlTree.LI(linkContent);
bpatel@766 1187 return li;
bpatel@766 1188 }
bpatel@766 1189
bpatel@766 1190 /**
duke@1 1191 * Print the word "Detail" in the navigation bar. No link is available.
duke@1 1192 */
duke@1 1193 protected void navDetail() {
duke@1 1194 printText("doclet.Detail");
duke@1 1195 }
duke@1 1196
duke@1 1197 /**
duke@1 1198 * Print the word "Summary" in the navigation bar. No link is available.
duke@1 1199 */
duke@1 1200 protected void navSummary() {
duke@1 1201 printText("doclet.Summary");
duke@1 1202 }
duke@1 1203
duke@1 1204 /**
duke@1 1205 * Print the Html table tag for the index summary tables. The table tag
duke@1 1206 * printed is
jjg@1326 1207 * {@code <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> }
duke@1 1208 */
duke@1 1209 public void tableIndexSummary() {
duke@1 1210 table(1, "100%", 3, 0);
duke@1 1211 }
duke@1 1212
duke@1 1213 /**
bpatel@243 1214 * Print the Html table tag for the index summary tables.
bpatel@243 1215 *
bpatel@243 1216 * @param summary the summary for the table tag summary attribute.
bpatel@243 1217 */
bpatel@243 1218 public void tableIndexSummary(String summary) {
bpatel@243 1219 table(1, "100%", 3, 0, summary);
bpatel@243 1220 }
bpatel@243 1221
bpatel@243 1222 /**
duke@1 1223 * Same as {@link #tableIndexSummary()}.
duke@1 1224 */
duke@1 1225 public void tableIndexDetail() {
duke@1 1226 table(1, "100%", 3, 0);
duke@1 1227 }
duke@1 1228
duke@1 1229 /**
duke@1 1230 * Print Html tag for table elements. The tag printed is
duke@1 1231 * &lt;TD ALIGN="right" VALIGN="top" WIDTH="1%"&gt;.
duke@1 1232 */
duke@1 1233 public void tdIndex() {
duke@1 1234 print("<TD ALIGN=\"right\" VALIGN=\"top\" WIDTH=\"1%\">");
duke@1 1235 }
duke@1 1236
duke@1 1237 /**
bpatel@243 1238 * Print table caption.
bpatel@243 1239 */
bpatel@243 1240 public void tableCaptionStart() {
bpatel@243 1241 captionStyle("TableCaption");
bpatel@243 1242 }
bpatel@243 1243
bpatel@243 1244 /**
bpatel@243 1245 * Print table sub-caption.
bpatel@243 1246 */
bpatel@243 1247 public void tableSubCaptionStart() {
bpatel@243 1248 captionStyle("TableSubCaption");
bpatel@243 1249 }
bpatel@243 1250
bpatel@243 1251 /**
bpatel@243 1252 * Print table caption end tags.
bpatel@243 1253 */
bpatel@243 1254 public void tableCaptionEnd() {
bpatel@243 1255 captionEnd();
bpatel@243 1256 }
bpatel@243 1257
bpatel@243 1258 /**
bpatel@243 1259 * Print summary table header.
bpatel@243 1260 */
bpatel@243 1261 public void summaryTableHeader(String[] header, String scope) {
bpatel@243 1262 tr();
bpatel@243 1263 for ( int i=0; i < header.length; i++ ) {
bpatel@243 1264 thScopeNoWrap("TableHeader", scope);
bpatel@243 1265 print(header[i]);
bpatel@243 1266 thEnd();
bpatel@243 1267 }
bpatel@243 1268 trEnd();
bpatel@243 1269 }
bpatel@243 1270
bpatel@243 1271 /**
bpatel@766 1272 * Get summary table header.
bpatel@766 1273 *
bpatel@766 1274 * @param header the header for the table
bpatel@766 1275 * @param scope the scope of the headers
bpatel@766 1276 * @return a content tree for the header
bpatel@766 1277 */
bpatel@766 1278 public Content getSummaryTableHeader(String[] header, String scope) {
bpatel@766 1279 Content tr = new HtmlTree(HtmlTag.TR);
bpatel@766 1280 int size = header.length;
bpatel@766 1281 Content tableHeader;
bpatel@766 1282 if (size == 1) {
bpatel@766 1283 tableHeader = new StringContent(header[0]);
bpatel@766 1284 tr.addContent(HtmlTree.TH(HtmlStyle.colOne, scope, tableHeader));
bpatel@766 1285 return tr;
bpatel@766 1286 }
bpatel@766 1287 for (int i = 0; i < size; i++) {
bpatel@766 1288 tableHeader = new StringContent(header[i]);
bpatel@766 1289 if(i == 0)
bpatel@766 1290 tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
bpatel@766 1291 else if(i == (size - 1))
bpatel@766 1292 tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
bpatel@766 1293 else
bpatel@766 1294 tr.addContent(HtmlTree.TH(scope, tableHeader));
bpatel@766 1295 }
bpatel@766 1296 return tr;
bpatel@766 1297 }
bpatel@766 1298
bpatel@766 1299 /**
bpatel@766 1300 * Get table caption.
bpatel@766 1301 *
bpatel@766 1302 * @param rawText the caption for the table which could be raw Html
bpatel@766 1303 * @return a content tree for the caption
bpatel@766 1304 */
bpatel@766 1305 public Content getTableCaption(String rawText) {
bpatel@766 1306 Content title = new RawHtml(rawText);
bpatel@766 1307 Content captionSpan = HtmlTree.SPAN(title);
bpatel@766 1308 Content space = getSpace();
bpatel@766 1309 Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, space);
bpatel@766 1310 Content caption = HtmlTree.CAPTION(captionSpan);
bpatel@766 1311 caption.addContent(tabSpan);
bpatel@766 1312 return caption;
bpatel@766 1313 }
bpatel@766 1314
bpatel@766 1315 /**
bpatel@766 1316 * Get the marker anchor which will be added to the documentation tree.
bpatel@766 1317 *
bpatel@766 1318 * @param anchorName the anchor name attribute
bpatel@766 1319 * @return a content tree for the marker anchor
bpatel@766 1320 */
bpatel@766 1321 public Content getMarkerAnchor(String anchorName) {
bpatel@766 1322 return getMarkerAnchor(anchorName, null);
bpatel@766 1323 }
bpatel@766 1324
bpatel@766 1325 /**
bpatel@766 1326 * Get the marker anchor which will be added to the documentation tree.
bpatel@766 1327 *
bpatel@766 1328 * @param anchorName the anchor name attribute
bpatel@766 1329 * @param anchorContent the content that should be added to the anchor
bpatel@766 1330 * @return a content tree for the marker anchor
bpatel@766 1331 */
bpatel@766 1332 public Content getMarkerAnchor(String anchorName, Content anchorContent) {
bpatel@766 1333 if (anchorContent == null)
bpatel@766 1334 anchorContent = new Comment(" ");
bpatel@766 1335 Content markerAnchor = HtmlTree.A_NAME(anchorName, anchorContent);
bpatel@766 1336 return markerAnchor;
bpatel@766 1337 }
bpatel@766 1338
bpatel@766 1339 /**
bpatel@766 1340 * Returns a packagename content.
bpatel@766 1341 *
bpatel@766 1342 * @param packageDoc the package to check
bpatel@766 1343 * @return package name content
bpatel@766 1344 */
bpatel@766 1345 public Content getPackageName(PackageDoc packageDoc) {
bpatel@766 1346 return packageDoc == null || packageDoc.name().length() == 0 ?
bpatel@766 1347 defaultPackageLabel :
bpatel@766 1348 getPackageLabel(packageDoc.name());
bpatel@766 1349 }
bpatel@766 1350
bpatel@766 1351 /**
bpatel@766 1352 * Returns a package name label.
bpatel@766 1353 *
jjg@1358 1354 * @param packageName the package name
bpatel@766 1355 * @return the package name content
bpatel@766 1356 */
bpatel@766 1357 public Content getPackageLabel(String packageName) {
bpatel@766 1358 return new StringContent(packageName);
bpatel@766 1359 }
bpatel@766 1360
bpatel@766 1361 /**
bpatel@995 1362 * Add package deprecation information to the documentation tree
bpatel@995 1363 *
bpatel@995 1364 * @param deprPkgs list of deprecated packages
bpatel@995 1365 * @param headingKey the caption for the deprecated package table
bpatel@995 1366 * @param tableSummary the summary for the deprecated package table
bpatel@995 1367 * @param tableHeader table headers for the deprecated package table
bpatel@995 1368 * @param contentTree the content tree to which the deprecated package table will be added
bpatel@995 1369 */
bpatel@995 1370 protected void addPackageDeprecatedAPI(List<Doc> deprPkgs, String headingKey,
bpatel@995 1371 String tableSummary, String[] tableHeader, Content contentTree) {
bpatel@995 1372 if (deprPkgs.size() > 0) {
bpatel@995 1373 Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
bpatel@995 1374 getTableCaption(configuration().getText(headingKey)));
bpatel@995 1375 table.addContent(getSummaryTableHeader(tableHeader, "col"));
bpatel@995 1376 Content tbody = new HtmlTree(HtmlTag.TBODY);
bpatel@995 1377 for (int i = 0; i < deprPkgs.size(); i++) {
bpatel@995 1378 PackageDoc pkg = (PackageDoc) deprPkgs.get(i);
bpatel@995 1379 HtmlTree td = HtmlTree.TD(HtmlStyle.colOne,
bpatel@995 1380 getPackageLink(pkg, getPackageName(pkg)));
bpatel@995 1381 if (pkg.tags("deprecated").length > 0) {
bpatel@995 1382 addInlineDeprecatedComment(pkg, pkg.tags("deprecated")[0], td);
bpatel@995 1383 }
bpatel@995 1384 HtmlTree tr = HtmlTree.TR(td);
bpatel@995 1385 if (i % 2 == 0) {
bpatel@995 1386 tr.addStyle(HtmlStyle.altColor);
bpatel@995 1387 } else {
bpatel@995 1388 tr.addStyle(HtmlStyle.rowColor);
bpatel@995 1389 }
bpatel@995 1390 tbody.addContent(tr);
bpatel@995 1391 }
bpatel@995 1392 table.addContent(tbody);
bpatel@995 1393 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@995 1394 Content ul = HtmlTree.UL(HtmlStyle.blockList, li);
bpatel@995 1395 contentTree.addContent(ul);
bpatel@995 1396 }
bpatel@995 1397 }
bpatel@995 1398
bpatel@995 1399 /**
duke@1 1400 * Prine table header information about color, column span and the font.
duke@1 1401 *
duke@1 1402 * @param color Background color.
duke@1 1403 * @param span Column span.
duke@1 1404 */
duke@1 1405 public void tableHeaderStart(String color, int span) {
duke@1 1406 trBgcolorStyle(color, "TableHeadingColor");
duke@1 1407 thAlignColspan("left", span);
duke@1 1408 font("+2");
duke@1 1409 }
duke@1 1410
duke@1 1411 /**
duke@1 1412 * Print table header for the inherited members summary tables. Print the
duke@1 1413 * background color information.
duke@1 1414 *
duke@1 1415 * @param color Background color.
duke@1 1416 */
duke@1 1417 public void tableInheritedHeaderStart(String color) {
duke@1 1418 trBgcolorStyle(color, "TableSubHeadingColor");
duke@1 1419 thAlign("left");
duke@1 1420 }
duke@1 1421
duke@1 1422 /**
duke@1 1423 * Print "Use" table header. Print the background color and the column span.
duke@1 1424 *
duke@1 1425 * @param color Background color.
duke@1 1426 */
duke@1 1427 public void tableUseInfoHeaderStart(String color) {
duke@1 1428 trBgcolorStyle(color, "TableSubHeadingColor");
duke@1 1429 thAlignColspan("left", 2);
duke@1 1430 }
duke@1 1431
duke@1 1432 /**
duke@1 1433 * Print table header with the background color with default column span 2.
duke@1 1434 *
duke@1 1435 * @param color Background color.
duke@1 1436 */
duke@1 1437 public void tableHeaderStart(String color) {
duke@1 1438 tableHeaderStart(color, 2);
duke@1 1439 }
duke@1 1440
duke@1 1441 /**
duke@1 1442 * Print table header with the column span, with the default color #CCCCFF.
duke@1 1443 *
duke@1 1444 * @param span Column span.
duke@1 1445 */
duke@1 1446 public void tableHeaderStart(int span) {
duke@1 1447 tableHeaderStart("#CCCCFF", span);
duke@1 1448 }
duke@1 1449
duke@1 1450 /**
duke@1 1451 * Print table header with default column span 2 and default color #CCCCFF.
duke@1 1452 */
duke@1 1453 public void tableHeaderStart() {
duke@1 1454 tableHeaderStart(2);
duke@1 1455 }
duke@1 1456
duke@1 1457 /**
duke@1 1458 * Print table header end tags for font, column and row.
duke@1 1459 */
duke@1 1460 public void tableHeaderEnd() {
duke@1 1461 fontEnd();
duke@1 1462 thEnd();
duke@1 1463 trEnd();
duke@1 1464 }
duke@1 1465
duke@1 1466 /**
duke@1 1467 * Print table header end tags in inherited tables for column and row.
duke@1 1468 */
duke@1 1469 public void tableInheritedHeaderEnd() {
duke@1 1470 thEnd();
duke@1 1471 trEnd();
duke@1 1472 }
duke@1 1473
duke@1 1474 /**
duke@1 1475 * Print the summary table row cell attribute width.
duke@1 1476 *
duke@1 1477 * @param width Width of the table cell.
duke@1 1478 */
duke@1 1479 public void summaryRow(int width) {
duke@1 1480 if (width != 0) {
duke@1 1481 tdWidth(width + "%");
duke@1 1482 } else {
duke@1 1483 td();
duke@1 1484 }
duke@1 1485 }
duke@1 1486
duke@1 1487 /**
duke@1 1488 * Print the summary table row cell end tag.
duke@1 1489 */
duke@1 1490 public void summaryRowEnd() {
duke@1 1491 tdEnd();
duke@1 1492 }
duke@1 1493
duke@1 1494 /**
jjg@1326 1495 * Print the heading in Html {@literal <H2>} format.
duke@1 1496 *
duke@1 1497 * @param str The Header string.
duke@1 1498 */
duke@1 1499 public void printIndexHeading(String str) {
duke@1 1500 h2();
duke@1 1501 print(str);
duke@1 1502 h2End();
duke@1 1503 }
duke@1 1504
duke@1 1505 /**
duke@1 1506 * Print Html tag &lt;FRAMESET=arg&gt;.
duke@1 1507 *
duke@1 1508 * @param arg Argument for the tag.
duke@1 1509 */
duke@1 1510 public void frameSet(String arg) {
duke@1 1511 println("<FRAMESET " + arg + ">");
duke@1 1512 }
duke@1 1513
duke@1 1514 /**
duke@1 1515 * Print Html closing tag &lt;/FRAMESET&gt;.
duke@1 1516 */
duke@1 1517 public void frameSetEnd() {
duke@1 1518 println("</FRAMESET>");
duke@1 1519 }
duke@1 1520
duke@1 1521 /**
duke@1 1522 * Print Html tag &lt;FRAME=arg&gt;.
duke@1 1523 *
duke@1 1524 * @param arg Argument for the tag.
duke@1 1525 */
duke@1 1526 public void frame(String arg) {
duke@1 1527 println("<FRAME " + arg + ">");
duke@1 1528 }
duke@1 1529
duke@1 1530 /**
duke@1 1531 * Print Html closing tag &lt;/FRAME&gt;.
duke@1 1532 */
duke@1 1533 public void frameEnd() {
duke@1 1534 println("</FRAME>");
duke@1 1535 }
duke@1 1536
duke@1 1537 /**
duke@1 1538 * Return path to the class page for a classdoc. For example, the class
duke@1 1539 * name is "java.lang.Object" and if the current file getting generated is
duke@1 1540 * "java/io/File.html", then the path string to the class, returned is
duke@1 1541 * "../../java/lang.Object.html".
duke@1 1542 *
duke@1 1543 * @param cd Class to which the path is requested.
duke@1 1544 */
duke@1 1545 protected String pathToClass(ClassDoc cd) {
duke@1 1546 return pathString(cd.containingPackage(), cd.name() + ".html");
duke@1 1547 }
duke@1 1548
duke@1 1549 /**
duke@1 1550 * Return the path to the class page for a classdoc. Works same as
duke@1 1551 * {@link #pathToClass(ClassDoc)}.
duke@1 1552 *
duke@1 1553 * @param cd Class to which the path is requested.
duke@1 1554 * @param name Name of the file(doesn't include path).
duke@1 1555 */
duke@1 1556 protected String pathString(ClassDoc cd, String name) {
duke@1 1557 return pathString(cd.containingPackage(), name);
duke@1 1558 }
duke@1 1559
duke@1 1560 /**
duke@1 1561 * Return path to the given file name in the given package. So if the name
duke@1 1562 * passed is "Object.html" and the name of the package is "java.lang", and
duke@1 1563 * if the relative path is "../.." then returned string will be
duke@1 1564 * "../../java/lang/Object.html"
duke@1 1565 *
duke@1 1566 * @param pd Package in which the file name is assumed to be.
duke@1 1567 * @param name File name, to which path string is.
duke@1 1568 */
duke@1 1569 protected String pathString(PackageDoc pd, String name) {
duke@1 1570 StringBuffer buf = new StringBuffer(relativePath);
duke@1 1571 buf.append(DirectoryManager.getPathToPackage(pd, name));
duke@1 1572 return buf.toString();
duke@1 1573 }
duke@1 1574
duke@1 1575 /**
duke@1 1576 * Print the link to the given package.
duke@1 1577 *
duke@1 1578 * @param pkg the package to link to.
duke@1 1579 * @param label the label for the link.
bpatel@182 1580 * @param isStrong true if the label should be strong.
duke@1 1581 */
bpatel@182 1582 public void printPackageLink(PackageDoc pkg, String label, boolean isStrong) {
bpatel@766 1583 print(getPackageLinkString(pkg, label, isStrong));
duke@1 1584 }
duke@1 1585
duke@1 1586 /**
duke@1 1587 * Print the link to the given package.
duke@1 1588 *
duke@1 1589 * @param pkg the package to link to.
duke@1 1590 * @param label the label for the link.
bpatel@182 1591 * @param isStrong true if the label should be strong.
duke@1 1592 * @param style the font of the package link label.
duke@1 1593 */
bpatel@182 1594 public void printPackageLink(PackageDoc pkg, String label, boolean isStrong,
duke@1 1595 String style) {
bpatel@766 1596 print(getPackageLinkString(pkg, label, isStrong, style));
duke@1 1597 }
duke@1 1598
duke@1 1599 /**
duke@1 1600 * Return the link to the given package.
duke@1 1601 *
duke@1 1602 * @param pkg the package to link to.
duke@1 1603 * @param label the label for the link.
bpatel@182 1604 * @param isStrong true if the label should be strong.
duke@1 1605 * @return the link to the given package.
duke@1 1606 */
bpatel@766 1607 public String getPackageLinkString(PackageDoc pkg, String label,
bpatel@182 1608 boolean isStrong) {
bpatel@766 1609 return getPackageLinkString(pkg, label, isStrong, "");
duke@1 1610 }
duke@1 1611
duke@1 1612 /**
duke@1 1613 * Return the link to the given package.
duke@1 1614 *
duke@1 1615 * @param pkg the package to link to.
duke@1 1616 * @param label the label for the link.
bpatel@182 1617 * @param isStrong true if the label should be strong.
duke@1 1618 * @param style the font of the package link label.
duke@1 1619 * @return the link to the given package.
duke@1 1620 */
bpatel@766 1621 public String getPackageLinkString(PackageDoc pkg, String label, boolean isStrong,
duke@1 1622 String style) {
duke@1 1623 boolean included = pkg != null && pkg.isIncluded();
duke@1 1624 if (! included) {
duke@1 1625 PackageDoc[] packages = configuration.packages;
duke@1 1626 for (int i = 0; i < packages.length; i++) {
duke@1 1627 if (packages[i].equals(pkg)) {
duke@1 1628 included = true;
duke@1 1629 break;
duke@1 1630 }
duke@1 1631 }
duke@1 1632 }
duke@1 1633 if (included || pkg == null) {
bpatel@766 1634 return getHyperLinkString(pathString(pkg, "package-summary.html"),
bpatel@182 1635 "", label, isStrong, style);
duke@1 1636 } else {
duke@1 1637 String crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
duke@1 1638 if (crossPkgLink != null) {
bpatel@766 1639 return getHyperLinkString(crossPkgLink, "", label, isStrong, style);
bpatel@766 1640 } else {
bpatel@766 1641 return label;
bpatel@766 1642 }
bpatel@766 1643 }
bpatel@766 1644 }
bpatel@766 1645
bpatel@766 1646 /**
bpatel@766 1647 * Return the link to the given package.
bpatel@766 1648 *
bpatel@766 1649 * @param pkg the package to link to.
bpatel@766 1650 * @param label the label for the link.
bpatel@766 1651 * @return a content tree for the package link.
bpatel@766 1652 */
bpatel@766 1653 public Content getPackageLink(PackageDoc pkg, Content label) {
bpatel@766 1654 boolean included = pkg != null && pkg.isIncluded();
bpatel@766 1655 if (! included) {
bpatel@766 1656 PackageDoc[] packages = configuration.packages;
bpatel@766 1657 for (int i = 0; i < packages.length; i++) {
bpatel@766 1658 if (packages[i].equals(pkg)) {
bpatel@766 1659 included = true;
bpatel@766 1660 break;
bpatel@766 1661 }
bpatel@766 1662 }
bpatel@766 1663 }
bpatel@766 1664 if (included || pkg == null) {
bpatel@766 1665 return getHyperLink(pathString(pkg, "package-summary.html"),
bpatel@766 1666 "", label);
bpatel@766 1667 } else {
bpatel@766 1668 String crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
bpatel@766 1669 if (crossPkgLink != null) {
bpatel@766 1670 return getHyperLink(crossPkgLink, "", label);
duke@1 1671 } else {
duke@1 1672 return label;
duke@1 1673 }
duke@1 1674 }
duke@1 1675 }
duke@1 1676
duke@1 1677 public String italicsClassName(ClassDoc cd, boolean qual) {
duke@1 1678 String name = (qual)? cd.qualifiedName(): cd.name();
duke@1 1679 return (cd.isInterface())? italicsText(name): name;
duke@1 1680 }
duke@1 1681
duke@1 1682 public void printSrcLink(ProgramElementDoc d, String label) {
duke@1 1683 if (d == null) {
duke@1 1684 return;
duke@1 1685 }
duke@1 1686 ClassDoc cd = d.containingClass();
duke@1 1687 if (cd == null) {
duke@1 1688 //d must be a class doc since in has no containing class.
duke@1 1689 cd = (ClassDoc) d;
duke@1 1690 }
duke@1 1691 String href = relativePath + DocletConstants.SOURCE_OUTPUT_DIR_NAME
duke@1 1692 + DirectoryManager.getDirectoryPath(cd.containingPackage())
duke@1 1693 + cd.name() + ".html#" + SourceToHTMLConverter.getAnchorName(d);
duke@1 1694 printHyperLink(href, "", label, true);
duke@1 1695 }
duke@1 1696
duke@1 1697 /**
bpatel@766 1698 * Add the link to the content tree.
bpatel@766 1699 *
bpatel@766 1700 * @param doc program element doc for which the link will be added
bpatel@766 1701 * @param label label for the link
bpatel@766 1702 * @param htmltree the content tree to which the link will be added
bpatel@766 1703 */
bpatel@766 1704 public void addSrcLink(ProgramElementDoc doc, Content label, Content htmltree) {
bpatel@766 1705 if (doc == null) {
bpatel@766 1706 return;
bpatel@766 1707 }
bpatel@766 1708 ClassDoc cd = doc.containingClass();
bpatel@766 1709 if (cd == null) {
bpatel@766 1710 //d must be a class doc since in has no containing class.
bpatel@766 1711 cd = (ClassDoc) doc;
bpatel@766 1712 }
bpatel@766 1713 String href = relativePath + DocletConstants.SOURCE_OUTPUT_DIR_NAME
bpatel@766 1714 + DirectoryManager.getDirectoryPath(cd.containingPackage())
bpatel@766 1715 + cd.name() + ".html#" + SourceToHTMLConverter.getAnchorName(doc);
bpatel@766 1716 Content linkContent = getHyperLink(href, "", label, "", "");
bpatel@766 1717 htmltree.addContent(linkContent);
bpatel@766 1718 }
bpatel@766 1719
bpatel@766 1720 /**
duke@1 1721 * Return the link to the given class.
duke@1 1722 *
duke@1 1723 * @param linkInfo the information about the link.
duke@1 1724 *
duke@1 1725 * @return the link for the given class.
duke@1 1726 */
duke@1 1727 public String getLink(LinkInfoImpl linkInfo) {
duke@1 1728 LinkFactoryImpl factory = new LinkFactoryImpl(this);
duke@1 1729 String link = ((LinkOutputImpl) factory.getLinkOutput(linkInfo)).toString();
duke@1 1730 displayLength += linkInfo.displayLength;
duke@1 1731 return link;
duke@1 1732 }
duke@1 1733
duke@1 1734 /**
duke@1 1735 * Return the type parameters for the given class.
duke@1 1736 *
duke@1 1737 * @param linkInfo the information about the link.
duke@1 1738 * @return the type for the given class.
duke@1 1739 */
duke@1 1740 public String getTypeParameterLinks(LinkInfoImpl linkInfo) {
duke@1 1741 LinkFactoryImpl factory = new LinkFactoryImpl(this);
duke@1 1742 return ((LinkOutputImpl)
duke@1 1743 factory.getTypeParameterLinks(linkInfo, false)).toString();
duke@1 1744 }
duke@1 1745
duke@1 1746 /**
duke@1 1747 * Print the link to the given class.
duke@1 1748 */
duke@1 1749 public void printLink(LinkInfoImpl linkInfo) {
duke@1 1750 print(getLink(linkInfo));
duke@1 1751 }
duke@1 1752
duke@1 1753 /*************************************************************
duke@1 1754 * Return a class cross link to external class documentation.
duke@1 1755 * The name must be fully qualified to determine which package
duke@1 1756 * the class is in. The -link option does not allow users to
duke@1 1757 * link to external classes in the "default" package.
duke@1 1758 *
duke@1 1759 * @param qualifiedClassName the qualified name of the external class.
duke@1 1760 * @param refMemName the name of the member being referenced. This should
duke@1 1761 * be null or empty string if no member is being referenced.
duke@1 1762 * @param label the label for the external link.
bpatel@182 1763 * @param strong true if the link should be strong.
duke@1 1764 * @param style the style of the link.
duke@1 1765 * @param code true if the label should be code font.
duke@1 1766 */
duke@1 1767 public String getCrossClassLink(String qualifiedClassName, String refMemName,
bpatel@182 1768 String label, boolean strong, String style,
duke@1 1769 boolean code) {
duke@1 1770 String className = "",
duke@1 1771 packageName = qualifiedClassName == null ? "" : qualifiedClassName;
duke@1 1772 int periodIndex;
duke@1 1773 while((periodIndex = packageName.lastIndexOf('.')) != -1) {
duke@1 1774 className = packageName.substring(periodIndex + 1, packageName.length()) +
duke@1 1775 (className.length() > 0 ? "." + className : "");
duke@1 1776 String defaultLabel = code ? getCode() + className + getCodeEnd() : className;
duke@1 1777 packageName = packageName.substring(0, periodIndex);
duke@1 1778 if (getCrossPackageLink(packageName) != null) {
duke@1 1779 //The package exists in external documentation, so link to the external
duke@1 1780 //class (assuming that it exists). This is definitely a limitation of
duke@1 1781 //the -link option. There are ways to determine if an external package
duke@1 1782 //exists, but no way to determine if the external class exists. We just
duke@1 1783 //have to assume that it does.
bpatel@766 1784 return getHyperLinkString(
duke@1 1785 configuration.extern.getExternalLink(packageName, relativePath,
duke@1 1786 className + ".html?is-external=true"),
duke@1 1787 refMemName == null ? "" : refMemName,
duke@1 1788 label == null || label.length() == 0 ? defaultLabel : label,
bpatel@182 1789 strong, style,
duke@1 1790 configuration.getText("doclet.Href_Class_Or_Interface_Title", packageName),
duke@1 1791 "");
duke@1 1792 }
duke@1 1793 }
duke@1 1794 return null;
duke@1 1795 }
duke@1 1796
duke@1 1797 public boolean isClassLinkable(ClassDoc cd) {
duke@1 1798 if (cd.isIncluded()) {
duke@1 1799 return configuration.isGeneratedDoc(cd);
duke@1 1800 }
duke@1 1801 return configuration.extern.isExternal(cd);
duke@1 1802 }
duke@1 1803
duke@1 1804 public String getCrossPackageLink(String pkgName) {
duke@1 1805 return configuration.extern.getExternalLink(pkgName, relativePath,
duke@1 1806 "package-summary.html?is-external=true");
duke@1 1807 }
duke@1 1808
bpatel@766 1809 /**
bpatel@766 1810 * Get the class link.
bpatel@766 1811 *
bpatel@766 1812 * @param context the id of the context where the link will be added
bpatel@766 1813 * @param cd the class doc to link to
bpatel@766 1814 * @return a content tree for the link
bpatel@766 1815 */
bpatel@766 1816 public Content getQualifiedClassLink(int context, ClassDoc cd) {
bpatel@766 1817 return new RawHtml(getLink(new LinkInfoImpl(context, cd,
bpatel@766 1818 configuration.getClassName(cd), "")));
duke@1 1819 }
duke@1 1820
duke@1 1821 /**
bpatel@766 1822 * Add the class link.
bpatel@766 1823 *
bpatel@766 1824 * @param context the id of the context where the link will be added
bpatel@766 1825 * @param cd the class doc to link to
bpatel@766 1826 * @param contentTree the content tree to which the link will be added
duke@1 1827 */
bpatel@766 1828 public void addPreQualifiedClassLink(int context, ClassDoc cd, Content contentTree) {
bpatel@766 1829 addPreQualifiedClassLink(context, cd, false, contentTree);
duke@1 1830 }
duke@1 1831
duke@1 1832 /**
duke@1 1833 * Retrieve the class link with the package portion of the label in
duke@1 1834 * plain text. If the qualifier is excluded, it willnot be included in the
duke@1 1835 * link label.
duke@1 1836 *
duke@1 1837 * @param cd the class to link to.
bpatel@182 1838 * @param isStrong true if the link should be strong.
duke@1 1839 * @return the link with the package portion of the label in plain text.
duke@1 1840 */
duke@1 1841 public String getPreQualifiedClassLink(int context,
bpatel@182 1842 ClassDoc cd, boolean isStrong) {
duke@1 1843 String classlink = "";
duke@1 1844 PackageDoc pd = cd.containingPackage();
duke@1 1845 if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
duke@1 1846 classlink = getPkgName(cd);
duke@1 1847 }
bpatel@182 1848 classlink += getLink(new LinkInfoImpl(context, cd, cd.name(), isStrong));
duke@1 1849 return classlink;
duke@1 1850 }
duke@1 1851
bpatel@766 1852 /**
bpatel@766 1853 * Add the class link with the package portion of the label in
bpatel@766 1854 * plain text. If the qualifier is excluded, it will not be included in the
bpatel@766 1855 * link label.
bpatel@766 1856 *
bpatel@766 1857 * @param context the id of the context where the link will be added
bpatel@766 1858 * @param cd the class to link to
bpatel@766 1859 * @param isStrong true if the link should be strong
bpatel@766 1860 * @param contentTree the content tree to which the link with be added
bpatel@766 1861 */
bpatel@766 1862 public void addPreQualifiedClassLink(int context,
bpatel@766 1863 ClassDoc cd, boolean isStrong, Content contentTree) {
bpatel@766 1864 PackageDoc pd = cd.containingPackage();
bpatel@766 1865 if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
bpatel@766 1866 contentTree.addContent(getPkgName(cd));
bpatel@766 1867 }
bpatel@766 1868 contentTree.addContent(new RawHtml(getLink(new LinkInfoImpl(
bpatel@766 1869 context, cd, cd.name(), isStrong))));
bpatel@766 1870 }
duke@1 1871
duke@1 1872 /**
bpatel@766 1873 * Add the class link, with only class name as the strong link and prefixing
duke@1 1874 * plain package name.
bpatel@766 1875 *
bpatel@766 1876 * @param context the id of the context where the link will be added
bpatel@766 1877 * @param cd the class to link to
bpatel@766 1878 * @param contentTree the content tree to which the link with be added
duke@1 1879 */
bpatel@766 1880 public void addPreQualifiedStrongClassLink(int context, ClassDoc cd, Content contentTree) {
bpatel@766 1881 addPreQualifiedClassLink(context, cd, true, contentTree);
duke@1 1882 }
duke@1 1883
duke@1 1884 public void printText(String key) {
duke@1 1885 print(configuration.getText(key));
duke@1 1886 }
duke@1 1887
duke@1 1888 public void printText(String key, String a1) {
duke@1 1889 print(configuration.getText(key, a1));
duke@1 1890 }
duke@1 1891
duke@1 1892 public void printText(String key, String a1, String a2) {
duke@1 1893 print(configuration.getText(key, a1, a2));
duke@1 1894 }
duke@1 1895
bpatel@182 1896 public void strongText(String key) {
bpatel@182 1897 strong(configuration.getText(key));
duke@1 1898 }
duke@1 1899
bpatel@182 1900 public void strongText(String key, String a1) {
bpatel@182 1901 strong(configuration.getText(key, a1));
duke@1 1902 }
duke@1 1903
bpatel@182 1904 public void strongText(String key, String a1, String a2) {
bpatel@182 1905 strong(configuration.getText(key, a1, a2));
duke@1 1906 }
duke@1 1907
duke@1 1908 /**
bpatel@766 1909 * Get the link for the given member.
duke@1 1910 *
bpatel@766 1911 * @param context the id of the context where the link will be added
bpatel@766 1912 * @param doc the member being linked to
bpatel@766 1913 * @param label the label for the link
bpatel@766 1914 * @return a content tree for the doc link
duke@1 1915 */
bpatel@766 1916 public Content getDocLink(int context, MemberDoc doc, String label) {
bpatel@766 1917 return getDocLink(context, doc.containingClass(), doc, label);
duke@1 1918 }
duke@1 1919
duke@1 1920 /**
duke@1 1921 * Print the link for the given member.
duke@1 1922 *
duke@1 1923 * @param context the id of the context where the link will be printed.
duke@1 1924 * @param classDoc the classDoc that we should link to. This is not
duke@1 1925 * necessarily equal to doc.containingClass(). We may be
duke@1 1926 * inheriting comments.
duke@1 1927 * @param doc the member being linked to.
duke@1 1928 * @param label the label for the link.
bpatel@182 1929 * @param strong true if the link should be strong.
duke@1 1930 */
duke@1 1931 public void printDocLink(int context, ClassDoc classDoc, MemberDoc doc,
bpatel@182 1932 String label, boolean strong) {
bpatel@182 1933 print(getDocLink(context, classDoc, doc, label, strong));
duke@1 1934 }
duke@1 1935
duke@1 1936 /**
duke@1 1937 * Return the link for the given member.
duke@1 1938 *
duke@1 1939 * @param context the id of the context where the link will be printed.
duke@1 1940 * @param doc the member being linked to.
duke@1 1941 * @param label the label for the link.
bpatel@182 1942 * @param strong true if the link should be strong.
duke@1 1943 * @return the link for the given member.
duke@1 1944 */
duke@1 1945 public String getDocLink(int context, MemberDoc doc, String label,
bpatel@182 1946 boolean strong) {
bpatel@182 1947 return getDocLink(context, doc.containingClass(), doc, label, strong);
duke@1 1948 }
duke@1 1949
duke@1 1950 /**
duke@1 1951 * Return the link for the given member.
duke@1 1952 *
duke@1 1953 * @param context the id of the context where the link will be printed.
duke@1 1954 * @param classDoc the classDoc that we should link to. This is not
duke@1 1955 * necessarily equal to doc.containingClass(). We may be
duke@1 1956 * inheriting comments.
duke@1 1957 * @param doc the member being linked to.
duke@1 1958 * @param label the label for the link.
bpatel@182 1959 * @param strong true if the link should be strong.
duke@1 1960 * @return the link for the given member.
duke@1 1961 */
duke@1 1962 public String getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
bpatel@182 1963 String label, boolean strong) {
duke@1 1964 if (! (doc.isIncluded() ||
duke@1 1965 Util.isLinkable(classDoc, configuration()))) {
duke@1 1966 return label;
duke@1 1967 } else if (doc instanceof ExecutableMemberDoc) {
duke@1 1968 ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
duke@1 1969 return getLink(new LinkInfoImpl(context, classDoc,
bpatel@182 1970 getAnchor(emd), label, strong));
duke@1 1971 } else if (doc instanceof MemberDoc) {
duke@1 1972 return getLink(new LinkInfoImpl(context, classDoc,
bpatel@182 1973 doc.name(), label, strong));
duke@1 1974 } else {
duke@1 1975 return label;
duke@1 1976 }
duke@1 1977 }
duke@1 1978
bpatel@766 1979 /**
bpatel@766 1980 * Return the link for the given member.
bpatel@766 1981 *
bpatel@766 1982 * @param context the id of the context where the link will be added
bpatel@766 1983 * @param classDoc the classDoc that we should link to. This is not
bpatel@766 1984 * necessarily equal to doc.containingClass(). We may be
bpatel@766 1985 * inheriting comments
bpatel@766 1986 * @param doc the member being linked to
bpatel@766 1987 * @param label the label for the link
bpatel@766 1988 * @return the link for the given member
bpatel@766 1989 */
bpatel@766 1990 public Content getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
bpatel@766 1991 String label) {
bpatel@766 1992 if (! (doc.isIncluded() ||
bpatel@766 1993 Util.isLinkable(classDoc, configuration()))) {
bpatel@766 1994 return new StringContent(label);
bpatel@766 1995 } else if (doc instanceof ExecutableMemberDoc) {
bpatel@766 1996 ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
bpatel@766 1997 return new RawHtml(getLink(new LinkInfoImpl(context, classDoc,
bpatel@766 1998 getAnchor(emd), label, false)));
bpatel@766 1999 } else if (doc instanceof MemberDoc) {
bpatel@766 2000 return new RawHtml(getLink(new LinkInfoImpl(context, classDoc,
bpatel@766 2001 doc.name(), label, false)));
bpatel@766 2002 } else {
bpatel@766 2003 return new StringContent(label);
bpatel@766 2004 }
bpatel@766 2005 }
bpatel@766 2006
duke@1 2007 public void anchor(ExecutableMemberDoc emd) {
duke@1 2008 anchor(getAnchor(emd));
duke@1 2009 }
duke@1 2010
duke@1 2011 public String getAnchor(ExecutableMemberDoc emd) {
duke@1 2012 StringBuilder signature = new StringBuilder(emd.signature());
duke@1 2013 StringBuilder signatureParsed = new StringBuilder();
duke@1 2014 int counter = 0;
duke@1 2015 for (int i = 0; i < signature.length(); i++) {
duke@1 2016 char c = signature.charAt(i);
duke@1 2017 if (c == '<') {
duke@1 2018 counter++;
duke@1 2019 } else if (c == '>') {
duke@1 2020 counter--;
duke@1 2021 } else if (counter == 0) {
duke@1 2022 signatureParsed.append(c);
duke@1 2023 }
duke@1 2024 }
duke@1 2025 return emd.name() + signatureParsed.toString();
duke@1 2026 }
duke@1 2027
duke@1 2028 public String seeTagToString(SeeTag see) {
duke@1 2029 String tagName = see.name();
duke@1 2030 if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
duke@1 2031 return "";
duke@1 2032 }
duke@1 2033 StringBuffer result = new StringBuffer();
duke@1 2034 boolean isplaintext = tagName.toLowerCase().equals("@linkplain");
duke@1 2035 String label = see.label();
duke@1 2036 label = (label.length() > 0)?
duke@1 2037 ((isplaintext) ? label :
duke@1 2038 getCode() + label + getCodeEnd()):"";
duke@1 2039 String seetext = replaceDocRootDir(see.text());
duke@1 2040
duke@1 2041 //Check if @see is an href or "string"
duke@1 2042 if (seetext.startsWith("<") || seetext.startsWith("\"")) {
duke@1 2043 result.append(seetext);
duke@1 2044 return result.toString();
duke@1 2045 }
duke@1 2046
duke@1 2047 //The text from the @see tag. We will output this text when a label is not specified.
duke@1 2048 String text = (isplaintext) ? seetext : getCode() + seetext + getCodeEnd();
duke@1 2049
duke@1 2050 ClassDoc refClass = see.referencedClass();
duke@1 2051 String refClassName = see.referencedClassName();
duke@1 2052 MemberDoc refMem = see.referencedMember();
duke@1 2053 String refMemName = see.referencedMemberName();
duke@1 2054 if (refClass == null) {
duke@1 2055 //@see is not referencing an included class
duke@1 2056 PackageDoc refPackage = see.referencedPackage();
duke@1 2057 if (refPackage != null && refPackage.isIncluded()) {
duke@1 2058 //@see is referencing an included package
duke@1 2059 String packageName = isplaintext ? refPackage.name() :
duke@1 2060 getCode() + refPackage.name() + getCodeEnd();
bpatel@766 2061 result.append(getPackageLinkString(refPackage,
duke@1 2062 label.length() == 0 ? packageName : label, false));
duke@1 2063 } else {
duke@1 2064 //@see is not referencing an included class or package. Check for cross links.
duke@1 2065 String classCrossLink, packageCrossLink = getCrossPackageLink(refClassName);
duke@1 2066 if (packageCrossLink != null) {
duke@1 2067 //Package cross link found
bpatel@766 2068 result.append(getHyperLinkString(packageCrossLink, "",
duke@1 2069 (label.length() == 0)? text : label, false));
duke@1 2070 } else if ((classCrossLink = getCrossClassLink(refClassName,
duke@1 2071 refMemName, label, false, "", ! isplaintext)) != null) {
duke@1 2072 //Class cross link found (possiblly to a member in the class)
duke@1 2073 result.append(classCrossLink);
duke@1 2074 } else {
duke@1 2075 //No cross link found so print warning
duke@1 2076 configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
duke@1 2077 tagName, seetext);
duke@1 2078 result.append((label.length() == 0)? text: label);
duke@1 2079 }
duke@1 2080 }
duke@1 2081 } else if (refMemName == null) {
duke@1 2082 // Must be a class reference since refClass is not null and refMemName is null.
duke@1 2083 if (label.length() == 0) {
duke@1 2084 label = (isplaintext) ? refClass.name() : getCode() + refClass.name() + getCodeEnd();
duke@1 2085 result.append(getLink(new LinkInfoImpl(refClass, label)));
duke@1 2086 } else {
duke@1 2087 result.append(getLink(new LinkInfoImpl(refClass, label)));
duke@1 2088 }
duke@1 2089 } else if (refMem == null) {
duke@1 2090 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 2091 // However, refMem is null, so this referenced member does not exist.
duke@1 2092 result.append((label.length() == 0)? text: label);
duke@1 2093 } else {
duke@1 2094 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 2095 // refMem is not null, so this @see tag must be referencing a valid member.
duke@1 2096 ClassDoc containing = refMem.containingClass();
duke@1 2097 if (see.text().trim().startsWith("#") &&
duke@1 2098 ! (containing.isPublic() ||
duke@1 2099 Util.isLinkable(containing, configuration()))) {
duke@1 2100 // Since the link is relative and the holder is not even being
duke@1 2101 // documented, this must be an inherited link. Redirect it.
duke@1 2102 // The current class either overrides the referenced member or
duke@1 2103 // inherits it automatically.
jjg@405 2104 if (this instanceof ClassWriterImpl) {
jjg@405 2105 containing = ((ClassWriterImpl) this).getClassDoc();
jjg@405 2106 } else if (!containing.isPublic()){
jjg@405 2107 configuration.getDocletSpecificMsg().warning(
jjg@405 2108 see.position(), "doclet.see.class_or_package_not_accessible",
jjg@405 2109 tagName, containing.qualifiedName());
jjg@405 2110 } else {
jjg@405 2111 configuration.getDocletSpecificMsg().warning(
jjg@405 2112 see.position(), "doclet.see.class_or_package_not_found",
jjg@405 2113 tagName, seetext);
jjg@405 2114 }
duke@1 2115 }
duke@1 2116 if (configuration.currentcd != containing) {
duke@1 2117 refMemName = containing.name() + "." + refMemName;
duke@1 2118 }
duke@1 2119 if (refMem instanceof ExecutableMemberDoc) {
duke@1 2120 if (refMemName.indexOf('(') < 0) {
duke@1 2121 refMemName += ((ExecutableMemberDoc)refMem).signature();
duke@1 2122 }
duke@1 2123 }
duke@1 2124 text = (isplaintext) ?
bpatel@981 2125 refMemName : getCode() + Util.escapeHtmlChars(refMemName) + getCodeEnd();
duke@1 2126
duke@1 2127 result.append(getDocLink(LinkInfoImpl.CONTEXT_SEE_TAG, containing,
duke@1 2128 refMem, (label.length() == 0)? text: label, false));
duke@1 2129 }
duke@1 2130 return result.toString();
duke@1 2131 }
duke@1 2132
duke@1 2133 public void printInlineComment(Doc doc, Tag tag) {
duke@1 2134 printCommentTags(doc, tag.inlineTags(), false, false);
duke@1 2135 }
duke@1 2136
bpatel@766 2137 /**
bpatel@766 2138 * Add the inline comment.
bpatel@766 2139 *
bpatel@766 2140 * @param doc the doc for which the inline comment will be added
bpatel@766 2141 * @param tag the inline tag to be added
bpatel@766 2142 * @param htmltree the content tree to which the comment will be added
bpatel@766 2143 */
bpatel@766 2144 public void addInlineComment(Doc doc, Tag tag, Content htmltree) {
bpatel@766 2145 addCommentTags(doc, tag.inlineTags(), false, false, htmltree);
bpatel@766 2146 }
bpatel@766 2147
duke@1 2148 public void printInlineDeprecatedComment(Doc doc, Tag tag) {
duke@1 2149 printCommentTags(doc, tag.inlineTags(), true, false);
duke@1 2150 }
duke@1 2151
bpatel@766 2152 /**
bpatel@766 2153 * Add the inline deprecated comment.
bpatel@766 2154 *
bpatel@766 2155 * @param doc the doc for which the inline deprecated comment will be added
bpatel@766 2156 * @param tag the inline tag to be added
bpatel@766 2157 * @param htmltree the content tree to which the comment will be added
bpatel@766 2158 */
bpatel@766 2159 public void addInlineDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
bpatel@766 2160 addCommentTags(doc, tag.inlineTags(), true, false, htmltree);
bpatel@766 2161 }
bpatel@766 2162
duke@1 2163 public void printSummaryComment(Doc doc) {
duke@1 2164 printSummaryComment(doc, doc.firstSentenceTags());
duke@1 2165 }
duke@1 2166
bpatel@766 2167 /**
bpatel@766 2168 * Adds the summary content.
bpatel@766 2169 *
bpatel@766 2170 * @param doc the doc for which the summary will be generated
bpatel@766 2171 * @param htmltree the documentation tree to which the summary will be added
bpatel@766 2172 */
bpatel@766 2173 public void addSummaryComment(Doc doc, Content htmltree) {
bpatel@766 2174 addSummaryComment(doc, doc.firstSentenceTags(), htmltree);
bpatel@766 2175 }
bpatel@766 2176
duke@1 2177 public void printSummaryComment(Doc doc, Tag[] firstSentenceTags) {
duke@1 2178 printCommentTags(doc, firstSentenceTags, false, true);
duke@1 2179 }
duke@1 2180
bpatel@766 2181 /**
bpatel@766 2182 * Adds the summary content.
bpatel@766 2183 *
bpatel@766 2184 * @param doc the doc for which the summary will be generated
bpatel@766 2185 * @param firstSentenceTags the first sentence tags for the doc
bpatel@766 2186 * @param htmltree the documentation tree to which the summary will be added
bpatel@766 2187 */
bpatel@766 2188 public void addSummaryComment(Doc doc, Tag[] firstSentenceTags, Content htmltree) {
bpatel@766 2189 addCommentTags(doc, firstSentenceTags, false, true, htmltree);
bpatel@766 2190 }
bpatel@766 2191
duke@1 2192 public void printSummaryDeprecatedComment(Doc doc) {
duke@1 2193 printCommentTags(doc, doc.firstSentenceTags(), true, true);
duke@1 2194 }
duke@1 2195
duke@1 2196 public void printSummaryDeprecatedComment(Doc doc, Tag tag) {
duke@1 2197 printCommentTags(doc, tag.firstSentenceTags(), true, true);
duke@1 2198 }
duke@1 2199
bpatel@766 2200 public void addSummaryDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
bpatel@766 2201 addCommentTags(doc, tag.firstSentenceTags(), true, true, htmltree);
bpatel@766 2202 }
bpatel@766 2203
duke@1 2204 public void printInlineComment(Doc doc) {
duke@1 2205 printCommentTags(doc, doc.inlineTags(), false, false);
duke@1 2206 p();
duke@1 2207 }
duke@1 2208
bpatel@766 2209 /**
bpatel@766 2210 * Adds the inline comment.
bpatel@766 2211 *
bpatel@766 2212 * @param doc the doc for which the inline comments will be generated
bpatel@766 2213 * @param htmltree the documentation tree to which the inline comments will be added
bpatel@766 2214 */
bpatel@766 2215 public void addInlineComment(Doc doc, Content htmltree) {
bpatel@766 2216 addCommentTags(doc, doc.inlineTags(), false, false, htmltree);
bpatel@766 2217 }
bpatel@766 2218
duke@1 2219 public void printInlineDeprecatedComment(Doc doc) {
duke@1 2220 printCommentTags(doc, doc.inlineTags(), true, false);
duke@1 2221 }
duke@1 2222
duke@1 2223 private void printCommentTags(Doc doc, Tag[] tags, boolean depr, boolean first) {
duke@1 2224 if(configuration.nocomment){
duke@1 2225 return;
duke@1 2226 }
duke@1 2227 if (depr) {
duke@1 2228 italic();
duke@1 2229 }
duke@1 2230 String result = commentTagsToString(null, doc, tags, first);
duke@1 2231 print(result);
duke@1 2232 if (depr) {
duke@1 2233 italicEnd();
duke@1 2234 }
duke@1 2235 if (tags.length == 0) {
duke@1 2236 space();
duke@1 2237 }
duke@1 2238 }
duke@1 2239
duke@1 2240 /**
bpatel@766 2241 * Adds the comment tags.
bpatel@766 2242 *
bpatel@766 2243 * @param doc the doc for which the comment tags will be generated
bpatel@766 2244 * @param tags the first sentence tags for the doc
bpatel@766 2245 * @param depr true if it is deprecated
bpatel@766 2246 * @param first true if the first sentenge tags should be added
bpatel@766 2247 * @param htmltree the documentation tree to which the comment tags will be added
bpatel@766 2248 */
bpatel@766 2249 private void addCommentTags(Doc doc, Tag[] tags, boolean depr,
bpatel@766 2250 boolean first, Content htmltree) {
bpatel@766 2251 if(configuration.nocomment){
bpatel@766 2252 return;
bpatel@766 2253 }
bpatel@766 2254 Content div;
bpatel@766 2255 Content result = new RawHtml(commentTagsToString(null, doc, tags, first));
bpatel@766 2256 if (depr) {
bpatel@766 2257 Content italic = HtmlTree.I(result);
bpatel@766 2258 div = HtmlTree.DIV(HtmlStyle.block, italic);
bpatel@766 2259 htmltree.addContent(div);
bpatel@766 2260 }
bpatel@766 2261 else {
bpatel@766 2262 div = HtmlTree.DIV(HtmlStyle.block, result);
bpatel@766 2263 htmltree.addContent(div);
bpatel@766 2264 }
bpatel@766 2265 if (tags.length == 0) {
bpatel@766 2266 htmltree.addContent(getSpace());
bpatel@766 2267 }
bpatel@766 2268 }
bpatel@766 2269
bpatel@766 2270 /**
duke@1 2271 * Converts inline tags and text to text strings, expanding the
duke@1 2272 * inline tags along the way. Called wherever text can contain
duke@1 2273 * an inline tag, such as in comments or in free-form text arguments
duke@1 2274 * to non-inline tags.
duke@1 2275 *
duke@1 2276 * @param holderTag specific tag where comment resides
duke@1 2277 * @param doc specific doc where comment resides
duke@1 2278 * @param tags array of text tags and inline tags (often alternating)
duke@1 2279 * present in the text of interest for this doc
duke@1 2280 * @param isFirstSentence true if text is first sentence
duke@1 2281 */
duke@1 2282 public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
duke@1 2283 boolean isFirstSentence) {
jjg@910 2284 StringBuilder result = new StringBuilder();
bpatel@997 2285 boolean textTagChange = false;
duke@1 2286 // Array of all possible inline tags for this javadoc run
duke@1 2287 configuration.tagletManager.checkTags(doc, tags, true);
duke@1 2288 for (int i = 0; i < tags.length; i++) {
duke@1 2289 Tag tagelem = tags[i];
duke@1 2290 String tagName = tagelem.name();
duke@1 2291 if (tagelem instanceof SeeTag) {
duke@1 2292 result.append(seeTagToString((SeeTag)tagelem));
duke@1 2293 } else if (! tagName.equals("Text")) {
duke@1 2294 int originalLength = result.length();
duke@1 2295 TagletOutput output = TagletWriter.getInlineTagOuput(
duke@1 2296 configuration.tagletManager, holderTag,
jjg@74 2297 tagelem, getTagletWriterInstance(isFirstSentence));
duke@1 2298 result.append(output == null ? "" : output.toString());
duke@1 2299 if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
duke@1 2300 break;
bpatel@997 2301 } else if (configuration.docrootparent.length() > 0 &&
bpatel@997 2302 tagelem.name().equals("@docRoot") &&
bpatel@997 2303 ((tags[i + 1]).text()).startsWith("/..")) {
bpatel@997 2304 //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
bpatel@997 2305 //{@docRoot} tag in the very next Text tag.
bpatel@997 2306 textTagChange = true;
bpatel@997 2307 continue;
duke@1 2308 } else {
bpatel@997 2309 continue;
duke@1 2310 }
duke@1 2311 } else {
bpatel@997 2312 String text = tagelem.text();
bpatel@997 2313 //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
bpatel@997 2314 if (textTagChange) {
bpatel@997 2315 text = text.replaceFirst("/..", "");
bpatel@997 2316 textTagChange = false;
bpatel@997 2317 }
duke@1 2318 //This is just a regular text tag. The text may contain html links (<a>)
duke@1 2319 //or inline tag {@docRoot}, which will be handled as special cases.
bpatel@997 2320 text = redirectRelativeLinks(tagelem.holder(), text);
duke@1 2321
duke@1 2322 // Replace @docRoot only if not represented by an instance of DocRootTaglet,
duke@1 2323 // that is, only if it was not present in a source file doc comment.
duke@1 2324 // This happens when inserted by the doclet (a few lines
duke@1 2325 // above in this method). [It might also happen when passed in on the command
duke@1 2326 // line as a text argument to an option (like -header).]
duke@1 2327 text = replaceDocRootDir(text);
duke@1 2328 if (isFirstSentence) {
duke@1 2329 text = removeNonInlineHtmlTags(text);
duke@1 2330 }
duke@1 2331 StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
duke@1 2332 StringBuffer textBuff = new StringBuffer();
duke@1 2333 while (lines.hasMoreTokens()) {
jjg@910 2334 StringBuilder line = new StringBuilder(lines.nextToken());
duke@1 2335 Util.replaceTabs(configuration.sourcetab, line);
duke@1 2336 textBuff.append(line.toString());
duke@1 2337 }
duke@1 2338 result.append(textBuff);
duke@1 2339 }
duke@1 2340 }
duke@1 2341 return result.toString();
duke@1 2342 }
duke@1 2343
duke@1 2344 /**
duke@1 2345 * Return true if relative links should not be redirected.
duke@1 2346 *
duke@1 2347 * @return Return true if a relative link should not be redirected.
duke@1 2348 */
duke@1 2349 private boolean shouldNotRedirectRelativeLinks() {
duke@1 2350 return this instanceof AnnotationTypeWriter ||
duke@1 2351 this instanceof ClassWriter ||
duke@1 2352 this instanceof PackageSummaryWriter;
duke@1 2353 }
duke@1 2354
duke@1 2355 /**
duke@1 2356 * Suppose a piece of documentation has a relative link. When you copy
duke@1 2357 * that documetation to another place such as the index or class-use page,
duke@1 2358 * that relative link will no longer work. We should redirect those links
duke@1 2359 * so that they will work again.
duke@1 2360 * <p>
duke@1 2361 * Here is the algorithm used to fix the link:
duke@1 2362 * <p>
jjg@1326 2363 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
duke@1 2364 * <p>
duke@1 2365 * For example, suppose com.sun.javadoc.RootDoc has this link:
jjg@1326 2366 * {@literal <a href="package-summary.html">The package Page</a> }
duke@1 2367 * <p>
duke@1 2368 * If this link appeared in the index, we would redirect
duke@1 2369 * the link like this:
duke@1 2370 *
jjg@1326 2371 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
duke@1 2372 *
duke@1 2373 * @param doc the Doc object whose documentation is being written.
duke@1 2374 * @param text the text being written.
duke@1 2375 *
duke@1 2376 * @return the text, with all the relative links redirected to work.
duke@1 2377 */
duke@1 2378 private String redirectRelativeLinks(Doc doc, String text) {
duke@1 2379 if (doc == null || shouldNotRedirectRelativeLinks()) {
duke@1 2380 return text;
duke@1 2381 }
duke@1 2382
duke@1 2383 String redirectPathFromRoot;
duke@1 2384 if (doc instanceof ClassDoc) {
duke@1 2385 redirectPathFromRoot = DirectoryManager.getDirectoryPath(((ClassDoc) doc).containingPackage());
duke@1 2386 } else if (doc instanceof MemberDoc) {
duke@1 2387 redirectPathFromRoot = DirectoryManager.getDirectoryPath(((MemberDoc) doc).containingPackage());
duke@1 2388 } else if (doc instanceof PackageDoc) {
duke@1 2389 redirectPathFromRoot = DirectoryManager.getDirectoryPath((PackageDoc) doc);
duke@1 2390 } else {
duke@1 2391 return text;
duke@1 2392 }
duke@1 2393
bpatel@766 2394 if (! redirectPathFromRoot.endsWith(DirectoryManager.URL_FILE_SEPARATOR)) {
bpatel@766 2395 redirectPathFromRoot += DirectoryManager.URL_FILE_SEPARATOR;
duke@1 2396 }
duke@1 2397
duke@1 2398 //Redirect all relative links.
duke@1 2399 int end, begin = text.toLowerCase().indexOf("<a");
duke@1 2400 if(begin >= 0){
duke@1 2401 StringBuffer textBuff = new StringBuffer(text);
duke@1 2402
duke@1 2403 while(begin >=0){
duke@1 2404 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
duke@1 2405 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 2406 continue;
duke@1 2407 }
duke@1 2408
duke@1 2409 begin = textBuff.indexOf("=", begin) + 1;
duke@1 2410 end = textBuff.indexOf(">", begin +1);
duke@1 2411 if(begin == 0){
duke@1 2412 //Link has no equal symbol.
duke@1 2413 configuration.root.printWarning(
duke@1 2414 doc.position(),
duke@1 2415 configuration.getText("doclet.malformed_html_link_tag", text));
duke@1 2416 break;
duke@1 2417 }
duke@1 2418 if (end == -1) {
duke@1 2419 //Break without warning. This <a> tag is not necessarily malformed. The text
duke@1 2420 //might be missing '>' character because the href has an inline tag.
duke@1 2421 break;
duke@1 2422 }
duke@1 2423 if(textBuff.substring(begin, end).indexOf("\"") != -1){
duke@1 2424 begin = textBuff.indexOf("\"", begin) + 1;
duke@1 2425 end = textBuff.indexOf("\"", begin +1);
duke@1 2426 if(begin == 0 || end == -1){
duke@1 2427 //Link is missing a quote.
duke@1 2428 break;
duke@1 2429 }
duke@1 2430 }
duke@1 2431 String relativeLink = textBuff.substring(begin, end);
duke@1 2432 if(!(relativeLink.toLowerCase().startsWith("mailto:") ||
duke@1 2433 relativeLink.toLowerCase().startsWith("http:") ||
duke@1 2434 relativeLink.toLowerCase().startsWith("https:") ||
duke@1 2435 relativeLink.toLowerCase().startsWith("file:"))){
duke@1 2436 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}"
duke@1 2437 + redirectPathFromRoot
duke@1 2438 + relativeLink;
duke@1 2439 textBuff.replace(begin, end, relativeLink);
duke@1 2440 }
duke@1 2441 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 2442 }
duke@1 2443 return textBuff.toString();
duke@1 2444 }
duke@1 2445 return text;
duke@1 2446 }
duke@1 2447
duke@1 2448 public String removeNonInlineHtmlTags(String text) {
duke@1 2449 if (text.indexOf('<') < 0) {
duke@1 2450 return text;
duke@1 2451 }
duke@1 2452 String noninlinetags[] = { "<ul>", "</ul>", "<ol>", "</ol>",
duke@1 2453 "<dl>", "</dl>", "<table>", "</table>",
duke@1 2454 "<tr>", "</tr>", "<td>", "</td>",
duke@1 2455 "<th>", "</th>", "<p>", "</p>",
duke@1 2456 "<li>", "</li>", "<dd>", "</dd>",
duke@1 2457 "<dir>", "</dir>", "<dt>", "</dt>",
duke@1 2458 "<h1>", "</h1>", "<h2>", "</h2>",
duke@1 2459 "<h3>", "</h3>", "<h4>", "</h4>",
duke@1 2460 "<h5>", "</h5>", "<h6>", "</h6>",
duke@1 2461 "<pre>", "</pre>", "<menu>", "</menu>",
duke@1 2462 "<listing>", "</listing>", "<hr>",
duke@1 2463 "<blockquote>", "</blockquote>",
duke@1 2464 "<center>", "</center>",
duke@1 2465 "<UL>", "</UL>", "<OL>", "</OL>",
duke@1 2466 "<DL>", "</DL>", "<TABLE>", "</TABLE>",
duke@1 2467 "<TR>", "</TR>", "<TD>", "</TD>",
duke@1 2468 "<TH>", "</TH>", "<P>", "</P>",
duke@1 2469 "<LI>", "</LI>", "<DD>", "</DD>",
duke@1 2470 "<DIR>", "</DIR>", "<DT>", "</DT>",
duke@1 2471 "<H1>", "</H1>", "<H2>", "</H2>",
duke@1 2472 "<H3>", "</H3>", "<H4>", "</H4>",
duke@1 2473 "<H5>", "</H5>", "<H6>", "</H6>",
duke@1 2474 "<PRE>", "</PRE>", "<MENU>", "</MENU>",
duke@1 2475 "<LISTING>", "</LISTING>", "<HR>",
duke@1 2476 "<BLOCKQUOTE>", "</BLOCKQUOTE>",
duke@1 2477 "<CENTER>", "</CENTER>"
duke@1 2478 };
duke@1 2479 for (int i = 0; i < noninlinetags.length; i++) {
duke@1 2480 text = replace(text, noninlinetags[i], "");
duke@1 2481 }
duke@1 2482 return text;
duke@1 2483 }
duke@1 2484
duke@1 2485 public String replace(String text, String tobe, String by) {
duke@1 2486 while (true) {
duke@1 2487 int startindex = text.indexOf(tobe);
duke@1 2488 if (startindex < 0) {
duke@1 2489 return text;
duke@1 2490 }
duke@1 2491 int endindex = startindex + tobe.length();
jjg@910 2492 StringBuilder replaced = new StringBuilder();
duke@1 2493 if (startindex > 0) {
duke@1 2494 replaced.append(text.substring(0, startindex));
duke@1 2495 }
duke@1 2496 replaced.append(by);
duke@1 2497 if (text.length() > endindex) {
duke@1 2498 replaced.append(text.substring(endindex));
duke@1 2499 }
duke@1 2500 text = replaced.toString();
duke@1 2501 }
duke@1 2502 }
duke@1 2503
duke@1 2504 public void printStyleSheetProperties() {
duke@1 2505 String filename = configuration.stylesheetfile;
duke@1 2506 if (filename.length() > 0) {
duke@1 2507 File stylefile = new File(filename);
duke@1 2508 String parent = stylefile.getParent();
duke@1 2509 filename = (parent == null)?
duke@1 2510 filename:
duke@1 2511 filename.substring(parent.length() + 1);
duke@1 2512 } else {
duke@1 2513 filename = "stylesheet.css";
duke@1 2514 }
duke@1 2515 filename = relativePath + filename;
duke@1 2516 link("REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"" +
duke@1 2517 filename + "\" " + "TITLE=\"Style\"");
duke@1 2518 }
duke@1 2519
duke@1 2520 /**
bpatel@766 2521 * Returns a link to the stylesheet file.
bpatel@766 2522 *
bpatel@766 2523 * @return an HtmlTree for the lINK tag which provides the stylesheet location
bpatel@766 2524 */
bpatel@766 2525 public HtmlTree getStyleSheetProperties() {
bpatel@766 2526 String filename = configuration.stylesheetfile;
bpatel@766 2527 if (filename.length() > 0) {
bpatel@766 2528 File stylefile = new File(filename);
bpatel@766 2529 String parent = stylefile.getParent();
bpatel@766 2530 filename = (parent == null)?
bpatel@766 2531 filename:
bpatel@766 2532 filename.substring(parent.length() + 1);
bpatel@766 2533 } else {
bpatel@766 2534 filename = "stylesheet.css";
bpatel@766 2535 }
bpatel@766 2536 filename = relativePath + filename;
bpatel@766 2537 HtmlTree link = HtmlTree.LINK("stylesheet", "text/css", filename, "Style");
bpatel@766 2538 return link;
bpatel@766 2539 }
bpatel@766 2540
bpatel@766 2541 /**
jjh@972 2542 * According to
jjh@972 2543 * <cite>The Java&trade; Language Specification</cite>,
jjh@972 2544 * all the outer classes and static nested classes are core classes.
duke@1 2545 */
duke@1 2546 public boolean isCoreClass(ClassDoc cd) {
duke@1 2547 return cd.containingClass() == null || cd.isStatic();
duke@1 2548 }
duke@1 2549
duke@1 2550 /**
duke@1 2551 * Write the annotatation types for the given packageDoc.
duke@1 2552 *
duke@1 2553 * @param packageDoc the package to write annotations for.
duke@1 2554 */
duke@1 2555 public void writeAnnotationInfo(PackageDoc packageDoc) {
duke@1 2556 writeAnnotationInfo(packageDoc, packageDoc.annotations());
duke@1 2557 }
duke@1 2558
duke@1 2559 /**
bpatel@766 2560 * Adds the annotatation types for the given packageDoc.
bpatel@766 2561 *
bpatel@766 2562 * @param packageDoc the package to write annotations for.
bpatel@766 2563 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 2564 * added
bpatel@766 2565 */
bpatel@766 2566 public void addAnnotationInfo(PackageDoc packageDoc, Content htmltree) {
bpatel@766 2567 addAnnotationInfo(packageDoc, packageDoc.annotations(), htmltree);
bpatel@766 2568 }
bpatel@766 2569
bpatel@766 2570 /**
duke@1 2571 * Write the annotatation types for the given doc.
duke@1 2572 *
duke@1 2573 * @param doc the doc to write annotations for.
duke@1 2574 */
duke@1 2575 public void writeAnnotationInfo(ProgramElementDoc doc) {
duke@1 2576 writeAnnotationInfo(doc, doc.annotations());
duke@1 2577 }
duke@1 2578
duke@1 2579 /**
bpatel@766 2580 * Adds the annotatation types for the given doc.
bpatel@766 2581 *
jjg@1358 2582 * @param doc the package to write annotations for
bpatel@766 2583 * @param htmltree the content tree to which the annotation types will be added
bpatel@766 2584 */
bpatel@766 2585 public void addAnnotationInfo(ProgramElementDoc doc, Content htmltree) {
bpatel@766 2586 addAnnotationInfo(doc, doc.annotations(), htmltree);
bpatel@766 2587 }
bpatel@766 2588
bpatel@766 2589 /**
duke@1 2590 * Write the annotatation types for the given doc and parameter.
duke@1 2591 *
duke@1 2592 * @param indent the number of spaced to indent the parameters.
duke@1 2593 * @param doc the doc to write annotations for.
duke@1 2594 * @param param the parameter to write annotations for.
duke@1 2595 */
duke@1 2596 public boolean writeAnnotationInfo(int indent, Doc doc, Parameter param) {
duke@1 2597 return writeAnnotationInfo(indent, doc, param.annotations(), false);
duke@1 2598 }
duke@1 2599
duke@1 2600 /**
bpatel@766 2601 * Add the annotatation types for the given doc and parameter.
bpatel@766 2602 *
bpatel@766 2603 * @param indent the number of spaces to indent the parameters.
bpatel@766 2604 * @param doc the doc to write annotations for.
bpatel@766 2605 * @param param the parameter to write annotations for.
bpatel@766 2606 * @param tree the content tree to which the annotation types will be added
bpatel@766 2607 */
bpatel@766 2608 public boolean addAnnotationInfo(int indent, Doc doc, Parameter param,
bpatel@766 2609 Content tree) {
bpatel@766 2610 return addAnnotationInfo(indent, doc, param.annotations(), false, tree);
bpatel@766 2611 }
bpatel@766 2612
bpatel@766 2613 /**
duke@1 2614 * Write the annotatation types for the given doc.
duke@1 2615 *
duke@1 2616 * @param doc the doc to write annotations for.
duke@1 2617 * @param descList the array of {@link AnnotationDesc}.
duke@1 2618 */
duke@1 2619 private void writeAnnotationInfo(Doc doc, AnnotationDesc[] descList) {
duke@1 2620 writeAnnotationInfo(0, doc, descList, true);
duke@1 2621 }
duke@1 2622
duke@1 2623 /**
bpatel@766 2624 * Adds the annotatation types for the given doc.
bpatel@766 2625 *
bpatel@766 2626 * @param doc the doc to write annotations for.
bpatel@766 2627 * @param descList the array of {@link AnnotationDesc}.
bpatel@766 2628 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 2629 * added
bpatel@766 2630 */
bpatel@766 2631 private void addAnnotationInfo(Doc doc, AnnotationDesc[] descList,
bpatel@766 2632 Content htmltree) {
bpatel@766 2633 addAnnotationInfo(0, doc, descList, true, htmltree);
bpatel@766 2634 }
bpatel@766 2635
bpatel@766 2636 /**
duke@1 2637 * Write the annotatation types for the given doc.
duke@1 2638 *
duke@1 2639 * @param indent the number of extra spaces to indent the annotations.
duke@1 2640 * @param doc the doc to write annotations for.
duke@1 2641 * @param descList the array of {@link AnnotationDesc}.
duke@1 2642 */
duke@1 2643 private boolean writeAnnotationInfo(int indent, Doc doc, AnnotationDesc[] descList, boolean lineBreak) {
mcimadamore@184 2644 List<String> annotations = getAnnotations(indent, descList, lineBreak);
duke@1 2645 if (annotations.size() == 0) {
duke@1 2646 return false;
duke@1 2647 }
duke@1 2648 fontNoNewLine("-1");
mcimadamore@184 2649 for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
mcimadamore@184 2650 print(iter.next());
duke@1 2651 }
duke@1 2652 fontEnd();
duke@1 2653 return true;
duke@1 2654 }
duke@1 2655
duke@1 2656 /**
bpatel@766 2657 * Adds the annotatation types for the given doc.
bpatel@766 2658 *
bpatel@766 2659 * @param indent the number of extra spaces to indent the annotations.
bpatel@766 2660 * @param doc the doc to write annotations for.
bpatel@766 2661 * @param descList the array of {@link AnnotationDesc}.
bpatel@766 2662 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 2663 * added
bpatel@766 2664 */
bpatel@766 2665 private boolean addAnnotationInfo(int indent, Doc doc,
bpatel@766 2666 AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
bpatel@766 2667 List<String> annotations = getAnnotations(indent, descList, lineBreak);
bpatel@766 2668 if (annotations.size() == 0) {
bpatel@766 2669 return false;
bpatel@766 2670 }
bpatel@766 2671 Content annotationContent;
bpatel@766 2672 for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
bpatel@766 2673 annotationContent = new RawHtml(iter.next());
bpatel@766 2674 htmltree.addContent(annotationContent);
bpatel@766 2675 }
bpatel@766 2676 return true;
bpatel@766 2677 }
bpatel@766 2678
bpatel@766 2679 /**
duke@1 2680 * Return the string representations of the annotation types for
duke@1 2681 * the given doc.
duke@1 2682 *
duke@1 2683 * @param indent the number of extra spaces to indent the annotations.
duke@1 2684 * @param descList the array of {@link AnnotationDesc}.
duke@1 2685 * @param linkBreak if true, add new line between each member value.
duke@1 2686 * @return an array of strings representing the annotations being
duke@1 2687 * documented.
duke@1 2688 */
jjg@74 2689 private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
jjg@74 2690 List<String> results = new ArrayList<String>();
duke@1 2691 StringBuffer annotation;
duke@1 2692 for (int i = 0; i < descList.length; i++) {
duke@1 2693 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
duke@1 2694 if (! Util.isDocumentedAnnotation(annotationDoc)){
duke@1 2695 continue;
duke@1 2696 }
duke@1 2697 annotation = new StringBuffer();
duke@1 2698 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 2699 LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc);
duke@1 2700 linkInfo.label = "@" + annotationDoc.name();
duke@1 2701 annotation.append(getLink(linkInfo));
duke@1 2702 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
duke@1 2703 if (pairs.length > 0) {
duke@1 2704 annotation.append('(');
duke@1 2705 for (int j = 0; j < pairs.length; j++) {
duke@1 2706 if (j > 0) {
duke@1 2707 annotation.append(",");
duke@1 2708 if (linkBreak) {
duke@1 2709 annotation.append(DocletConstants.NL);
duke@1 2710 int spaces = annotationDoc.name().length() + 2;
duke@1 2711 for (int k = 0; k < (spaces + indent); k++) {
duke@1 2712 annotation.append(' ');
duke@1 2713 }
duke@1 2714 }
duke@1 2715 }
duke@1 2716 annotation.append(getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
duke@1 2717 pairs[j].element(), pairs[j].element().name(), false));
duke@1 2718 annotation.append('=');
duke@1 2719 AnnotationValue annotationValue = pairs[j].value();
jjg@74 2720 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
duke@1 2721 if (annotationValue.value() instanceof AnnotationValue[]) {
duke@1 2722 AnnotationValue[] annotationArray =
duke@1 2723 (AnnotationValue[]) annotationValue.value();
duke@1 2724 for (int k = 0; k < annotationArray.length; k++) {
duke@1 2725 annotationTypeValues.add(annotationArray[k]);
duke@1 2726 }
duke@1 2727 } else {
duke@1 2728 annotationTypeValues.add(annotationValue);
duke@1 2729 }
duke@1 2730 annotation.append(annotationTypeValues.size() == 1 ? "" : "{");
mcimadamore@184 2731 for (Iterator<AnnotationValue> iter = annotationTypeValues.iterator(); iter.hasNext(); ) {
mcimadamore@184 2732 annotation.append(annotationValueToString(iter.next()));
duke@1 2733 annotation.append(iter.hasNext() ? "," : "");
duke@1 2734 }
duke@1 2735 annotation.append(annotationTypeValues.size() == 1 ? "" : "}");
duke@1 2736 }
duke@1 2737 annotation.append(")");
duke@1 2738 }
duke@1 2739 annotation.append(linkBreak ? DocletConstants.NL : "");
duke@1 2740 results.add(annotation.toString());
duke@1 2741 }
duke@1 2742 return results;
duke@1 2743 }
duke@1 2744
duke@1 2745 private String annotationValueToString(AnnotationValue annotationValue) {
duke@1 2746 if (annotationValue.value() instanceof Type) {
duke@1 2747 Type type = (Type) annotationValue.value();
duke@1 2748 if (type.asClassDoc() != null) {
duke@1 2749 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 2750 LinkInfoImpl.CONTEXT_ANNOTATION, type);
duke@1 2751 linkInfo.label = (type.asClassDoc().isIncluded() ?
duke@1 2752 type.typeName() :
duke@1 2753 type.qualifiedTypeName()) + type.dimension() + ".class";
duke@1 2754 return getLink(linkInfo);
duke@1 2755 } else {
duke@1 2756 return type.typeName() + type.dimension() + ".class";
duke@1 2757 }
duke@1 2758 } else if (annotationValue.value() instanceof AnnotationDesc) {
mcimadamore@184 2759 List<String> list = getAnnotations(0,
duke@1 2760 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
duke@1 2761 false);
duke@1 2762 StringBuffer buf = new StringBuffer();
mcimadamore@184 2763 for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
duke@1 2764 buf.append(iter.next());
duke@1 2765 }
duke@1 2766 return buf.toString();
duke@1 2767 } else if (annotationValue.value() instanceof MemberDoc) {
duke@1 2768 return getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
duke@1 2769 (MemberDoc) annotationValue.value(),
duke@1 2770 ((MemberDoc) annotationValue.value()).name(), false);
duke@1 2771 } else {
duke@1 2772 return annotationValue.toString();
duke@1 2773 }
duke@1 2774 }
duke@1 2775
duke@1 2776 /**
duke@1 2777 * Return the configuation for this doclet.
duke@1 2778 *
duke@1 2779 * @return the configuration for this doclet.
duke@1 2780 */
duke@1 2781 public Configuration configuration() {
duke@1 2782 return configuration;
duke@1 2783 }
duke@1 2784 }

mercurial