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

Thu, 10 Oct 2013 10:51:15 -0700

author
bpatel
date
Thu, 10 Oct 2013 10:51:15 -0700
changeset 2101
933ba3f81a87
parent 2084
6e186ca11ec0
child 2147
130b8c0e570e
permissions
-rw-r--r--

8025633: Fix javadoc to generate valid anchor names
Reviewed-by: jjg

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

mercurial