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

Tue, 17 Dec 2013 10:55:59 +0100

author
jlahoda
date
Tue, 17 Dec 2013 10:55:59 +0100
changeset 2413
fe033d997ddf
parent 2218
2d0a0ae7fa9c
child 2415
7ceaee0e497b
permissions
-rw-r--r--

8029800: Flags.java uses String.toLowerCase without specifying Locale
Summary: Introducing StringUtils.toLowerCase/toUpperCase independent on the default locale, converting almost all usages of String.toLowerCase/toUpperCase to use the new methods.
Reviewed-by: jjg, bpatel

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

mercurial