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

Tue, 14 May 2013 10:14:53 -0700

author
jjg
date
Tue, 14 May 2013 10:14:53 -0700
changeset 1740
ce4f0769b4b2
parent 1738
6ea964c78845
child 1741
4c43e51433ba
permissions
-rw-r--r--

8011668: Allow HTMLWriter.getResource to take Content args
Reviewed-by: darcy

duke@1 1 /*
jjg@1521 2 * Copyright (c) 1998, 2013, 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
jjg@1372 58 * "java/lang/Object.html", then the path to the root 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 */
jjg@1372 62 public final DocPath pathToRoot;
duke@1 63
duke@1 64 /**
jjg@1372 65 * Platform-independent path from the current or the
duke@1 66 * destination directory to the file getting generated.
duke@1 67 * Used when creating the file.
duke@1 68 */
jjg@1372 69 public final DocPath path;
duke@1 70
duke@1 71 /**
duke@1 72 * Name of the file getting generated. If the file getting generated is
duke@1 73 * "java/lang/Object.html", then the filename is "Object.html".
duke@1 74 */
jjg@1372 75 public final DocPath filename;
duke@1 76
duke@1 77 /**
duke@1 78 * The display length used for indentation while generating the class page.
duke@1 79 */
duke@1 80 public int displayLength = 0;
duke@1 81
duke@1 82 /**
duke@1 83 * The global configuration information for this run.
duke@1 84 */
jjg@1410 85 public final ConfigurationImpl configuration;
duke@1 86
duke@1 87 /**
bpatel@766 88 * To check whether annotation heading is printed or not.
bpatel@766 89 */
bpatel@766 90 protected boolean printedAnnotationHeading = false;
bpatel@766 91
bpatel@766 92 /**
bpatel@1477 93 * To check whether the repeated annotations is documented or not.
bpatel@1477 94 */
bpatel@1477 95 private boolean isAnnotationDocumented = false;
bpatel@1477 96
bpatel@1477 97 /**
bpatel@1477 98 * To check whether the container annotations is documented or not.
bpatel@1477 99 */
bpatel@1477 100 private boolean isContainerDocumented = false;
bpatel@1477 101
bpatel@1477 102 /**
duke@1 103 * Constructor to construct the HtmlStandardWriter object.
duke@1 104 *
jjg@1372 105 * @param path File to be generated.
duke@1 106 */
jjg@1372 107 public HtmlDocletWriter(ConfigurationImpl configuration, DocPath path)
jjg@1372 108 throws IOException {
jjg@1372 109 super(configuration, path);
duke@1 110 this.configuration = configuration;
duke@1 111 this.path = path;
jjg@1372 112 this.pathToRoot = path.parent().invert();
jjg@1372 113 this.filename = path.basename();
duke@1 114 }
duke@1 115
duke@1 116 /**
duke@1 117 * Replace {&#064;docRoot} tag used in options that accept HTML text, such
duke@1 118 * as -header, -footer, -top and -bottom, and when converting a relative
duke@1 119 * HREF where commentTagsToString inserts a {&#064;docRoot} where one was
duke@1 120 * missing. (Also see DocRootTaglet for {&#064;docRoot} tags in doc
duke@1 121 * comments.)
duke@1 122 * <p>
duke@1 123 * Replace {&#064;docRoot} tag in htmlstr with the relative path to the
duke@1 124 * destination directory from the directory where the file is being
duke@1 125 * written, looping to handle all such tags in htmlstr.
duke@1 126 * <p>
duke@1 127 * For example, for "-d docs" and -header containing {&#064;docRoot}, when
duke@1 128 * the HTML page for source file p/C1.java is being generated, the
duke@1 129 * {&#064;docRoot} tag would be inserted into the header as "../",
duke@1 130 * the relative path from docs/p/ to docs/ (the document root).
duke@1 131 * <p>
duke@1 132 * Note: This doc comment was written with '&amp;#064;' representing '@'
duke@1 133 * to prevent the inline tag from being interpreted.
duke@1 134 */
duke@1 135 public String replaceDocRootDir(String htmlstr) {
duke@1 136 // Return if no inline tags exist
duke@1 137 int index = htmlstr.indexOf("{@");
duke@1 138 if (index < 0) {
duke@1 139 return htmlstr;
duke@1 140 }
duke@1 141 String lowerHtml = htmlstr.toLowerCase();
duke@1 142 // Return index of first occurrence of {@docroot}
duke@1 143 // Note: {@docRoot} is not case sensitive when passed in w/command line option
duke@1 144 index = lowerHtml.indexOf("{@docroot}", index);
duke@1 145 if (index < 0) {
duke@1 146 return htmlstr;
duke@1 147 }
jjg@910 148 StringBuilder buf = new StringBuilder();
duke@1 149 int previndex = 0;
duke@1 150 while (true) {
bpatel@997 151 if (configuration.docrootparent.length() > 0) {
jjg@1372 152 final String docroot_parent = "{@docroot}/..";
bpatel@997 153 // Search for lowercase version of {@docRoot}/..
jjg@1372 154 index = lowerHtml.indexOf(docroot_parent, previndex);
bpatel@997 155 // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
bpatel@997 156 if (index < 0) {
bpatel@997 157 buf.append(htmlstr.substring(previndex));
bpatel@997 158 break;
bpatel@997 159 }
bpatel@997 160 // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
bpatel@997 161 buf.append(htmlstr.substring(previndex, index));
jjg@1372 162 previndex = index + docroot_parent.length();
bpatel@997 163 // Insert docrootparent absolute path where {@docRoot}/.. was located
bpatel@997 164
bpatel@997 165 buf.append(configuration.docrootparent);
bpatel@997 166 // Append slash if next character is not a slash
bpatel@997 167 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
jjg@1372 168 buf.append('/');
bpatel@997 169 }
bpatel@997 170 } else {
jjg@1372 171 final String docroot = "{@docroot}";
bpatel@997 172 // Search for lowercase version of {@docRoot}
jjg@1372 173 index = lowerHtml.indexOf(docroot, previndex);
bpatel@997 174 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
bpatel@997 175 if (index < 0) {
bpatel@997 176 buf.append(htmlstr.substring(previndex));
bpatel@997 177 break;
bpatel@997 178 }
bpatel@997 179 // If next {@docroot} tag found, append htmlstr up to start of tag
bpatel@997 180 buf.append(htmlstr.substring(previndex, index));
jjg@1372 181 previndex = index + docroot.length();
bpatel@997 182 // Insert relative path where {@docRoot} was located
jjg@1372 183 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
bpatel@997 184 // Append slash if next character is not a slash
jjg@1372 185 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
jjg@1372 186 buf.append('/');
bpatel@997 187 }
duke@1 188 }
duke@1 189 }
duke@1 190 return buf.toString();
duke@1 191 }
duke@1 192
duke@1 193 /**
bpatel@766 194 * Get the script to show or hide the All classes link.
bpatel@766 195 *
bpatel@766 196 * @param id id of the element to show or hide
bpatel@766 197 * @return a content tree for the script
bpatel@766 198 */
bpatel@766 199 public Content getAllClassesLinkScript(String id) {
bpatel@766 200 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
bpatel@766 201 script.addAttr(HtmlAttr.TYPE, "text/javascript");
bpatel@793 202 String scriptCode = "<!--" + DocletConstants.NL +
bpatel@793 203 " allClassesLink = document.getElementById(\"" + id + "\");" + DocletConstants.NL +
bpatel@793 204 " if(window==top) {" + DocletConstants.NL +
bpatel@793 205 " allClassesLink.style.display = \"block\";" + DocletConstants.NL +
bpatel@793 206 " }" + DocletConstants.NL +
bpatel@793 207 " else {" + DocletConstants.NL +
bpatel@793 208 " allClassesLink.style.display = \"none\";" + DocletConstants.NL +
bpatel@793 209 " }" + DocletConstants.NL +
bpatel@793 210 " //-->" + DocletConstants.NL;
bpatel@766 211 Content scriptContent = new RawHtml(scriptCode);
bpatel@766 212 script.addContent(scriptContent);
bpatel@766 213 Content div = HtmlTree.DIV(script);
bpatel@766 214 return div;
bpatel@766 215 }
bpatel@766 216
bpatel@766 217 /**
bpatel@766 218 * Add method information.
bpatel@766 219 *
bpatel@766 220 * @param method the method to be documented
bpatel@766 221 * @param dl the content tree to which the method information will be added
bpatel@766 222 */
bpatel@766 223 private void addMethodInfo(MethodDoc method, Content dl) {
duke@1 224 ClassDoc[] intfacs = method.containingClass().interfaces();
duke@1 225 MethodDoc overriddenMethod = method.overriddenMethod();
bpatel@233 226 // Check whether there is any implementation or overridden info to be
bpatel@233 227 // printed. If no overridden or implementation info needs to be
bpatel@233 228 // printed, do not print this section.
bpatel@233 229 if ((intfacs.length > 0 &&
bpatel@233 230 new ImplementedMethods(method, this.configuration).build().length > 0) ||
bpatel@233 231 overriddenMethod != null) {
bpatel@766 232 MethodWriterImpl.addImplementsInfo(this, method, dl);
duke@1 233 if (overriddenMethod != null) {
bpatel@766 234 MethodWriterImpl.addOverridden(this,
bpatel@766 235 method.overriddenType(), overriddenMethod, dl);
duke@1 236 }
duke@1 237 }
duke@1 238 }
duke@1 239
bpatel@766 240 /**
bpatel@766 241 * Adds the tags information.
bpatel@766 242 *
bpatel@766 243 * @param doc the doc for which the tags will be generated
bpatel@766 244 * @param htmltree the documentation tree to which the tags will be added
bpatel@766 245 */
bpatel@766 246 protected void addTagsInfo(Doc doc, Content htmltree) {
bpatel@766 247 if (configuration.nocomment) {
duke@1 248 return;
duke@1 249 }
bpatel@766 250 Content dl = new HtmlTree(HtmlTag.DL);
duke@1 251 if (doc instanceof MethodDoc) {
bpatel@766 252 addMethodInfo((MethodDoc) doc, dl);
duke@1 253 }
duke@1 254 TagletOutputImpl output = new TagletOutputImpl("");
duke@1 255 TagletWriter.genTagOuput(configuration.tagletManager, doc,
duke@1 256 configuration.tagletManager.getCustomTags(doc),
duke@1 257 getTagletWriterInstance(false), output);
bpatel@233 258 String outputString = output.toString().trim();
bpatel@233 259 if (!outputString.isEmpty()) {
bpatel@766 260 Content resultString = new RawHtml(outputString);
bpatel@766 261 dl.addContent(resultString);
duke@1 262 }
bpatel@766 263 htmltree.addContent(dl);
duke@1 264 }
duke@1 265
duke@1 266 /**
bpatel@233 267 * Check whether there are any tags for Serialization Overview
bpatel@233 268 * section to be printed.
bpatel@222 269 *
bpatel@233 270 * @param field the FieldDoc object to check for tags.
bpatel@222 271 * @return true if there are tags to be printed else return false.
bpatel@222 272 */
bpatel@233 273 protected boolean hasSerializationOverviewTags(FieldDoc field) {
bpatel@222 274 TagletOutputImpl output = new TagletOutputImpl("");
bpatel@233 275 TagletWriter.genTagOuput(configuration.tagletManager, field,
bpatel@233 276 configuration.tagletManager.getCustomTags(field),
bpatel@222 277 getTagletWriterInstance(false), output);
bpatel@233 278 return (!output.toString().trim().isEmpty());
bpatel@222 279 }
bpatel@222 280
bpatel@222 281 /**
duke@1 282 * Returns a TagletWriter that knows how to write HTML.
duke@1 283 *
duke@1 284 * @return a TagletWriter that knows how to write HTML.
duke@1 285 */
duke@1 286 public TagletWriter getTagletWriterInstance(boolean isFirstSentence) {
duke@1 287 return new TagletWriterImpl(this, isFirstSentence);
duke@1 288 }
duke@1 289
duke@1 290 /**
bpatel@766 291 * Get Package link, with target frame.
duke@1 292 *
bpatel@766 293 * @param pd The link will be to the "package-summary.html" page for this package
bpatel@766 294 * @param target name of the target frame
bpatel@766 295 * @param label tag for the link
bpatel@766 296 * @return a content for the target package link
duke@1 297 */
bpatel@766 298 public Content getTargetPackageLink(PackageDoc pd, String target,
bpatel@766 299 Content label) {
jjg@1373 300 return getHyperLink(pathString(pd, DocPaths.PACKAGE_SUMMARY), label, "", target);
duke@1 301 }
duke@1 302
duke@1 303 /**
bpatel@1568 304 * Get Profile Package link, with target frame.
bpatel@1568 305 *
bpatel@1568 306 * @param pd the packageDoc object
bpatel@1568 307 * @param target name of the target frame
bpatel@1568 308 * @param label tag for the link
bpatel@1568 309 * @param profileName the name of the profile being documented
bpatel@1568 310 * @return a content for the target profile packages link
bpatel@1568 311 */
bpatel@1568 312 public Content getTargetProfilePackageLink(PackageDoc pd, String target,
bpatel@1568 313 Content label, String profileName) {
bpatel@1568 314 return getHyperLink(pathString(pd, DocPaths.profilePackageSummary(profileName)),
bpatel@1568 315 label, "", target);
bpatel@1568 316 }
bpatel@1568 317
bpatel@1568 318 /**
bpatel@1568 319 * Get Profile link, with target frame.
bpatel@1568 320 *
bpatel@1568 321 * @param target name of the target frame
bpatel@1568 322 * @param label tag for the link
bpatel@1568 323 * @param profileName the name of the profile being documented
bpatel@1568 324 * @return a content for the target profile link
bpatel@1568 325 */
bpatel@1568 326 public Content getTargetProfileLink(String target, Content label,
bpatel@1568 327 String profileName) {
bpatel@1568 328 return getHyperLink(pathToRoot.resolve(
bpatel@1568 329 DocPaths.profileSummary(profileName)), label, "", target);
bpatel@1568 330 }
bpatel@1568 331
bpatel@1568 332 /**
bpatel@1568 333 * Get the type name for profile search.
bpatel@1568 334 *
bpatel@1568 335 * @param cd the classDoc object for which the type name conversion is needed
bpatel@1568 336 * @return a type name string for the type
bpatel@1568 337 */
bpatel@1568 338 public String getTypeNameForProfile(ClassDoc cd) {
bpatel@1568 339 StringBuilder typeName =
bpatel@1568 340 new StringBuilder((cd.containingPackage()).name().replace(".", "/"));
bpatel@1568 341 typeName.append("/")
bpatel@1568 342 .append(cd.name().replace(".", "$"));
bpatel@1568 343 return typeName.toString();
bpatel@1568 344 }
bpatel@1568 345
bpatel@1568 346 /**
bpatel@1568 347 * Check if a type belongs to a profile.
bpatel@1568 348 *
bpatel@1568 349 * @param cd the classDoc object that needs to be checked
bpatel@1568 350 * @param profileValue the profile in which the type needs to be checked
bpatel@1568 351 * @return true if the type is in the profile
bpatel@1568 352 */
bpatel@1568 353 public boolean isTypeInProfile(ClassDoc cd, int profileValue) {
bpatel@1568 354 return (configuration.profiles.getProfile(getTypeNameForProfile(cd)) <= profileValue);
bpatel@1568 355 }
bpatel@1568 356
bpatel@1568 357 public void addClassesSummary(ClassDoc[] classes, String label,
bpatel@1568 358 String tableSummary, String[] tableHeader, Content summaryContentTree,
bpatel@1568 359 int profileValue) {
bpatel@1568 360 if(classes.length > 0) {
bpatel@1568 361 Arrays.sort(classes);
bpatel@1568 362 Content caption = getTableCaption(label);
bpatel@1568 363 Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
bpatel@1568 364 tableSummary, caption);
bpatel@1568 365 table.addContent(getSummaryTableHeader(tableHeader, "col"));
bpatel@1568 366 Content tbody = new HtmlTree(HtmlTag.TBODY);
bpatel@1568 367 for (int i = 0; i < classes.length; i++) {
bpatel@1568 368 if (!isTypeInProfile(classes[i], profileValue)) {
bpatel@1568 369 continue;
bpatel@1568 370 }
bpatel@1568 371 if (!Util.isCoreClass(classes[i]) ||
bpatel@1568 372 !configuration.isGeneratedDoc(classes[i])) {
bpatel@1568 373 continue;
bpatel@1568 374 }
jjg@1736 375 Content classContent = getLink(new LinkInfoImpl(
jjg@1738 376 configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
bpatel@1568 377 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
bpatel@1568 378 HtmlTree tr = HtmlTree.TR(tdClass);
bpatel@1568 379 if (i%2 == 0)
bpatel@1568 380 tr.addStyle(HtmlStyle.altColor);
bpatel@1568 381 else
bpatel@1568 382 tr.addStyle(HtmlStyle.rowColor);
bpatel@1568 383 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
bpatel@1568 384 tdClassDescription.addStyle(HtmlStyle.colLast);
bpatel@1568 385 if (Util.isDeprecated(classes[i])) {
bpatel@1568 386 tdClassDescription.addContent(deprecatedLabel);
bpatel@1568 387 if (classes[i].tags("deprecated").length > 0) {
bpatel@1568 388 addSummaryDeprecatedComment(classes[i],
bpatel@1568 389 classes[i].tags("deprecated")[0], tdClassDescription);
bpatel@1568 390 }
bpatel@1568 391 }
bpatel@1568 392 else
bpatel@1568 393 addSummaryComment(classes[i], tdClassDescription);
bpatel@1568 394 tr.addContent(tdClassDescription);
bpatel@1568 395 tbody.addContent(tr);
bpatel@1568 396 }
bpatel@1568 397 table.addContent(tbody);
bpatel@1568 398 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@1568 399 summaryContentTree.addContent(li);
bpatel@1568 400 }
bpatel@1568 401 }
bpatel@1568 402
bpatel@1568 403 /**
bpatel@766 404 * Generates the HTML document tree and prints it out.
bpatel@766 405 *
bpatel@766 406 * @param metakeywords Array of String keywords for META tag. Each element
bpatel@766 407 * of the array is assigned to a separate META tag.
bpatel@766 408 * Pass in null for no array
bpatel@766 409 * @param includeScript true if printing windowtitle script
bpatel@766 410 * false for files that appear in the left-hand frames
bpatel@766 411 * @param body the body htmltree to be included in the document
bpatel@766 412 */
bpatel@766 413 public void printHtmlDocument(String[] metakeywords, boolean includeScript,
jjg@1364 414 Content body) throws IOException {
jjg@1410 415 Content htmlDocType = DocType.TRANSITIONAL;
bpatel@766 416 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 417 Content head = new HtmlTree(HtmlTag.HEAD);
bpatel@766 418 if (!configuration.notimestamp) {
jjg@1361 419 Content headComment = new Comment(getGeneratedByString());
bpatel@766 420 head.addContent(headComment);
bpatel@766 421 }
bpatel@766 422 if (configuration.charset.length() > 0) {
bpatel@766 423 Content meta = HtmlTree.META("Content-Type", "text/html",
bpatel@766 424 configuration.charset);
bpatel@766 425 head.addContent(meta);
bpatel@766 426 }
bpatel@766 427 head.addContent(getTitle());
bpatel@766 428 if (!configuration.notimestamp) {
bpatel@766 429 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
bpatel@766 430 Content meta = HtmlTree.META("date", dateFormat.format(new Date()));
bpatel@766 431 head.addContent(meta);
bpatel@766 432 }
bpatel@766 433 if (metakeywords != null) {
bpatel@766 434 for (int i=0; i < metakeywords.length; i++) {
bpatel@766 435 Content meta = HtmlTree.META("keywords", metakeywords[i]);
bpatel@766 436 head.addContent(meta);
bpatel@766 437 }
bpatel@766 438 }
bpatel@766 439 head.addContent(getStyleSheetProperties());
bpatel@1417 440 head.addContent(getScriptProperties());
bpatel@766 441 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 442 head, body);
bpatel@766 443 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 444 htmlComment, htmlTree);
jjg@1365 445 write(htmlDocument);
bpatel@766 446 }
bpatel@766 447
bpatel@766 448 /**
bpatel@766 449 * Get the window title.
bpatel@766 450 *
bpatel@766 451 * @param title the title string to construct the complete window title
bpatel@766 452 * @return the window title string
bpatel@766 453 */
bpatel@766 454 public String getWindowTitle(String title) {
bpatel@766 455 if (configuration.windowtitle.length() > 0) {
bpatel@766 456 title += " (" + configuration.windowtitle + ")";
bpatel@766 457 }
bpatel@766 458 return title;
bpatel@766 459 }
bpatel@766 460
bpatel@766 461 /**
bpatel@766 462 * Get user specified header and the footer.
bpatel@766 463 *
bpatel@766 464 * @param header if true print the user provided header else print the
bpatel@766 465 * user provided footer.
bpatel@766 466 */
bpatel@766 467 public Content getUserHeaderFooter(boolean header) {
bpatel@766 468 String content;
bpatel@766 469 if (header) {
bpatel@766 470 content = replaceDocRootDir(configuration.header);
bpatel@766 471 } else {
bpatel@766 472 if (configuration.footer.length() != 0) {
bpatel@766 473 content = replaceDocRootDir(configuration.footer);
bpatel@766 474 } else {
bpatel@766 475 content = replaceDocRootDir(configuration.header);
bpatel@766 476 }
bpatel@766 477 }
bpatel@766 478 Content rawContent = new RawHtml(content);
bpatel@766 479 Content em = HtmlTree.EM(rawContent);
bpatel@766 480 return em;
bpatel@766 481 }
bpatel@766 482
bpatel@766 483 /**
bpatel@766 484 * Adds the user specified top.
bpatel@766 485 *
bpatel@766 486 * @param body the content tree to which user specified top will be added
bpatel@766 487 */
bpatel@766 488 public void addTop(Content body) {
bpatel@766 489 Content top = new RawHtml(replaceDocRootDir(configuration.top));
bpatel@766 490 body.addContent(top);
bpatel@766 491 }
bpatel@766 492
bpatel@766 493 /**
bpatel@766 494 * Adds the user specified bottom.
bpatel@766 495 *
bpatel@766 496 * @param body the content tree to which user specified bottom will be added
bpatel@766 497 */
bpatel@766 498 public void addBottom(Content body) {
bpatel@766 499 Content bottom = new RawHtml(replaceDocRootDir(configuration.bottom));
bpatel@766 500 Content small = HtmlTree.SMALL(bottom);
bpatel@766 501 Content p = HtmlTree.P(HtmlStyle.legalCopy, small);
bpatel@766 502 body.addContent(p);
bpatel@766 503 }
bpatel@766 504
bpatel@766 505 /**
bpatel@766 506 * Adds the navigation bar for the Html page at the top and and the bottom.
bpatel@766 507 *
bpatel@766 508 * @param header If true print navigation bar at the top of the page else
bpatel@766 509 * @param body the HtmlTree to which the nav links will be added
bpatel@766 510 */
bpatel@766 511 protected void addNavLinks(boolean header, Content body) {
bpatel@766 512 if (!configuration.nonavbar) {
bpatel@766 513 String allClassesId = "allclasses_";
bpatel@766 514 HtmlTree navDiv = new HtmlTree(HtmlTag.DIV);
bpatel@766 515 if (header) {
bpatel@766 516 body.addContent(HtmlConstants.START_OF_TOP_NAVBAR);
bpatel@766 517 navDiv.addStyle(HtmlStyle.topNav);
bpatel@766 518 allClassesId += "navbar_top";
bpatel@766 519 Content a = getMarkerAnchor("navbar_top");
bpatel@766 520 navDiv.addContent(a);
jjg@1373 521 Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_top"),
jjg@1373 522 HtmlTree.EMPTY,
jjg@1373 523 configuration.getText("doclet.Skip_navigation_links"),
jjg@1373 524 "");
bpatel@766 525 navDiv.addContent(skipLinkContent);
bpatel@766 526 } else {
bpatel@766 527 body.addContent(HtmlConstants.START_OF_BOTTOM_NAVBAR);
bpatel@766 528 navDiv.addStyle(HtmlStyle.bottomNav);
bpatel@766 529 allClassesId += "navbar_bottom";
bpatel@766 530 Content a = getMarkerAnchor("navbar_bottom");
bpatel@766 531 navDiv.addContent(a);
jjg@1373 532 Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_bottom"),
jjg@1373 533 HtmlTree.EMPTY,
jjg@1373 534 configuration.getText("doclet.Skip_navigation_links"),
jjg@1373 535 "");
bpatel@766 536 navDiv.addContent(skipLinkContent);
bpatel@766 537 }
bpatel@766 538 if (header) {
bpatel@766 539 navDiv.addContent(getMarkerAnchor("navbar_top_firstrow"));
bpatel@766 540 } else {
bpatel@766 541 navDiv.addContent(getMarkerAnchor("navbar_bottom_firstrow"));
bpatel@766 542 }
bpatel@766 543 HtmlTree navList = new HtmlTree(HtmlTag.UL);
bpatel@766 544 navList.addStyle(HtmlStyle.navList);
jjg@1606 545 navList.addAttr(HtmlAttr.TITLE,
jjg@1606 546 configuration.getText("doclet.Navigation"));
bpatel@766 547 if (configuration.createoverview) {
bpatel@766 548 navList.addContent(getNavLinkContents());
bpatel@766 549 }
bpatel@766 550 if (configuration.packages.length == 1) {
bpatel@766 551 navList.addContent(getNavLinkPackage(configuration.packages[0]));
bpatel@766 552 } else if (configuration.packages.length > 1) {
bpatel@766 553 navList.addContent(getNavLinkPackage());
bpatel@766 554 }
bpatel@766 555 navList.addContent(getNavLinkClass());
bpatel@766 556 if(configuration.classuse) {
bpatel@766 557 navList.addContent(getNavLinkClassUse());
bpatel@766 558 }
bpatel@766 559 if(configuration.createtree) {
bpatel@766 560 navList.addContent(getNavLinkTree());
bpatel@766 561 }
bpatel@766 562 if(!(configuration.nodeprecated ||
bpatel@766 563 configuration.nodeprecatedlist)) {
bpatel@766 564 navList.addContent(getNavLinkDeprecated());
bpatel@766 565 }
bpatel@766 566 if(configuration.createindex) {
bpatel@766 567 navList.addContent(getNavLinkIndex());
bpatel@766 568 }
bpatel@766 569 if (!configuration.nohelp) {
bpatel@766 570 navList.addContent(getNavLinkHelp());
bpatel@766 571 }
bpatel@766 572 navDiv.addContent(navList);
bpatel@766 573 Content aboutDiv = HtmlTree.DIV(HtmlStyle.aboutLanguage, getUserHeaderFooter(header));
bpatel@766 574 navDiv.addContent(aboutDiv);
bpatel@766 575 body.addContent(navDiv);
bpatel@766 576 Content ulNav = HtmlTree.UL(HtmlStyle.navList, getNavLinkPrevious());
bpatel@766 577 ulNav.addContent(getNavLinkNext());
bpatel@766 578 Content subDiv = HtmlTree.DIV(HtmlStyle.subNav, ulNav);
bpatel@766 579 Content ulFrames = HtmlTree.UL(HtmlStyle.navList, getNavShowLists());
bpatel@766 580 ulFrames.addContent(getNavHideLists(filename));
bpatel@766 581 subDiv.addContent(ulFrames);
bpatel@766 582 HtmlTree ulAllClasses = HtmlTree.UL(HtmlStyle.navList, getNavLinkClassIndex());
bpatel@766 583 ulAllClasses.addAttr(HtmlAttr.ID, allClassesId.toString());
bpatel@766 584 subDiv.addContent(ulAllClasses);
bpatel@766 585 subDiv.addContent(getAllClassesLinkScript(allClassesId.toString()));
bpatel@766 586 addSummaryDetailLinks(subDiv);
bpatel@766 587 if (header) {
bpatel@766 588 subDiv.addContent(getMarkerAnchor("skip-navbar_top"));
bpatel@766 589 body.addContent(subDiv);
bpatel@766 590 body.addContent(HtmlConstants.END_OF_TOP_NAVBAR);
bpatel@766 591 } else {
bpatel@766 592 subDiv.addContent(getMarkerAnchor("skip-navbar_bottom"));
bpatel@766 593 body.addContent(subDiv);
bpatel@766 594 body.addContent(HtmlConstants.END_OF_BOTTOM_NAVBAR);
bpatel@766 595 }
bpatel@766 596 }
bpatel@766 597 }
bpatel@766 598
bpatel@766 599 /**
bpatel@766 600 * Get the word "NEXT" to indicate that no link is available. Override
bpatel@766 601 * this method to customize next link.
bpatel@766 602 *
bpatel@766 603 * @return a content tree for the link
bpatel@766 604 */
bpatel@766 605 protected Content getNavLinkNext() {
bpatel@766 606 return getNavLinkNext(null);
bpatel@766 607 }
bpatel@766 608
bpatel@766 609 /**
bpatel@766 610 * Get the word "PREV" to indicate that no link is available. Override
bpatel@766 611 * this method to customize prev link.
bpatel@766 612 *
bpatel@766 613 * @return a content tree for the link
bpatel@766 614 */
bpatel@766 615 protected Content getNavLinkPrevious() {
bpatel@766 616 return getNavLinkPrevious(null);
bpatel@766 617 }
bpatel@766 618
bpatel@766 619 /**
duke@1 620 * Do nothing. This is the default method.
duke@1 621 */
bpatel@766 622 protected void addSummaryDetailLinks(Content navDiv) {
bpatel@766 623 }
bpatel@766 624
bpatel@766 625 /**
bpatel@766 626 * Get link to the "overview-summary.html" page.
bpatel@766 627 *
bpatel@766 628 * @return a content tree for the link
bpatel@766 629 */
bpatel@766 630 protected Content getNavLinkContents() {
jjg@1372 631 Content linkContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_SUMMARY),
jjg@1373 632 overviewLabel, "", "");
bpatel@766 633 Content li = HtmlTree.LI(linkContent);
bpatel@766 634 return li;
bpatel@766 635 }
bpatel@766 636
bpatel@766 637 /**
bpatel@766 638 * Get link to the "package-summary.html" page for the package passed.
bpatel@766 639 *
bpatel@766 640 * @param pkg Package to which link will be generated
bpatel@766 641 * @return a content tree for the link
bpatel@766 642 */
bpatel@766 643 protected Content getNavLinkPackage(PackageDoc pkg) {
bpatel@766 644 Content linkContent = getPackageLink(pkg,
bpatel@766 645 packageLabel);
bpatel@766 646 Content li = HtmlTree.LI(linkContent);
bpatel@766 647 return li;
bpatel@766 648 }
bpatel@766 649
bpatel@766 650 /**
bpatel@766 651 * Get the word "Package" , to indicate that link is not available here.
bpatel@766 652 *
bpatel@766 653 * @return a content tree for the link
bpatel@766 654 */
bpatel@766 655 protected Content getNavLinkPackage() {
bpatel@766 656 Content li = HtmlTree.LI(packageLabel);
bpatel@766 657 return li;
bpatel@766 658 }
bpatel@766 659
bpatel@766 660 /**
bpatel@766 661 * Get the word "Use", to indicate that link is not available.
bpatel@766 662 *
bpatel@766 663 * @return a content tree for the link
bpatel@766 664 */
bpatel@766 665 protected Content getNavLinkClassUse() {
bpatel@766 666 Content li = HtmlTree.LI(useLabel);
bpatel@766 667 return li;
bpatel@766 668 }
bpatel@766 669
bpatel@766 670 /**
bpatel@766 671 * Get link for previous file.
bpatel@766 672 *
bpatel@766 673 * @param prev File name for the prev link
bpatel@766 674 * @return a content tree for the link
bpatel@766 675 */
jjg@1372 676 public Content getNavLinkPrevious(DocPath prev) {
bpatel@766 677 Content li;
bpatel@766 678 if (prev != null) {
jjg@1373 679 li = HtmlTree.LI(getHyperLink(prev, prevLabel, "", ""));
bpatel@766 680 }
bpatel@766 681 else
bpatel@766 682 li = HtmlTree.LI(prevLabel);
bpatel@766 683 return li;
bpatel@766 684 }
bpatel@766 685
bpatel@766 686 /**
bpatel@766 687 * Get link for next file. If next is null, just print the label
bpatel@766 688 * without linking it anywhere.
bpatel@766 689 *
bpatel@766 690 * @param next File name for the next link
bpatel@766 691 * @return a content tree for the link
bpatel@766 692 */
jjg@1372 693 public Content getNavLinkNext(DocPath next) {
bpatel@766 694 Content li;
bpatel@766 695 if (next != null) {
jjg@1373 696 li = HtmlTree.LI(getHyperLink(next, nextLabel, "", ""));
bpatel@766 697 }
bpatel@766 698 else
bpatel@766 699 li = HtmlTree.LI(nextLabel);
bpatel@766 700 return li;
bpatel@766 701 }
bpatel@766 702
bpatel@766 703 /**
bpatel@766 704 * Get "FRAMES" link, to switch to the frame version of the output.
bpatel@766 705 *
bpatel@766 706 * @param link File to be linked, "index.html"
bpatel@766 707 * @return a content tree for the link
bpatel@766 708 */
jjg@1372 709 protected Content getNavShowLists(DocPath link) {
jjg@1373 710 DocLink dl = new DocLink(link, path.getPath(), null);
jjg@1373 711 Content framesContent = getHyperLink(dl, framesLabel, "", "_top");
bpatel@766 712 Content li = HtmlTree.LI(framesContent);
bpatel@766 713 return li;
bpatel@766 714 }
bpatel@766 715
bpatel@766 716 /**
bpatel@766 717 * Get "FRAMES" link, to switch to the frame version of the output.
bpatel@766 718 *
bpatel@766 719 * @return a content tree for the link
bpatel@766 720 */
bpatel@766 721 protected Content getNavShowLists() {
jjg@1372 722 return getNavShowLists(pathToRoot.resolve(DocPaths.INDEX));
bpatel@766 723 }
bpatel@766 724
bpatel@766 725 /**
bpatel@766 726 * Get "NO FRAMES" link, to switch to the non-frame version of the output.
bpatel@766 727 *
bpatel@766 728 * @param link File to be linked
bpatel@766 729 * @return a content tree for the link
bpatel@766 730 */
jjg@1372 731 protected Content getNavHideLists(DocPath link) {
jjg@1373 732 Content noFramesContent = getHyperLink(link, noframesLabel, "", "_top");
bpatel@766 733 Content li = HtmlTree.LI(noFramesContent);
bpatel@766 734 return li;
bpatel@766 735 }
bpatel@766 736
bpatel@766 737 /**
bpatel@766 738 * Get "Tree" link in the navigation bar. If there is only one package
bpatel@766 739 * specified on the command line, then the "Tree" link will be to the
bpatel@766 740 * only "package-tree.html" file otherwise it will be to the
bpatel@766 741 * "overview-tree.html" file.
bpatel@766 742 *
bpatel@766 743 * @return a content tree for the link
duke@1 744 */
bpatel@766 745 protected Content getNavLinkTree() {
bpatel@766 746 Content treeLinkContent;
bpatel@766 747 PackageDoc[] packages = configuration.root.specifiedPackages();
bpatel@766 748 if (packages.length == 1 && configuration.root.specifiedClasses().length == 0) {
bpatel@766 749 treeLinkContent = getHyperLink(pathString(packages[0],
jjg@1373 750 DocPaths.PACKAGE_TREE), treeLabel,
bpatel@766 751 "", "");
bpatel@766 752 } else {
jjg@1372 753 treeLinkContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE),
jjg@1373 754 treeLabel, "", "");
bpatel@766 755 }
bpatel@766 756 Content li = HtmlTree.LI(treeLinkContent);
bpatel@766 757 return li;
bpatel@766 758 }
bpatel@766 759
bpatel@766 760 /**
bpatel@766 761 * Get the overview tree link for the main tree.
bpatel@766 762 *
bpatel@766 763 * @param label the label for the link
bpatel@766 764 * @return a content tree for the link
bpatel@766 765 */
bpatel@766 766 protected Content getNavLinkMainTree(String label) {
jjg@1372 767 Content mainTreeContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE),
bpatel@766 768 new StringContent(label));
bpatel@766 769 Content li = HtmlTree.LI(mainTreeContent);
bpatel@766 770 return li;
duke@1 771 }
duke@1 772
duke@1 773 /**
bpatel@766 774 * Get the word "Class", to indicate that class link is not available.
bpatel@766 775 *
bpatel@766 776 * @return a content tree for the link
bpatel@766 777 */
bpatel@766 778 protected Content getNavLinkClass() {
bpatel@766 779 Content li = HtmlTree.LI(classLabel);
bpatel@766 780 return li;
bpatel@766 781 }
bpatel@766 782
bpatel@766 783 /**
bpatel@766 784 * Get "Deprecated" API link in the navigation bar.
bpatel@766 785 *
bpatel@766 786 * @return a content tree for the link
bpatel@766 787 */
bpatel@766 788 protected Content getNavLinkDeprecated() {
jjg@1372 789 Content linkContent = getHyperLink(pathToRoot.resolve(DocPaths.DEPRECATED_LIST),
jjg@1373 790 deprecatedLabel, "", "");
bpatel@766 791 Content li = HtmlTree.LI(linkContent);
bpatel@766 792 return li;
bpatel@766 793 }
bpatel@766 794
bpatel@766 795 /**
bpatel@766 796 * Get link for generated index. If the user has used "-splitindex"
bpatel@766 797 * command line option, then link to file "index-files/index-1.html" is
bpatel@766 798 * generated otherwise link to file "index-all.html" is generated.
bpatel@766 799 *
bpatel@766 800 * @return a content tree for the link
bpatel@766 801 */
bpatel@766 802 protected Content getNavLinkClassIndex() {
jjg@1372 803 Content allClassesContent = getHyperLink(pathToRoot.resolve(
jjg@1373 804 DocPaths.ALLCLASSES_NOFRAME),
bpatel@766 805 allclassesLabel, "", "");
bpatel@766 806 Content li = HtmlTree.LI(allClassesContent);
bpatel@766 807 return li;
bpatel@766 808 }
duke@1 809
duke@1 810 /**
bpatel@766 811 * Get link for generated class index.
bpatel@766 812 *
bpatel@766 813 * @return a content tree for the link
bpatel@766 814 */
bpatel@766 815 protected Content getNavLinkIndex() {
jjg@1372 816 Content linkContent = getHyperLink(pathToRoot.resolve(
jjg@1372 817 (configuration.splitindex
jjg@1372 818 ? DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1))
jjg@1373 819 : DocPaths.INDEX_ALL)),
bpatel@766 820 indexLabel, "", "");
bpatel@766 821 Content li = HtmlTree.LI(linkContent);
bpatel@766 822 return li;
bpatel@766 823 }
bpatel@766 824
bpatel@766 825 /**
bpatel@766 826 * Get help file link. If user has provided a help file, then generate a
bpatel@766 827 * link to the user given file, which is already copied to current or
bpatel@766 828 * destination directory.
bpatel@766 829 *
bpatel@766 830 * @return a content tree for the link
bpatel@766 831 */
bpatel@766 832 protected Content getNavLinkHelp() {
jjg@1372 833 String helpfile = configuration.helpfile;
jjg@1372 834 DocPath helpfilenm;
jjg@1372 835 if (helpfile.isEmpty()) {
jjg@1372 836 helpfilenm = DocPaths.HELP_DOC;
bpatel@766 837 } else {
jjg@1383 838 DocFile file = DocFile.createFileForInput(configuration, helpfile);
jjg@1383 839 helpfilenm = DocPath.create(file.getName());
bpatel@766 840 }
jjg@1373 841 Content linkContent = getHyperLink(pathToRoot.resolve(helpfilenm),
bpatel@766 842 helpLabel, "", "");
bpatel@766 843 Content li = HtmlTree.LI(linkContent);
bpatel@766 844 return li;
bpatel@766 845 }
bpatel@766 846
bpatel@766 847 /**
bpatel@766 848 * Get summary table header.
bpatel@766 849 *
bpatel@766 850 * @param header the header for the table
bpatel@766 851 * @param scope the scope of the headers
bpatel@766 852 * @return a content tree for the header
bpatel@766 853 */
bpatel@766 854 public Content getSummaryTableHeader(String[] header, String scope) {
bpatel@766 855 Content tr = new HtmlTree(HtmlTag.TR);
bpatel@766 856 int size = header.length;
bpatel@766 857 Content tableHeader;
bpatel@766 858 if (size == 1) {
bpatel@766 859 tableHeader = new StringContent(header[0]);
bpatel@766 860 tr.addContent(HtmlTree.TH(HtmlStyle.colOne, scope, tableHeader));
bpatel@766 861 return tr;
bpatel@766 862 }
bpatel@766 863 for (int i = 0; i < size; i++) {
bpatel@766 864 tableHeader = new StringContent(header[i]);
bpatel@766 865 if(i == 0)
bpatel@766 866 tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
bpatel@766 867 else if(i == (size - 1))
bpatel@766 868 tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
bpatel@766 869 else
bpatel@766 870 tr.addContent(HtmlTree.TH(scope, tableHeader));
bpatel@766 871 }
bpatel@766 872 return tr;
bpatel@766 873 }
bpatel@766 874
bpatel@766 875 /**
bpatel@766 876 * Get table caption.
bpatel@766 877 *
bpatel@766 878 * @param rawText the caption for the table which could be raw Html
bpatel@766 879 * @return a content tree for the caption
bpatel@766 880 */
bpatel@766 881 public Content getTableCaption(String rawText) {
bpatel@766 882 Content title = new RawHtml(rawText);
bpatel@766 883 Content captionSpan = HtmlTree.SPAN(title);
bpatel@766 884 Content space = getSpace();
bpatel@766 885 Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, space);
bpatel@766 886 Content caption = HtmlTree.CAPTION(captionSpan);
bpatel@766 887 caption.addContent(tabSpan);
bpatel@766 888 return caption;
bpatel@766 889 }
bpatel@766 890
bpatel@766 891 /**
bpatel@766 892 * Get the marker anchor which will be added to the documentation tree.
bpatel@766 893 *
bpatel@766 894 * @param anchorName the anchor name attribute
bpatel@766 895 * @return a content tree for the marker anchor
bpatel@766 896 */
bpatel@766 897 public Content getMarkerAnchor(String anchorName) {
bpatel@766 898 return getMarkerAnchor(anchorName, null);
bpatel@766 899 }
bpatel@766 900
bpatel@766 901 /**
bpatel@766 902 * Get the marker anchor which will be added to the documentation tree.
bpatel@766 903 *
bpatel@766 904 * @param anchorName the anchor name attribute
bpatel@766 905 * @param anchorContent the content that should be added to the anchor
bpatel@766 906 * @return a content tree for the marker anchor
bpatel@766 907 */
bpatel@766 908 public Content getMarkerAnchor(String anchorName, Content anchorContent) {
bpatel@766 909 if (anchorContent == null)
bpatel@766 910 anchorContent = new Comment(" ");
bpatel@766 911 Content markerAnchor = HtmlTree.A_NAME(anchorName, anchorContent);
bpatel@766 912 return markerAnchor;
bpatel@766 913 }
bpatel@766 914
bpatel@766 915 /**
bpatel@766 916 * Returns a packagename content.
bpatel@766 917 *
bpatel@766 918 * @param packageDoc the package to check
bpatel@766 919 * @return package name content
bpatel@766 920 */
bpatel@766 921 public Content getPackageName(PackageDoc packageDoc) {
bpatel@766 922 return packageDoc == null || packageDoc.name().length() == 0 ?
bpatel@766 923 defaultPackageLabel :
bpatel@766 924 getPackageLabel(packageDoc.name());
bpatel@766 925 }
bpatel@766 926
bpatel@766 927 /**
bpatel@766 928 * Returns a package name label.
bpatel@766 929 *
jjg@1358 930 * @param packageName the package name
bpatel@766 931 * @return the package name content
bpatel@766 932 */
bpatel@766 933 public Content getPackageLabel(String packageName) {
bpatel@766 934 return new StringContent(packageName);
bpatel@766 935 }
bpatel@766 936
bpatel@766 937 /**
bpatel@995 938 * Add package deprecation information to the documentation tree
bpatel@995 939 *
bpatel@995 940 * @param deprPkgs list of deprecated packages
bpatel@995 941 * @param headingKey the caption for the deprecated package table
bpatel@995 942 * @param tableSummary the summary for the deprecated package table
bpatel@995 943 * @param tableHeader table headers for the deprecated package table
bpatel@995 944 * @param contentTree the content tree to which the deprecated package table will be added
bpatel@995 945 */
bpatel@995 946 protected void addPackageDeprecatedAPI(List<Doc> deprPkgs, String headingKey,
bpatel@995 947 String tableSummary, String[] tableHeader, Content contentTree) {
bpatel@995 948 if (deprPkgs.size() > 0) {
bpatel@995 949 Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
jjg@1410 950 getTableCaption(configuration.getText(headingKey)));
bpatel@995 951 table.addContent(getSummaryTableHeader(tableHeader, "col"));
bpatel@995 952 Content tbody = new HtmlTree(HtmlTag.TBODY);
bpatel@995 953 for (int i = 0; i < deprPkgs.size(); i++) {
bpatel@995 954 PackageDoc pkg = (PackageDoc) deprPkgs.get(i);
bpatel@995 955 HtmlTree td = HtmlTree.TD(HtmlStyle.colOne,
bpatel@995 956 getPackageLink(pkg, getPackageName(pkg)));
bpatel@995 957 if (pkg.tags("deprecated").length > 0) {
bpatel@995 958 addInlineDeprecatedComment(pkg, pkg.tags("deprecated")[0], td);
bpatel@995 959 }
bpatel@995 960 HtmlTree tr = HtmlTree.TR(td);
bpatel@995 961 if (i % 2 == 0) {
bpatel@995 962 tr.addStyle(HtmlStyle.altColor);
bpatel@995 963 } else {
bpatel@995 964 tr.addStyle(HtmlStyle.rowColor);
bpatel@995 965 }
bpatel@995 966 tbody.addContent(tr);
bpatel@995 967 }
bpatel@995 968 table.addContent(tbody);
bpatel@995 969 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@995 970 Content ul = HtmlTree.UL(HtmlStyle.blockList, li);
bpatel@995 971 contentTree.addContent(ul);
bpatel@995 972 }
bpatel@995 973 }
bpatel@995 974
bpatel@995 975 /**
jjg@1381 976 * Return the path to the class page for a classdoc.
duke@1 977 *
duke@1 978 * @param cd Class to which the path is requested.
duke@1 979 * @param name Name of the file(doesn't include path).
duke@1 980 */
jjg@1372 981 protected DocPath pathString(ClassDoc cd, DocPath name) {
duke@1 982 return pathString(cd.containingPackage(), name);
duke@1 983 }
duke@1 984
duke@1 985 /**
duke@1 986 * Return path to the given file name in the given package. So if the name
duke@1 987 * passed is "Object.html" and the name of the package is "java.lang", and
duke@1 988 * if the relative path is "../.." then returned string will be
duke@1 989 * "../../java/lang/Object.html"
duke@1 990 *
duke@1 991 * @param pd Package in which the file name is assumed to be.
duke@1 992 * @param name File name, to which path string is.
duke@1 993 */
jjg@1372 994 protected DocPath pathString(PackageDoc pd, DocPath name) {
jjg@1372 995 return pathToRoot.resolve(DocPath.forPackage(pd).resolve(name));
duke@1 996 }
duke@1 997
duke@1 998 /**
duke@1 999 * Return the link to the given package.
duke@1 1000 *
duke@1 1001 * @param pkg the package to link to.
duke@1 1002 * @param label the label for the link.
bpatel@182 1003 * @param isStrong true if the label should be strong.
duke@1 1004 * @return the link to the given package.
duke@1 1005 */
bpatel@766 1006 public String getPackageLinkString(PackageDoc pkg, String label,
bpatel@182 1007 boolean isStrong) {
bpatel@766 1008 return getPackageLinkString(pkg, label, isStrong, "");
duke@1 1009 }
duke@1 1010
duke@1 1011 /**
duke@1 1012 * Return the link to the given package.
duke@1 1013 *
duke@1 1014 * @param pkg the package to link to.
duke@1 1015 * @param label the label for the link.
bpatel@182 1016 * @param isStrong true if the label should be strong.
duke@1 1017 * @param style the font of the package link label.
duke@1 1018 * @return the link to the given package.
duke@1 1019 */
bpatel@766 1020 public String getPackageLinkString(PackageDoc pkg, String label, boolean isStrong,
duke@1 1021 String style) {
duke@1 1022 boolean included = pkg != null && pkg.isIncluded();
duke@1 1023 if (! included) {
duke@1 1024 PackageDoc[] packages = configuration.packages;
duke@1 1025 for (int i = 0; i < packages.length; i++) {
duke@1 1026 if (packages[i].equals(pkg)) {
duke@1 1027 included = true;
duke@1 1028 break;
duke@1 1029 }
duke@1 1030 }
duke@1 1031 }
duke@1 1032 if (included || pkg == null) {
jjg@1372 1033 return getHyperLinkString(pathString(pkg, DocPaths.PACKAGE_SUMMARY),
jjg@1373 1034 label, isStrong, style);
duke@1 1035 } else {
jjg@1373 1036 DocLink crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
duke@1 1037 if (crossPkgLink != null) {
jjg@1373 1038 return getHyperLinkString(crossPkgLink, label, isStrong, style);
bpatel@766 1039 } else {
bpatel@766 1040 return label;
bpatel@766 1041 }
bpatel@766 1042 }
bpatel@766 1043 }
bpatel@766 1044
bpatel@766 1045 /**
bpatel@766 1046 * Return the link to the given package.
bpatel@766 1047 *
bpatel@766 1048 * @param pkg the package to link to.
bpatel@766 1049 * @param label the label for the link.
bpatel@766 1050 * @return a content tree for the package link.
bpatel@766 1051 */
jjg@1740 1052 public Content getPackageLink(PackageDoc pkg, String label) {
jjg@1740 1053 return getPackageLink(pkg, new StringContent(label));
jjg@1740 1054 }
jjg@1740 1055
jjg@1740 1056 /**
jjg@1740 1057 * Return the link to the given package.
jjg@1740 1058 *
jjg@1740 1059 * @param pkg the package to link to.
jjg@1740 1060 * @param label the label for the link.
jjg@1740 1061 * @return a content tree for the package link.
jjg@1740 1062 */
bpatel@766 1063 public Content getPackageLink(PackageDoc pkg, Content label) {
bpatel@766 1064 boolean included = pkg != null && pkg.isIncluded();
bpatel@766 1065 if (! included) {
bpatel@766 1066 PackageDoc[] packages = configuration.packages;
bpatel@766 1067 for (int i = 0; i < packages.length; i++) {
bpatel@766 1068 if (packages[i].equals(pkg)) {
bpatel@766 1069 included = true;
bpatel@766 1070 break;
bpatel@766 1071 }
bpatel@766 1072 }
bpatel@766 1073 }
bpatel@766 1074 if (included || pkg == null) {
jjg@1372 1075 return getHyperLink(pathString(pkg, DocPaths.PACKAGE_SUMMARY),
jjg@1373 1076 label);
bpatel@766 1077 } else {
jjg@1373 1078 DocLink crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
bpatel@766 1079 if (crossPkgLink != null) {
jjg@1373 1080 return getHyperLink(crossPkgLink, label);
duke@1 1081 } else {
duke@1 1082 return label;
duke@1 1083 }
duke@1 1084 }
duke@1 1085 }
duke@1 1086
jjg@1737 1087 public Content italicsClassName(ClassDoc cd, boolean qual) {
jjg@1737 1088 Content name = new StringContent((qual)? cd.qualifiedName(): cd.name());
jjg@1737 1089 return (cd.isInterface())? HtmlTree.I(name): name;
duke@1 1090 }
duke@1 1091
duke@1 1092 /**
bpatel@766 1093 * Add the link to the content tree.
bpatel@766 1094 *
bpatel@766 1095 * @param doc program element doc for which the link will be added
bpatel@766 1096 * @param label label for the link
bpatel@766 1097 * @param htmltree the content tree to which the link will be added
bpatel@766 1098 */
bpatel@766 1099 public void addSrcLink(ProgramElementDoc doc, Content label, Content htmltree) {
bpatel@766 1100 if (doc == null) {
bpatel@766 1101 return;
bpatel@766 1102 }
bpatel@766 1103 ClassDoc cd = doc.containingClass();
bpatel@766 1104 if (cd == null) {
bpatel@766 1105 //d must be a class doc since in has no containing class.
bpatel@766 1106 cd = (ClassDoc) doc;
bpatel@766 1107 }
jjg@1372 1108 DocPath href = pathToRoot
jjg@1372 1109 .resolve(DocPaths.SOURCE_OUTPUT)
jjg@1372 1110 .resolve(DocPath.forClass(cd));
jjg@1373 1111 Content linkContent = getHyperLink(href.fragment(SourceToHTMLConverter.getAnchorName(doc)), label, "", "");
bpatel@766 1112 htmltree.addContent(linkContent);
bpatel@766 1113 }
bpatel@766 1114
bpatel@766 1115 /**
duke@1 1116 * Return the link to the given class.
duke@1 1117 *
duke@1 1118 * @param linkInfo the information about the link.
duke@1 1119 *
duke@1 1120 * @return the link for the given class.
duke@1 1121 */
jjg@1736 1122 public Content getLink(LinkInfoImpl linkInfo) {
duke@1 1123 LinkFactoryImpl factory = new LinkFactoryImpl(this);
jjg@1736 1124 Content link = factory.getLink(linkInfo);
duke@1 1125 displayLength += linkInfo.displayLength;
duke@1 1126 return link;
duke@1 1127 }
duke@1 1128
duke@1 1129 /**
duke@1 1130 * Return the type parameters for the given class.
duke@1 1131 *
duke@1 1132 * @param linkInfo the information about the link.
duke@1 1133 * @return the type for the given class.
duke@1 1134 */
jjg@1736 1135 public Content getTypeParameterLinks(LinkInfoImpl linkInfo) {
duke@1 1136 LinkFactoryImpl factory = new LinkFactoryImpl(this);
jjg@1736 1137 return factory.getTypeParameterLinks(linkInfo, false);
duke@1 1138 }
duke@1 1139
duke@1 1140 /*************************************************************
duke@1 1141 * Return a class cross link to external class documentation.
duke@1 1142 * The name must be fully qualified to determine which package
duke@1 1143 * the class is in. The -link option does not allow users to
duke@1 1144 * link to external classes in the "default" package.
duke@1 1145 *
duke@1 1146 * @param qualifiedClassName the qualified name of the external class.
duke@1 1147 * @param refMemName the name of the member being referenced. This should
duke@1 1148 * be null or empty string if no member is being referenced.
duke@1 1149 * @param label the label for the external link.
bpatel@182 1150 * @param strong true if the link should be strong.
duke@1 1151 * @param style the style of the link.
duke@1 1152 * @param code true if the label should be code font.
duke@1 1153 */
jjg@1737 1154 public Content getCrossClassLink(String qualifiedClassName, String refMemName,
jjg@1737 1155 Content label, boolean strong, String style,
duke@1 1156 boolean code) {
jjg@1373 1157 String className = "";
jjg@1373 1158 String packageName = qualifiedClassName == null ? "" : qualifiedClassName;
duke@1 1159 int periodIndex;
jjg@1373 1160 while ((periodIndex = packageName.lastIndexOf('.')) != -1) {
duke@1 1161 className = packageName.substring(periodIndex + 1, packageName.length()) +
duke@1 1162 (className.length() > 0 ? "." + className : "");
jjg@1737 1163 Content defaultLabel = new StringContent(className);
jjg@1737 1164 if (code)
jjg@1737 1165 defaultLabel = HtmlTree.CODE(defaultLabel);
duke@1 1166 packageName = packageName.substring(0, periodIndex);
duke@1 1167 if (getCrossPackageLink(packageName) != null) {
duke@1 1168 //The package exists in external documentation, so link to the external
duke@1 1169 //class (assuming that it exists). This is definitely a limitation of
duke@1 1170 //the -link option. There are ways to determine if an external package
duke@1 1171 //exists, but no way to determine if the external class exists. We just
duke@1 1172 //have to assume that it does.
jjg@1373 1173 DocLink link = configuration.extern.getExternalLink(packageName, pathToRoot,
jjg@1373 1174 className + ".html", refMemName);
jjg@1737 1175 return getHyperLink(link,
jjg@1737 1176 (label == null) || label.isEmpty() ? defaultLabel : label,
bpatel@182 1177 strong, style,
duke@1 1178 configuration.getText("doclet.Href_Class_Or_Interface_Title", packageName),
duke@1 1179 "");
duke@1 1180 }
duke@1 1181 }
duke@1 1182 return null;
duke@1 1183 }
duke@1 1184
duke@1 1185 public boolean isClassLinkable(ClassDoc cd) {
duke@1 1186 if (cd.isIncluded()) {
duke@1 1187 return configuration.isGeneratedDoc(cd);
duke@1 1188 }
duke@1 1189 return configuration.extern.isExternal(cd);
duke@1 1190 }
duke@1 1191
jjg@1373 1192 public DocLink getCrossPackageLink(String pkgName) {
jjg@1372 1193 return configuration.extern.getExternalLink(pkgName, pathToRoot,
jjg@1373 1194 DocPaths.PACKAGE_SUMMARY.getPath());
duke@1 1195 }
duke@1 1196
bpatel@766 1197 /**
bpatel@766 1198 * Get the class link.
bpatel@766 1199 *
bpatel@766 1200 * @param context the id of the context where the link will be added
bpatel@766 1201 * @param cd the class doc to link to
bpatel@766 1202 * @return a content tree for the link
bpatel@766 1203 */
jjg@1735 1204 public Content getQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd) {
jjg@1738 1205 return getLink(new LinkInfoImpl(configuration, context, cd)
jjg@1738 1206 .label(configuration.getClassName(cd)));
duke@1 1207 }
duke@1 1208
duke@1 1209 /**
bpatel@766 1210 * Add the class link.
bpatel@766 1211 *
bpatel@766 1212 * @param context the id of the context where the link will be added
bpatel@766 1213 * @param cd the class doc to link to
bpatel@766 1214 * @param contentTree the content tree to which the link will be added
duke@1 1215 */
jjg@1735 1216 public void addPreQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
bpatel@766 1217 addPreQualifiedClassLink(context, cd, false, contentTree);
duke@1 1218 }
duke@1 1219
duke@1 1220 /**
duke@1 1221 * Retrieve the class link with the package portion of the label in
jjg@1373 1222 * plain text. If the qualifier is excluded, it will not be included in the
duke@1 1223 * link label.
duke@1 1224 *
duke@1 1225 * @param cd the class to link to.
bpatel@182 1226 * @param isStrong true if the link should be strong.
duke@1 1227 * @return the link with the package portion of the label in plain text.
duke@1 1228 */
jjg@1737 1229 public Content getPreQualifiedClassLink(LinkInfoImpl.Kind context,
bpatel@182 1230 ClassDoc cd, boolean isStrong) {
jjg@1737 1231 ContentBuilder classlink = new ContentBuilder();
duke@1 1232 PackageDoc pd = cd.containingPackage();
jjg@1737 1233 if (pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
jjg@1737 1234 classlink.addContent(getPkgName(cd));
duke@1 1235 }
jjg@1737 1236 classlink.addContent(getLink(new LinkInfoImpl(configuration,
jjg@1738 1237 context, cd).label(cd.name()).strong(isStrong)));
duke@1 1238 return classlink;
duke@1 1239 }
duke@1 1240
bpatel@766 1241 /**
bpatel@766 1242 * Add the class link with the package portion of the label in
bpatel@766 1243 * plain text. If the qualifier is excluded, it will not be included in the
bpatel@766 1244 * link label.
bpatel@766 1245 *
bpatel@766 1246 * @param context the id of the context where the link will be added
bpatel@766 1247 * @param cd the class to link to
bpatel@766 1248 * @param isStrong true if the link should be strong
bpatel@766 1249 * @param contentTree the content tree to which the link with be added
bpatel@766 1250 */
jjg@1735 1251 public void addPreQualifiedClassLink(LinkInfoImpl.Kind context,
bpatel@766 1252 ClassDoc cd, boolean isStrong, Content contentTree) {
bpatel@766 1253 PackageDoc pd = cd.containingPackage();
bpatel@766 1254 if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
bpatel@766 1255 contentTree.addContent(getPkgName(cd));
bpatel@766 1256 }
jjg@1736 1257 contentTree.addContent(getLink(new LinkInfoImpl(configuration,
jjg@1738 1258 context, cd).label(cd.name()).strong(isStrong)));
bpatel@766 1259 }
duke@1 1260
duke@1 1261 /**
bpatel@766 1262 * Add the class link, with only class name as the strong link and prefixing
duke@1 1263 * plain package name.
bpatel@766 1264 *
bpatel@766 1265 * @param context the id of the context where the link will be added
bpatel@766 1266 * @param cd the class to link to
bpatel@766 1267 * @param contentTree the content tree to which the link with be added
duke@1 1268 */
jjg@1735 1269 public void addPreQualifiedStrongClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
bpatel@766 1270 addPreQualifiedClassLink(context, cd, true, contentTree);
duke@1 1271 }
duke@1 1272
duke@1 1273 /**
bpatel@766 1274 * Get the link for the given member.
duke@1 1275 *
bpatel@766 1276 * @param context the id of the context where the link will be added
bpatel@766 1277 * @param doc the member being linked to
bpatel@766 1278 * @param label the label for the link
bpatel@766 1279 * @return a content tree for the doc link
duke@1 1280 */
jjg@1735 1281 public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label) {
jjg@1737 1282 return getDocLink(context, doc.containingClass(), doc,
jjg@1737 1283 new StringContent(label));
duke@1 1284 }
duke@1 1285
duke@1 1286 /**
duke@1 1287 * Return the link for the given member.
duke@1 1288 *
duke@1 1289 * @param context the id of the context where the link will be printed.
duke@1 1290 * @param doc the member being linked to.
duke@1 1291 * @param label the label for the link.
bpatel@182 1292 * @param strong true if the link should be strong.
duke@1 1293 * @return the link for the given member.
duke@1 1294 */
jjg@1736 1295 public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label,
jjg@1736 1296 boolean strong) {
bpatel@182 1297 return getDocLink(context, doc.containingClass(), doc, label, strong);
duke@1 1298 }
duke@1 1299
duke@1 1300 /**
duke@1 1301 * Return the link for the given member.
duke@1 1302 *
duke@1 1303 * @param context the id of the context where the link will be printed.
duke@1 1304 * @param classDoc the classDoc that we should link to. This is not
duke@1 1305 * necessarily equal to doc.containingClass(). We may be
duke@1 1306 * inheriting comments.
duke@1 1307 * @param doc the member being linked to.
duke@1 1308 * @param label the label for the link.
bpatel@182 1309 * @param strong true if the link should be strong.
duke@1 1310 * @return the link for the given member.
duke@1 1311 */
jjg@1736 1312 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
jjg@1736 1313 String label, boolean strong) {
jjg@1606 1314 return getDocLink(context, classDoc, doc, label, strong, false);
jjg@1606 1315 }
jjg@1606 1316
jjg@1606 1317 /**
jjg@1606 1318 * Return the link for the given member.
jjg@1606 1319 *
jjg@1606 1320 * @param context the id of the context where the link will be printed.
jjg@1606 1321 * @param classDoc the classDoc that we should link to. This is not
jjg@1606 1322 * necessarily equal to doc.containingClass(). We may be
jjg@1606 1323 * inheriting comments.
jjg@1606 1324 * @param doc the member being linked to.
jjg@1606 1325 * @param label the label for the link.
jjg@1606 1326 * @param strong true if the link should be strong.
jjg@1606 1327 * @param isProperty true if the doc parameter is a JavaFX property.
jjg@1606 1328 * @return the link for the given member.
jjg@1606 1329 */
jjg@1736 1330 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
jjg@1737 1331 String label, boolean strong, boolean isProperty) {
jjg@1737 1332 return getDocLink(context, classDoc, doc, new RawHtml(label), strong, isProperty);
jjg@1737 1333 }
jjg@1737 1334
jjg@1737 1335 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
jjg@1737 1336 Content label, boolean strong, boolean isProperty) {
duke@1 1337 if (! (doc.isIncluded() ||
jjg@1410 1338 Util.isLinkable(classDoc, configuration))) {
jjg@1737 1339 return label;
duke@1 1340 } else if (doc instanceof ExecutableMemberDoc) {
duke@1 1341 ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
jjg@1738 1342 return getLink(new LinkInfoImpl(configuration, context, classDoc)
jjg@1738 1343 .label(label).where(getAnchor(emd, isProperty)).strong(strong));
duke@1 1344 } else if (doc instanceof MemberDoc) {
jjg@1738 1345 return getLink(new LinkInfoImpl(configuration, context, classDoc)
jjg@1738 1346 .label(label).where(doc.name()).strong(strong));
duke@1 1347 } else {
jjg@1737 1348 return label;
duke@1 1349 }
duke@1 1350 }
duke@1 1351
bpatel@766 1352 /**
bpatel@766 1353 * Return the link for the given member.
bpatel@766 1354 *
bpatel@766 1355 * @param context the id of the context where the link will be added
bpatel@766 1356 * @param classDoc the classDoc that we should link to. This is not
bpatel@766 1357 * necessarily equal to doc.containingClass(). We may be
bpatel@766 1358 * inheriting comments
bpatel@766 1359 * @param doc the member being linked to
bpatel@766 1360 * @param label the label for the link
bpatel@766 1361 * @return the link for the given member
bpatel@766 1362 */
jjg@1735 1363 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
jjg@1737 1364 Content label) {
bpatel@766 1365 if (! (doc.isIncluded() ||
jjg@1410 1366 Util.isLinkable(classDoc, configuration))) {
jjg@1737 1367 return label;
bpatel@766 1368 } else if (doc instanceof ExecutableMemberDoc) {
jjg@1738 1369 ExecutableMemberDoc emd = (ExecutableMemberDoc) doc;
jjg@1738 1370 return getLink(new LinkInfoImpl(configuration, context, classDoc)
jjg@1738 1371 .label(label).where(getAnchor(emd)));
bpatel@766 1372 } else if (doc instanceof MemberDoc) {
jjg@1738 1373 return getLink(new LinkInfoImpl(configuration, context, classDoc)
jjg@1738 1374 .label(label).where(doc.name()));
bpatel@766 1375 } else {
jjg@1737 1376 return label;
bpatel@766 1377 }
bpatel@766 1378 }
bpatel@766 1379
duke@1 1380 public String getAnchor(ExecutableMemberDoc emd) {
jjg@1606 1381 return getAnchor(emd, false);
jjg@1606 1382 }
jjg@1606 1383
jjg@1606 1384 public String getAnchor(ExecutableMemberDoc emd, boolean isProperty) {
jjg@1606 1385 if (isProperty) {
jjg@1606 1386 return emd.name();
jjg@1606 1387 }
duke@1 1388 StringBuilder signature = new StringBuilder(emd.signature());
duke@1 1389 StringBuilder signatureParsed = new StringBuilder();
duke@1 1390 int counter = 0;
duke@1 1391 for (int i = 0; i < signature.length(); i++) {
duke@1 1392 char c = signature.charAt(i);
duke@1 1393 if (c == '<') {
duke@1 1394 counter++;
duke@1 1395 } else if (c == '>') {
duke@1 1396 counter--;
duke@1 1397 } else if (counter == 0) {
duke@1 1398 signatureParsed.append(c);
duke@1 1399 }
duke@1 1400 }
duke@1 1401 return emd.name() + signatureParsed.toString();
duke@1 1402 }
duke@1 1403
duke@1 1404 public String seeTagToString(SeeTag see) {
duke@1 1405 String tagName = see.name();
duke@1 1406 if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
duke@1 1407 return "";
duke@1 1408 }
jjg@1365 1409
duke@1 1410 String seetext = replaceDocRootDir(see.text());
duke@1 1411
duke@1 1412 //Check if @see is an href or "string"
duke@1 1413 if (seetext.startsWith("<") || seetext.startsWith("\"")) {
jjg@1365 1414 return seetext;
duke@1 1415 }
duke@1 1416
jjg@1365 1417 boolean plain = tagName.equalsIgnoreCase("@linkplain");
jjg@1737 1418 Content label = plainOrCode(plain, new RawHtml(see.label()));
jjg@1365 1419
duke@1 1420 //The text from the @see tag. We will output this text when a label is not specified.
jjg@1737 1421 Content text = plainOrCode(plain, new RawHtml(seetext));
duke@1 1422
duke@1 1423 ClassDoc refClass = see.referencedClass();
duke@1 1424 String refClassName = see.referencedClassName();
duke@1 1425 MemberDoc refMem = see.referencedMember();
duke@1 1426 String refMemName = see.referencedMemberName();
jjg@1365 1427
duke@1 1428 if (refClass == null) {
duke@1 1429 //@see is not referencing an included class
duke@1 1430 PackageDoc refPackage = see.referencedPackage();
duke@1 1431 if (refPackage != null && refPackage.isIncluded()) {
duke@1 1432 //@see is referencing an included package
jjg@1365 1433 if (label.isEmpty())
jjg@1737 1434 label = plainOrCode(plain, new StringContent(refPackage.name()));
jjg@1737 1435 return getPackageLink(refPackage, label).toString();
duke@1 1436 } else {
duke@1 1437 //@see is not referencing an included class or package. Check for cross links.
jjg@1737 1438 Content classCrossLink;
jjg@1373 1439 DocLink packageCrossLink = getCrossPackageLink(refClassName);
duke@1 1440 if (packageCrossLink != null) {
duke@1 1441 //Package cross link found
jjg@1737 1442 return getHyperLink(packageCrossLink,
jjg@1737 1443 (label.isEmpty() ? text : label)).toString();
duke@1 1444 } else if ((classCrossLink = getCrossClassLink(refClassName,
jjg@1365 1445 refMemName, label, false, "", !plain)) != null) {
jjg@1365 1446 //Class cross link found (possibly to a member in the class)
jjg@1737 1447 return classCrossLink.toString();
duke@1 1448 } else {
duke@1 1449 //No cross link found so print warning
duke@1 1450 configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
duke@1 1451 tagName, seetext);
jjg@1737 1452 return (label.isEmpty() ? text: label).toString();
duke@1 1453 }
duke@1 1454 }
duke@1 1455 } else if (refMemName == null) {
duke@1 1456 // Must be a class reference since refClass is not null and refMemName is null.
jjg@1365 1457 if (label.isEmpty()) {
jjg@1737 1458 label = plainOrCode(plain, new StringContent(refClass.name()));
duke@1 1459 }
jjg@1738 1460 return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass)
jjg@1738 1461 .label(label)).toString();
duke@1 1462 } else if (refMem == null) {
duke@1 1463 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 1464 // However, refMem is null, so this referenced member does not exist.
jjg@1737 1465 return (label.isEmpty() ? text: label).toString();
duke@1 1466 } else {
duke@1 1467 // Must be a member reference since refClass is not null and refMemName is not null.
duke@1 1468 // refMem is not null, so this @see tag must be referencing a valid member.
duke@1 1469 ClassDoc containing = refMem.containingClass();
duke@1 1470 if (see.text().trim().startsWith("#") &&
duke@1 1471 ! (containing.isPublic() ||
jjg@1410 1472 Util.isLinkable(containing, configuration))) {
duke@1 1473 // Since the link is relative and the holder is not even being
duke@1 1474 // documented, this must be an inherited link. Redirect it.
duke@1 1475 // The current class either overrides the referenced member or
duke@1 1476 // inherits it automatically.
jjg@405 1477 if (this instanceof ClassWriterImpl) {
jjg@405 1478 containing = ((ClassWriterImpl) this).getClassDoc();
jjg@405 1479 } else if (!containing.isPublic()){
jjg@405 1480 configuration.getDocletSpecificMsg().warning(
jjg@405 1481 see.position(), "doclet.see.class_or_package_not_accessible",
jjg@405 1482 tagName, containing.qualifiedName());
jjg@405 1483 } else {
jjg@405 1484 configuration.getDocletSpecificMsg().warning(
jjg@405 1485 see.position(), "doclet.see.class_or_package_not_found",
jjg@405 1486 tagName, seetext);
jjg@405 1487 }
duke@1 1488 }
duke@1 1489 if (configuration.currentcd != containing) {
duke@1 1490 refMemName = containing.name() + "." + refMemName;
duke@1 1491 }
duke@1 1492 if (refMem instanceof ExecutableMemberDoc) {
duke@1 1493 if (refMemName.indexOf('(') < 0) {
duke@1 1494 refMemName += ((ExecutableMemberDoc)refMem).signature();
duke@1 1495 }
duke@1 1496 }
duke@1 1497
jjg@1737 1498 text = plainOrCode(plain, new StringContent(refMemName));
jjg@1365 1499
jjg@1735 1500 return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing,
jjg@1737 1501 refMem, (label.isEmpty() ? text: label).toString(), false).toString();
duke@1 1502 }
duke@1 1503 }
duke@1 1504
jjg@1365 1505 private String plainOrCodeText(boolean plain, String text) {
jjg@1365 1506 return (plain || text.isEmpty()) ? text : codeText(text);
duke@1 1507 }
duke@1 1508
jjg@1737 1509 private Content plainOrCode(boolean plain, Content body) {
jjg@1737 1510 return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
jjg@1737 1511 }
jjg@1737 1512
bpatel@766 1513 /**
bpatel@766 1514 * Add the inline comment.
bpatel@766 1515 *
bpatel@766 1516 * @param doc the doc for which the inline comment will be added
bpatel@766 1517 * @param tag the inline tag to be added
bpatel@766 1518 * @param htmltree the content tree to which the comment will be added
bpatel@766 1519 */
bpatel@766 1520 public void addInlineComment(Doc doc, Tag tag, Content htmltree) {
jjg@1724 1521 addCommentTags(doc, tag, tag.inlineTags(), false, false, htmltree);
bpatel@766 1522 }
bpatel@766 1523
bpatel@766 1524 /**
bpatel@766 1525 * Add the inline deprecated comment.
bpatel@766 1526 *
bpatel@766 1527 * @param doc the doc for which the inline deprecated comment will be added
bpatel@766 1528 * @param tag the inline tag to be added
bpatel@766 1529 * @param htmltree the content tree to which the comment will be added
bpatel@766 1530 */
bpatel@766 1531 public void addInlineDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
bpatel@766 1532 addCommentTags(doc, tag.inlineTags(), true, false, htmltree);
bpatel@766 1533 }
bpatel@766 1534
bpatel@766 1535 /**
bpatel@766 1536 * Adds the summary content.
bpatel@766 1537 *
bpatel@766 1538 * @param doc the doc for which the summary will be generated
bpatel@766 1539 * @param htmltree the documentation tree to which the summary will be added
bpatel@766 1540 */
bpatel@766 1541 public void addSummaryComment(Doc doc, Content htmltree) {
bpatel@766 1542 addSummaryComment(doc, doc.firstSentenceTags(), htmltree);
bpatel@766 1543 }
bpatel@766 1544
bpatel@766 1545 /**
bpatel@766 1546 * Adds the summary content.
bpatel@766 1547 *
bpatel@766 1548 * @param doc the doc for which the summary will be generated
bpatel@766 1549 * @param firstSentenceTags the first sentence tags for the doc
bpatel@766 1550 * @param htmltree the documentation tree to which the summary will be added
bpatel@766 1551 */
bpatel@766 1552 public void addSummaryComment(Doc doc, Tag[] firstSentenceTags, Content htmltree) {
bpatel@766 1553 addCommentTags(doc, firstSentenceTags, false, true, htmltree);
bpatel@766 1554 }
bpatel@766 1555
bpatel@766 1556 public void addSummaryDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
bpatel@766 1557 addCommentTags(doc, tag.firstSentenceTags(), true, true, htmltree);
bpatel@766 1558 }
bpatel@766 1559
bpatel@766 1560 /**
bpatel@766 1561 * Adds the inline comment.
bpatel@766 1562 *
bpatel@766 1563 * @param doc the doc for which the inline comments will be generated
bpatel@766 1564 * @param htmltree the documentation tree to which the inline comments will be added
bpatel@766 1565 */
bpatel@766 1566 public void addInlineComment(Doc doc, Content htmltree) {
bpatel@766 1567 addCommentTags(doc, doc.inlineTags(), false, false, htmltree);
bpatel@766 1568 }
bpatel@766 1569
duke@1 1570 /**
bpatel@766 1571 * Adds the comment tags.
bpatel@766 1572 *
bpatel@766 1573 * @param doc the doc for which the comment tags will be generated
bpatel@766 1574 * @param tags the first sentence tags for the doc
bpatel@766 1575 * @param depr true if it is deprecated
jjg@1372 1576 * @param first true if the first sentence tags should be added
bpatel@766 1577 * @param htmltree the documentation tree to which the comment tags will be added
bpatel@766 1578 */
bpatel@766 1579 private void addCommentTags(Doc doc, Tag[] tags, boolean depr,
bpatel@766 1580 boolean first, Content htmltree) {
jjg@1724 1581 addCommentTags(doc, null, tags, depr, first, htmltree);
jjg@1724 1582 }
jjg@1724 1583
jjg@1724 1584 /**
jjg@1724 1585 * Adds the comment tags.
jjg@1724 1586 *
jjg@1724 1587 * @param doc the doc for which the comment tags will be generated
jjg@1724 1588 * @param holderTag the block tag context for the inline tags
jjg@1724 1589 * @param tags the first sentence tags for the doc
jjg@1724 1590 * @param depr true if it is deprecated
jjg@1724 1591 * @param first true if the first sentence tags should be added
jjg@1724 1592 * @param htmltree the documentation tree to which the comment tags will be added
jjg@1724 1593 */
jjg@1724 1594 private void addCommentTags(Doc doc, Tag holderTag, Tag[] tags, boolean depr,
jjg@1724 1595 boolean first, Content htmltree) {
bpatel@766 1596 if(configuration.nocomment){
bpatel@766 1597 return;
bpatel@766 1598 }
bpatel@766 1599 Content div;
jjg@1724 1600 Content result = new RawHtml(commentTagsToString(holderTag, doc, tags, first));
bpatel@766 1601 if (depr) {
bpatel@766 1602 Content italic = HtmlTree.I(result);
bpatel@766 1603 div = HtmlTree.DIV(HtmlStyle.block, italic);
bpatel@766 1604 htmltree.addContent(div);
bpatel@766 1605 }
bpatel@766 1606 else {
bpatel@766 1607 div = HtmlTree.DIV(HtmlStyle.block, result);
bpatel@766 1608 htmltree.addContent(div);
bpatel@766 1609 }
bpatel@766 1610 if (tags.length == 0) {
bpatel@766 1611 htmltree.addContent(getSpace());
bpatel@766 1612 }
bpatel@766 1613 }
bpatel@766 1614
bpatel@766 1615 /**
duke@1 1616 * Converts inline tags and text to text strings, expanding the
duke@1 1617 * inline tags along the way. Called wherever text can contain
duke@1 1618 * an inline tag, such as in comments or in free-form text arguments
duke@1 1619 * to non-inline tags.
duke@1 1620 *
duke@1 1621 * @param holderTag specific tag where comment resides
duke@1 1622 * @param doc specific doc where comment resides
duke@1 1623 * @param tags array of text tags and inline tags (often alternating)
duke@1 1624 * present in the text of interest for this doc
duke@1 1625 * @param isFirstSentence true if text is first sentence
duke@1 1626 */
duke@1 1627 public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
duke@1 1628 boolean isFirstSentence) {
jjg@910 1629 StringBuilder result = new StringBuilder();
bpatel@997 1630 boolean textTagChange = false;
duke@1 1631 // Array of all possible inline tags for this javadoc run
duke@1 1632 configuration.tagletManager.checkTags(doc, tags, true);
duke@1 1633 for (int i = 0; i < tags.length; i++) {
duke@1 1634 Tag tagelem = tags[i];
duke@1 1635 String tagName = tagelem.name();
duke@1 1636 if (tagelem instanceof SeeTag) {
duke@1 1637 result.append(seeTagToString((SeeTag)tagelem));
duke@1 1638 } else if (! tagName.equals("Text")) {
duke@1 1639 int originalLength = result.length();
duke@1 1640 TagletOutput output = TagletWriter.getInlineTagOuput(
duke@1 1641 configuration.tagletManager, holderTag,
jjg@74 1642 tagelem, getTagletWriterInstance(isFirstSentence));
duke@1 1643 result.append(output == null ? "" : output.toString());
duke@1 1644 if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
duke@1 1645 break;
bpatel@997 1646 } else if (configuration.docrootparent.length() > 0 &&
bpatel@997 1647 tagelem.name().equals("@docRoot") &&
bpatel@997 1648 ((tags[i + 1]).text()).startsWith("/..")) {
bpatel@997 1649 //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
bpatel@997 1650 //{@docRoot} tag in the very next Text tag.
bpatel@997 1651 textTagChange = true;
bpatel@997 1652 continue;
duke@1 1653 } else {
bpatel@997 1654 continue;
duke@1 1655 }
duke@1 1656 } else {
bpatel@997 1657 String text = tagelem.text();
bpatel@997 1658 //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
bpatel@997 1659 if (textTagChange) {
bpatel@997 1660 text = text.replaceFirst("/..", "");
bpatel@997 1661 textTagChange = false;
bpatel@997 1662 }
duke@1 1663 //This is just a regular text tag. The text may contain html links (<a>)
duke@1 1664 //or inline tag {@docRoot}, which will be handled as special cases.
bpatel@997 1665 text = redirectRelativeLinks(tagelem.holder(), text);
duke@1 1666
duke@1 1667 // Replace @docRoot only if not represented by an instance of DocRootTaglet,
duke@1 1668 // that is, only if it was not present in a source file doc comment.
duke@1 1669 // This happens when inserted by the doclet (a few lines
duke@1 1670 // above in this method). [It might also happen when passed in on the command
duke@1 1671 // line as a text argument to an option (like -header).]
duke@1 1672 text = replaceDocRootDir(text);
duke@1 1673 if (isFirstSentence) {
duke@1 1674 text = removeNonInlineHtmlTags(text);
duke@1 1675 }
duke@1 1676 StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
jjg@1362 1677 StringBuilder textBuff = new StringBuilder();
duke@1 1678 while (lines.hasMoreTokens()) {
jjg@910 1679 StringBuilder line = new StringBuilder(lines.nextToken());
jjg@1410 1680 Util.replaceTabs(configuration, line);
duke@1 1681 textBuff.append(line.toString());
duke@1 1682 }
duke@1 1683 result.append(textBuff);
duke@1 1684 }
duke@1 1685 }
duke@1 1686 return result.toString();
duke@1 1687 }
duke@1 1688
duke@1 1689 /**
duke@1 1690 * Return true if relative links should not be redirected.
duke@1 1691 *
duke@1 1692 * @return Return true if a relative link should not be redirected.
duke@1 1693 */
duke@1 1694 private boolean shouldNotRedirectRelativeLinks() {
duke@1 1695 return this instanceof AnnotationTypeWriter ||
duke@1 1696 this instanceof ClassWriter ||
duke@1 1697 this instanceof PackageSummaryWriter;
duke@1 1698 }
duke@1 1699
duke@1 1700 /**
duke@1 1701 * Suppose a piece of documentation has a relative link. When you copy
jjg@1372 1702 * that documentation to another place such as the index or class-use page,
duke@1 1703 * that relative link will no longer work. We should redirect those links
duke@1 1704 * so that they will work again.
duke@1 1705 * <p>
duke@1 1706 * Here is the algorithm used to fix the link:
duke@1 1707 * <p>
jjg@1326 1708 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
duke@1 1709 * <p>
duke@1 1710 * For example, suppose com.sun.javadoc.RootDoc has this link:
jjg@1326 1711 * {@literal <a href="package-summary.html">The package Page</a> }
duke@1 1712 * <p>
duke@1 1713 * If this link appeared in the index, we would redirect
duke@1 1714 * the link like this:
duke@1 1715 *
jjg@1326 1716 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
duke@1 1717 *
duke@1 1718 * @param doc the Doc object whose documentation is being written.
duke@1 1719 * @param text the text being written.
duke@1 1720 *
duke@1 1721 * @return the text, with all the relative links redirected to work.
duke@1 1722 */
duke@1 1723 private String redirectRelativeLinks(Doc doc, String text) {
duke@1 1724 if (doc == null || shouldNotRedirectRelativeLinks()) {
duke@1 1725 return text;
duke@1 1726 }
duke@1 1727
jjg@1372 1728 DocPath redirectPathFromRoot;
duke@1 1729 if (doc instanceof ClassDoc) {
jjg@1372 1730 redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
duke@1 1731 } else if (doc instanceof MemberDoc) {
jjg@1372 1732 redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
duke@1 1733 } else if (doc instanceof PackageDoc) {
jjg@1372 1734 redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
duke@1 1735 } else {
duke@1 1736 return text;
duke@1 1737 }
duke@1 1738
duke@1 1739 //Redirect all relative links.
duke@1 1740 int end, begin = text.toLowerCase().indexOf("<a");
duke@1 1741 if(begin >= 0){
jjg@1362 1742 StringBuilder textBuff = new StringBuilder(text);
duke@1 1743
duke@1 1744 while(begin >=0){
duke@1 1745 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
duke@1 1746 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 1747 continue;
duke@1 1748 }
duke@1 1749
duke@1 1750 begin = textBuff.indexOf("=", begin) + 1;
duke@1 1751 end = textBuff.indexOf(">", begin +1);
duke@1 1752 if(begin == 0){
duke@1 1753 //Link has no equal symbol.
duke@1 1754 configuration.root.printWarning(
duke@1 1755 doc.position(),
duke@1 1756 configuration.getText("doclet.malformed_html_link_tag", text));
duke@1 1757 break;
duke@1 1758 }
duke@1 1759 if (end == -1) {
duke@1 1760 //Break without warning. This <a> tag is not necessarily malformed. The text
duke@1 1761 //might be missing '>' character because the href has an inline tag.
duke@1 1762 break;
duke@1 1763 }
jjg@1372 1764 if (textBuff.substring(begin, end).indexOf("\"") != -1){
duke@1 1765 begin = textBuff.indexOf("\"", begin) + 1;
duke@1 1766 end = textBuff.indexOf("\"", begin +1);
jjg@1372 1767 if (begin == 0 || end == -1){
duke@1 1768 //Link is missing a quote.
duke@1 1769 break;
duke@1 1770 }
duke@1 1771 }
duke@1 1772 String relativeLink = textBuff.substring(begin, end);
jjg@1372 1773 if (!(relativeLink.toLowerCase().startsWith("mailto:") ||
jjg@1372 1774 relativeLink.toLowerCase().startsWith("http:") ||
jjg@1372 1775 relativeLink.toLowerCase().startsWith("https:") ||
jjg@1372 1776 relativeLink.toLowerCase().startsWith("file:"))) {
jjg@1372 1777 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
jjg@1372 1778 + redirectPathFromRoot.resolve(relativeLink).getPath();
duke@1 1779 textBuff.replace(begin, end, relativeLink);
duke@1 1780 }
duke@1 1781 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
duke@1 1782 }
duke@1 1783 return textBuff.toString();
duke@1 1784 }
duke@1 1785 return text;
duke@1 1786 }
duke@1 1787
duke@1 1788 public String removeNonInlineHtmlTags(String text) {
duke@1 1789 if (text.indexOf('<') < 0) {
duke@1 1790 return text;
duke@1 1791 }
duke@1 1792 String noninlinetags[] = { "<ul>", "</ul>", "<ol>", "</ol>",
duke@1 1793 "<dl>", "</dl>", "<table>", "</table>",
duke@1 1794 "<tr>", "</tr>", "<td>", "</td>",
duke@1 1795 "<th>", "</th>", "<p>", "</p>",
duke@1 1796 "<li>", "</li>", "<dd>", "</dd>",
duke@1 1797 "<dir>", "</dir>", "<dt>", "</dt>",
duke@1 1798 "<h1>", "</h1>", "<h2>", "</h2>",
duke@1 1799 "<h3>", "</h3>", "<h4>", "</h4>",
duke@1 1800 "<h5>", "</h5>", "<h6>", "</h6>",
duke@1 1801 "<pre>", "</pre>", "<menu>", "</menu>",
duke@1 1802 "<listing>", "</listing>", "<hr>",
duke@1 1803 "<blockquote>", "</blockquote>",
duke@1 1804 "<center>", "</center>",
duke@1 1805 "<UL>", "</UL>", "<OL>", "</OL>",
duke@1 1806 "<DL>", "</DL>", "<TABLE>", "</TABLE>",
duke@1 1807 "<TR>", "</TR>", "<TD>", "</TD>",
duke@1 1808 "<TH>", "</TH>", "<P>", "</P>",
duke@1 1809 "<LI>", "</LI>", "<DD>", "</DD>",
duke@1 1810 "<DIR>", "</DIR>", "<DT>", "</DT>",
duke@1 1811 "<H1>", "</H1>", "<H2>", "</H2>",
duke@1 1812 "<H3>", "</H3>", "<H4>", "</H4>",
duke@1 1813 "<H5>", "</H5>", "<H6>", "</H6>",
duke@1 1814 "<PRE>", "</PRE>", "<MENU>", "</MENU>",
duke@1 1815 "<LISTING>", "</LISTING>", "<HR>",
duke@1 1816 "<BLOCKQUOTE>", "</BLOCKQUOTE>",
duke@1 1817 "<CENTER>", "</CENTER>"
duke@1 1818 };
duke@1 1819 for (int i = 0; i < noninlinetags.length; i++) {
duke@1 1820 text = replace(text, noninlinetags[i], "");
duke@1 1821 }
duke@1 1822 return text;
duke@1 1823 }
duke@1 1824
duke@1 1825 public String replace(String text, String tobe, String by) {
duke@1 1826 while (true) {
duke@1 1827 int startindex = text.indexOf(tobe);
duke@1 1828 if (startindex < 0) {
duke@1 1829 return text;
duke@1 1830 }
duke@1 1831 int endindex = startindex + tobe.length();
jjg@910 1832 StringBuilder replaced = new StringBuilder();
duke@1 1833 if (startindex > 0) {
duke@1 1834 replaced.append(text.substring(0, startindex));
duke@1 1835 }
duke@1 1836 replaced.append(by);
duke@1 1837 if (text.length() > endindex) {
duke@1 1838 replaced.append(text.substring(endindex));
duke@1 1839 }
duke@1 1840 text = replaced.toString();
duke@1 1841 }
duke@1 1842 }
duke@1 1843
duke@1 1844 /**
bpatel@766 1845 * Returns a link to the stylesheet file.
bpatel@766 1846 *
bpatel@766 1847 * @return an HtmlTree for the lINK tag which provides the stylesheet location
bpatel@766 1848 */
bpatel@766 1849 public HtmlTree getStyleSheetProperties() {
jjg@1383 1850 String stylesheetfile = configuration.stylesheetfile;
jjg@1372 1851 DocPath stylesheet;
jjg@1383 1852 if (stylesheetfile.isEmpty()) {
jjg@1383 1853 stylesheet = DocPaths.STYLESHEET;
bpatel@766 1854 } else {
jjg@1383 1855 DocFile file = DocFile.createFileForInput(configuration, stylesheetfile);
jjg@1383 1856 stylesheet = DocPath.create(file.getName());
bpatel@766 1857 }
jjg@1372 1858 HtmlTree link = HtmlTree.LINK("stylesheet", "text/css",
jjg@1372 1859 pathToRoot.resolve(stylesheet).getPath(),
jjg@1372 1860 "Style");
bpatel@766 1861 return link;
bpatel@766 1862 }
bpatel@766 1863
bpatel@766 1864 /**
bpatel@1417 1865 * Returns a link to the JavaScript file.
bpatel@1417 1866 *
bpatel@1417 1867 * @return an HtmlTree for the Script tag which provides the JavaScript location
bpatel@1417 1868 */
bpatel@1417 1869 public HtmlTree getScriptProperties() {
bpatel@1417 1870 HtmlTree script = HtmlTree.SCRIPT("text/javascript",
bpatel@1417 1871 pathToRoot.resolve(DocPaths.JAVASCRIPT).getPath());
bpatel@1417 1872 return script;
bpatel@1417 1873 }
bpatel@1417 1874
bpatel@1417 1875 /**
jjh@972 1876 * According to
jjh@972 1877 * <cite>The Java&trade; Language Specification</cite>,
jjh@972 1878 * all the outer classes and static nested classes are core classes.
duke@1 1879 */
duke@1 1880 public boolean isCoreClass(ClassDoc cd) {
duke@1 1881 return cd.containingClass() == null || cd.isStatic();
duke@1 1882 }
duke@1 1883
duke@1 1884 /**
bpatel@766 1885 * Adds the annotatation types for the given packageDoc.
bpatel@766 1886 *
bpatel@766 1887 * @param packageDoc the package to write annotations for.
bpatel@766 1888 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 1889 * added
bpatel@766 1890 */
bpatel@766 1891 public void addAnnotationInfo(PackageDoc packageDoc, Content htmltree) {
bpatel@766 1892 addAnnotationInfo(packageDoc, packageDoc.annotations(), htmltree);
bpatel@766 1893 }
bpatel@766 1894
bpatel@766 1895 /**
jjg@1521 1896 * Add the annotation types of the executable receiver.
jjg@1521 1897 *
jjg@1521 1898 * @param method the executable to write the receiver annotations for.
bpatel@1686 1899 * @param descList list of annotation description.
jjg@1521 1900 * @param htmltree the documentation tree to which the annotation info will be
jjg@1521 1901 * added
jjg@1521 1902 */
bpatel@1686 1903 public void addReceiverAnnotationInfo(ExecutableMemberDoc method, AnnotationDesc[] descList,
bpatel@1686 1904 Content htmltree) {
bpatel@1686 1905 addAnnotationInfo(0, method, descList, false, htmltree);
jjg@1521 1906 }
jjg@1521 1907
jjg@1521 1908 /**
bpatel@766 1909 * Adds the annotatation types for the given doc.
bpatel@766 1910 *
jjg@1358 1911 * @param doc the package to write annotations for
bpatel@766 1912 * @param htmltree the content tree to which the annotation types will be added
bpatel@766 1913 */
bpatel@766 1914 public void addAnnotationInfo(ProgramElementDoc doc, Content htmltree) {
bpatel@766 1915 addAnnotationInfo(doc, doc.annotations(), htmltree);
bpatel@766 1916 }
bpatel@766 1917
bpatel@766 1918 /**
bpatel@766 1919 * Add the annotatation types for the given doc and parameter.
bpatel@766 1920 *
bpatel@766 1921 * @param indent the number of spaces to indent the parameters.
bpatel@766 1922 * @param doc the doc to write annotations for.
bpatel@766 1923 * @param param the parameter to write annotations for.
bpatel@766 1924 * @param tree the content tree to which the annotation types will be added
bpatel@766 1925 */
bpatel@766 1926 public boolean addAnnotationInfo(int indent, Doc doc, Parameter param,
bpatel@766 1927 Content tree) {
bpatel@766 1928 return addAnnotationInfo(indent, doc, param.annotations(), false, tree);
bpatel@766 1929 }
bpatel@766 1930
bpatel@766 1931 /**
bpatel@766 1932 * Adds the annotatation types for the given doc.
bpatel@766 1933 *
bpatel@766 1934 * @param doc the doc to write annotations for.
bpatel@766 1935 * @param descList the array of {@link AnnotationDesc}.
bpatel@766 1936 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 1937 * added
bpatel@766 1938 */
bpatel@766 1939 private void addAnnotationInfo(Doc doc, AnnotationDesc[] descList,
bpatel@766 1940 Content htmltree) {
bpatel@766 1941 addAnnotationInfo(0, doc, descList, true, htmltree);
bpatel@766 1942 }
bpatel@766 1943
bpatel@766 1944 /**
bpatel@766 1945 * Adds the annotatation types for the given doc.
bpatel@766 1946 *
bpatel@766 1947 * @param indent the number of extra spaces to indent the annotations.
bpatel@766 1948 * @param doc the doc to write annotations for.
bpatel@766 1949 * @param descList the array of {@link AnnotationDesc}.
bpatel@766 1950 * @param htmltree the documentation tree to which the annotation info will be
bpatel@766 1951 * added
bpatel@766 1952 */
bpatel@766 1953 private boolean addAnnotationInfo(int indent, Doc doc,
bpatel@766 1954 AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
bpatel@766 1955 List<String> annotations = getAnnotations(indent, descList, lineBreak);
bpatel@1686 1956 String sep ="";
bpatel@766 1957 if (annotations.size() == 0) {
bpatel@766 1958 return false;
bpatel@766 1959 }
bpatel@766 1960 Content annotationContent;
bpatel@766 1961 for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
bpatel@1686 1962 htmltree.addContent(sep);
bpatel@766 1963 annotationContent = new RawHtml(iter.next());
bpatel@766 1964 htmltree.addContent(annotationContent);
bpatel@1686 1965 sep = " ";
bpatel@766 1966 }
bpatel@766 1967 return true;
bpatel@766 1968 }
bpatel@766 1969
bpatel@766 1970 /**
duke@1 1971 * Return the string representations of the annotation types for
duke@1 1972 * the given doc.
duke@1 1973 *
duke@1 1974 * @param indent the number of extra spaces to indent the annotations.
duke@1 1975 * @param descList the array of {@link AnnotationDesc}.
duke@1 1976 * @param linkBreak if true, add new line between each member value.
duke@1 1977 * @return an array of strings representing the annotations being
duke@1 1978 * documented.
duke@1 1979 */
jjg@74 1980 private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
jjg@1521 1981 return getAnnotations(indent, descList, linkBreak, true);
jjg@1521 1982 }
jjg@1521 1983
jjg@1521 1984 /**
jjg@1521 1985 * Return the string representations of the annotation types for
jjg@1521 1986 * the given doc.
jjg@1521 1987 *
jjg@1521 1988 * A {@code null} {@code elementType} indicates that all the
jjg@1521 1989 * annotations should be returned without any filtering.
jjg@1521 1990 *
jjg@1521 1991 * @param indent the number of extra spaces to indent the annotations.
jjg@1521 1992 * @param descList the array of {@link AnnotationDesc}.
jjg@1521 1993 * @param linkBreak if true, add new line between each member value.
jjg@1521 1994 * @param elementType the type of targeted element (used for filtering
jjg@1521 1995 * type annotations from declaration annotations)
jjg@1521 1996 * @return an array of strings representing the annotations being
jjg@1521 1997 * documented.
jjg@1521 1998 */
jjg@1521 1999 public List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak,
jjg@1521 2000 boolean isJava5DeclarationLocation) {
jjg@74 2001 List<String> results = new ArrayList<String>();
jjg@1362 2002 StringBuilder annotation;
duke@1 2003 for (int i = 0; i < descList.length; i++) {
duke@1 2004 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
bpatel@1477 2005 // If an annotation is not documented, do not add it to the list. If
bpatel@1477 2006 // the annotation is of a repeatable type, and if it is not documented
bpatel@1477 2007 // and also if its container annotation is not documented, do not add it
bpatel@1477 2008 // to the list. If an annotation of a repeatable type is not documented
bpatel@1477 2009 // but its container is documented, it will be added to the list.
bpatel@1477 2010 if (! Util.isDocumentedAnnotation(annotationDoc) &&
bpatel@1477 2011 (!isAnnotationDocumented && !isContainerDocumented)) {
duke@1 2012 continue;
duke@1 2013 }
jjg@1521 2014 /* TODO: check logic here to correctly handle declaration
jjg@1521 2015 * and type annotations.
jjg@1521 2016 if (Util.isDeclarationAnnotation(annotationDoc, isJava5DeclarationLocation)) {
jjg@1521 2017 continue;
jjg@1521 2018 }*/
jjg@1362 2019 annotation = new StringBuilder();
bpatel@1477 2020 isAnnotationDocumented = false;
jjg@1410 2021 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
jjg@1735 2022 LinkInfoImpl.Kind.ANNOTATION, annotationDoc);
duke@1 2023 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
bpatel@1477 2024 // If the annotation is synthesized, do not print the container.
bpatel@1477 2025 if (descList[i].isSynthesized()) {
duke@1 2026 for (int j = 0; j < pairs.length; j++) {
duke@1 2027 AnnotationValue annotationValue = pairs[j].value();
jjg@74 2028 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
duke@1 2029 if (annotationValue.value() instanceof AnnotationValue[]) {
duke@1 2030 AnnotationValue[] annotationArray =
bpatel@1477 2031 (AnnotationValue[]) annotationValue.value();
bpatel@1477 2032 annotationTypeValues.addAll(Arrays.asList(annotationArray));
duke@1 2033 } else {
duke@1 2034 annotationTypeValues.add(annotationValue);
duke@1 2035 }
bpatel@1477 2036 String sep = "";
bpatel@1477 2037 for (AnnotationValue av : annotationTypeValues) {
bpatel@1477 2038 annotation.append(sep);
bpatel@1477 2039 annotation.append(annotationValueToString(av));
bpatel@1477 2040 sep = " ";
duke@1 2041 }
duke@1 2042 }
bpatel@1477 2043 }
bpatel@1477 2044 else if (isAnnotationArray(pairs)) {
bpatel@1477 2045 // If the container has 1 or more value defined and if the
bpatel@1477 2046 // repeatable type annotation is not documented, do not print
bpatel@1477 2047 // the container.
bpatel@1477 2048 if (pairs.length == 1 && isAnnotationDocumented) {
bpatel@1477 2049 AnnotationValue[] annotationArray =
bpatel@1477 2050 (AnnotationValue[]) (pairs[0].value()).value();
bpatel@1477 2051 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
bpatel@1477 2052 annotationTypeValues.addAll(Arrays.asList(annotationArray));
bpatel@1477 2053 String sep = "";
bpatel@1477 2054 for (AnnotationValue av : annotationTypeValues) {
bpatel@1477 2055 annotation.append(sep);
bpatel@1477 2056 annotation.append(annotationValueToString(av));
bpatel@1477 2057 sep = " ";
bpatel@1477 2058 }
bpatel@1477 2059 }
bpatel@1477 2060 // If the container has 1 or more value defined and if the
bpatel@1477 2061 // repeatable type annotation is not documented, print the container.
bpatel@1477 2062 else {
bpatel@1477 2063 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
bpatel@1477 2064 indent, false);
bpatel@1477 2065 }
bpatel@1477 2066 }
bpatel@1477 2067 else {
bpatel@1477 2068 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
bpatel@1477 2069 indent, linkBreak);
duke@1 2070 }
duke@1 2071 annotation.append(linkBreak ? DocletConstants.NL : "");
duke@1 2072 results.add(annotation.toString());
duke@1 2073 }
duke@1 2074 return results;
duke@1 2075 }
duke@1 2076
bpatel@1477 2077 /**
bpatel@1477 2078 * Add annotation to the annotation string.
bpatel@1477 2079 *
bpatel@1477 2080 * @param annotationDoc the annotation being documented
bpatel@1477 2081 * @param linkInfo the information about the link
bpatel@1477 2082 * @param annotation the annotation string to which the annotation will be added
bpatel@1477 2083 * @param pairs annotation type element and value pairs
bpatel@1477 2084 * @param indent the number of extra spaces to indent the annotations.
bpatel@1477 2085 * @param linkBreak if true, add new line between each member value
bpatel@1477 2086 */
bpatel@1477 2087 private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
bpatel@1477 2088 StringBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
bpatel@1477 2089 int indent, boolean linkBreak) {
jjg@1737 2090 linkInfo.label = new StringContent("@" + annotationDoc.name());
bpatel@1477 2091 annotation.append(getLink(linkInfo));
bpatel@1477 2092 if (pairs.length > 0) {
bpatel@1477 2093 annotation.append('(');
bpatel@1477 2094 for (int j = 0; j < pairs.length; j++) {
bpatel@1477 2095 if (j > 0) {
bpatel@1477 2096 annotation.append(",");
bpatel@1477 2097 if (linkBreak) {
bpatel@1477 2098 annotation.append(DocletConstants.NL);
bpatel@1477 2099 int spaces = annotationDoc.name().length() + 2;
bpatel@1477 2100 for (int k = 0; k < (spaces + indent); k++) {
bpatel@1477 2101 annotation.append(' ');
bpatel@1477 2102 }
bpatel@1477 2103 }
bpatel@1477 2104 }
jjg@1735 2105 annotation.append(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
bpatel@1477 2106 pairs[j].element(), pairs[j].element().name(), false));
bpatel@1477 2107 annotation.append('=');
bpatel@1477 2108 AnnotationValue annotationValue = pairs[j].value();
bpatel@1477 2109 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
bpatel@1477 2110 if (annotationValue.value() instanceof AnnotationValue[]) {
bpatel@1477 2111 AnnotationValue[] annotationArray =
bpatel@1477 2112 (AnnotationValue[]) annotationValue.value();
bpatel@1477 2113 annotationTypeValues.addAll(Arrays.asList(annotationArray));
bpatel@1477 2114 } else {
bpatel@1477 2115 annotationTypeValues.add(annotationValue);
bpatel@1477 2116 }
bpatel@1477 2117 annotation.append(annotationTypeValues.size() == 1 ? "" : "{");
bpatel@1477 2118 String sep = "";
bpatel@1477 2119 for (AnnotationValue av : annotationTypeValues) {
bpatel@1477 2120 annotation.append(sep);
bpatel@1477 2121 annotation.append(annotationValueToString(av));
bpatel@1477 2122 sep = ",";
bpatel@1477 2123 }
bpatel@1477 2124 annotation.append(annotationTypeValues.size() == 1 ? "" : "}");
bpatel@1477 2125 isContainerDocumented = false;
bpatel@1477 2126 }
bpatel@1477 2127 annotation.append(")");
bpatel@1477 2128 }
bpatel@1477 2129 }
bpatel@1477 2130
bpatel@1477 2131 /**
bpatel@1477 2132 * Check if the annotation contains an array of annotation as a value. This
bpatel@1477 2133 * check is to verify if a repeatable type annotation is present or not.
bpatel@1477 2134 *
bpatel@1477 2135 * @param pairs annotation type element and value pairs
bpatel@1477 2136 *
bpatel@1477 2137 * @return true if the annotation contains an array of annotation as a value.
bpatel@1477 2138 */
bpatel@1477 2139 private boolean isAnnotationArray(AnnotationDesc.ElementValuePair[] pairs) {
bpatel@1477 2140 AnnotationValue annotationValue;
bpatel@1477 2141 for (int j = 0; j < pairs.length; j++) {
bpatel@1477 2142 annotationValue = pairs[j].value();
bpatel@1477 2143 if (annotationValue.value() instanceof AnnotationValue[]) {
bpatel@1477 2144 AnnotationValue[] annotationArray =
bpatel@1477 2145 (AnnotationValue[]) annotationValue.value();
bpatel@1477 2146 if (annotationArray.length > 1) {
bpatel@1477 2147 if (annotationArray[0].value() instanceof AnnotationDesc) {
bpatel@1477 2148 AnnotationTypeDoc annotationDoc =
bpatel@1477 2149 ((AnnotationDesc) annotationArray[0].value()).annotationType();
bpatel@1477 2150 isContainerDocumented = true;
bpatel@1477 2151 if (Util.isDocumentedAnnotation(annotationDoc)) {
bpatel@1477 2152 isAnnotationDocumented = true;
bpatel@1477 2153 }
bpatel@1477 2154 return true;
bpatel@1477 2155 }
bpatel@1477 2156 }
bpatel@1477 2157 }
bpatel@1477 2158 }
bpatel@1477 2159 return false;
bpatel@1477 2160 }
bpatel@1477 2161
duke@1 2162 private String annotationValueToString(AnnotationValue annotationValue) {
duke@1 2163 if (annotationValue.value() instanceof Type) {
duke@1 2164 Type type = (Type) annotationValue.value();
duke@1 2165 if (type.asClassDoc() != null) {
jjg@1410 2166 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
jjg@1735 2167 LinkInfoImpl.Kind.ANNOTATION, type);
jjg@1737 2168 linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ?
jjg@1737 2169 type.typeName() :
jjg@1737 2170 type.qualifiedTypeName()) + type.dimension() + ".class");
jjg@1736 2171 return getLink(linkInfo).toString();
duke@1 2172 } else {
duke@1 2173 return type.typeName() + type.dimension() + ".class";
duke@1 2174 }
duke@1 2175 } else if (annotationValue.value() instanceof AnnotationDesc) {
mcimadamore@184 2176 List<String> list = getAnnotations(0,
duke@1 2177 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
duke@1 2178 false);
jjg@1362 2179 StringBuilder buf = new StringBuilder();
jjg@1362 2180 for (String s: list) {
jjg@1362 2181 buf.append(s);
duke@1 2182 }
duke@1 2183 return buf.toString();
duke@1 2184 } else if (annotationValue.value() instanceof MemberDoc) {
jjg@1735 2185 return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
duke@1 2186 (MemberDoc) annotationValue.value(),
jjg@1736 2187 ((MemberDoc) annotationValue.value()).name(), false).toString();
duke@1 2188 } else {
duke@1 2189 return annotationValue.toString();
duke@1 2190 }
duke@1 2191 }
duke@1 2192
duke@1 2193 /**
duke@1 2194 * Return the configuation for this doclet.
duke@1 2195 *
duke@1 2196 * @return the configuration for this doclet.
duke@1 2197 */
duke@1 2198 public Configuration configuration() {
duke@1 2199 return configuration;
duke@1 2200 }
duke@1 2201 }

mercurial