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

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

author
jjg
date
Tue, 14 May 2013 10:14:54 -0700
changeset 1743
6a5288a298fd
parent 1741
4c43e51433ba
child 1744
76a691e3e961
permissions
-rw-r--r--

8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy

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

mercurial