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

Wed, 23 Oct 2013 13:54:13 -0700

author
bpatel
date
Wed, 23 Oct 2013 13:54:13 -0700
changeset 2163
8746caa5cf80
parent 2147
130b8c0e570e
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8026770: javadoc creates invalid HTML in profile summary pages
Reviewed-by: jjg

bpatel@1568 1 /*
bpatel@1568 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
bpatel@1568 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bpatel@1568 4 *
bpatel@1568 5 * This code is free software; you can redistribute it and/or modify it
bpatel@1568 6 * under the terms of the GNU General Public License version 2 only, as
bpatel@1568 7 * published by the Free Software Foundation. Oracle designates this
bpatel@1568 8 * particular file as subject to the "Classpath" exception as provided
bpatel@1568 9 * by Oracle in the LICENSE file that accompanied this code.
bpatel@1568 10 *
bpatel@1568 11 * This code is distributed in the hope that it will be useful, but WITHOUT
bpatel@1568 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bpatel@1568 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bpatel@1568 14 * version 2 for more details (a copy is included in the LICENSE file that
bpatel@1568 15 * accompanied this code).
bpatel@1568 16 *
bpatel@1568 17 * You should have received a copy of the GNU General Public License version
bpatel@1568 18 * 2 along with this work; if not, write to the Free Software Foundation,
bpatel@1568 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bpatel@1568 20 *
bpatel@1568 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bpatel@1568 22 * or visit www.oracle.com if you need additional information or have any
bpatel@1568 23 * questions.
bpatel@1568 24 */
bpatel@1568 25
bpatel@1568 26 package com.sun.tools.doclets.formats.html;
bpatel@1568 27
bpatel@1568 28 import java.io.*;
bpatel@1568 29 import java.util.*;
bpatel@1568 30
bpatel@1568 31 import com.sun.javadoc.*;
bpatel@1568 32 import com.sun.tools.javac.jvm.Profile;
bpatel@1568 33 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@1568 34 import com.sun.tools.doclets.internal.toolkit.*;
bpatel@1568 35 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@1568 36
bpatel@1568 37 /**
bpatel@1568 38 * Class to generate file for each profile package contents in the right-hand
bpatel@1568 39 * frame. This will list all the Class Kinds in the package. A click on any
bpatel@1568 40 * class-kind will update the frame with the clicked class-kind page.
bpatel@1568 41 *
bpatel@1568 42 * <p><b>This is NOT part of any supported API.
bpatel@1568 43 * If you write code that depends on this, you do so at your own risk.
bpatel@1568 44 * This code and its internal interfaces are subject to change or
bpatel@1568 45 * deletion without notice.</b>
bpatel@1568 46 *
bpatel@1568 47 * @author Bhavesh Patel
bpatel@1568 48 */
bpatel@1568 49 public class ProfilePackageWriterImpl extends HtmlDocletWriter
bpatel@1568 50 implements ProfilePackageSummaryWriter {
bpatel@1568 51
bpatel@1568 52 /**
bpatel@1568 53 * The prev package name in the alpha-order list.
bpatel@1568 54 */
bpatel@1568 55 protected PackageDoc prev;
bpatel@1568 56
bpatel@1568 57 /**
bpatel@1568 58 * The next package name in the alpha-order list.
bpatel@1568 59 */
bpatel@1568 60 protected PackageDoc next;
bpatel@1568 61
bpatel@1568 62 /**
bpatel@1568 63 * The profile package being documented.
bpatel@1568 64 */
bpatel@1568 65 protected PackageDoc packageDoc;
bpatel@1568 66
bpatel@1568 67 /**
bpatel@1568 68 * The name of the profile being documented.
bpatel@1568 69 */
bpatel@1568 70 protected String profileName;
bpatel@1568 71
bpatel@1568 72 /**
bpatel@1568 73 * The value of the profile being documented.
bpatel@1568 74 */
bpatel@1568 75 protected int profileValue;
bpatel@1568 76
bpatel@1568 77 /**
bpatel@1568 78 * Constructor to construct ProfilePackageWriter object and to generate
bpatel@1568 79 * "profilename-package-summary.html" file in the respective package directory.
bpatel@1568 80 * For example for profile compact1 and package "java.lang" this will generate file
bpatel@1568 81 * "compact1-package-summary.html" file in the "java/lang" directory. It will also
bpatel@1568 82 * create "java/lang" directory in the current or the destination directory
bpatel@1568 83 * if it doesn't exist.
bpatel@1568 84 *
bpatel@1568 85 * @param configuration the configuration of the doclet.
bpatel@1568 86 * @param packageDoc PackageDoc under consideration.
bpatel@1568 87 * @param prev Previous package in the sorted array.
bpatel@1568 88 * @param next Next package in the sorted array.
bpatel@1568 89 * @param profile The profile being documented.
bpatel@1568 90 */
bpatel@1568 91 public ProfilePackageWriterImpl(ConfigurationImpl configuration,
bpatel@1568 92 PackageDoc packageDoc, PackageDoc prev, PackageDoc next,
bpatel@1568 93 Profile profile) throws IOException {
bpatel@1568 94 super(configuration, DocPath.forPackage(packageDoc).resolve(
bpatel@1568 95 DocPaths.profilePackageSummary(profile.name)));
bpatel@1568 96 this.prev = prev;
bpatel@1568 97 this.next = next;
bpatel@1568 98 this.packageDoc = packageDoc;
bpatel@1568 99 this.profileName = profile.name;
bpatel@1568 100 this.profileValue = profile.value;
bpatel@1568 101 }
bpatel@1568 102
bpatel@1568 103 /**
bpatel@1568 104 * {@inheritDoc}
bpatel@1568 105 */
bpatel@1568 106 public Content getPackageHeader(String heading) {
bpatel@1568 107 String pkgName = packageDoc.name();
bpatel@1568 108 Content bodyTree = getBody(true, getWindowTitle(pkgName));
bpatel@1568 109 addTop(bodyTree);
bpatel@1568 110 addNavLinks(true, bodyTree);
bpatel@1568 111 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@1568 112 div.addStyle(HtmlStyle.header);
bpatel@1568 113 Content profileContent = new StringContent(profileName);
bpatel@1568 114 Content profileNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, profileContent);
bpatel@1568 115 div.addContent(profileNameDiv);
bpatel@1568 116 Content annotationContent = new HtmlTree(HtmlTag.P);
bpatel@1568 117 addAnnotationInfo(packageDoc, annotationContent);
bpatel@1568 118 div.addContent(annotationContent);
bpatel@1568 119 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
bpatel@1568 120 HtmlStyle.title, packageLabel);
bpatel@1568 121 tHeading.addContent(getSpace());
bpatel@1568 122 Content packageHead = new RawHtml(heading);
bpatel@1568 123 tHeading.addContent(packageHead);
bpatel@1568 124 div.addContent(tHeading);
bpatel@1568 125 addDeprecationInfo(div);
bpatel@1568 126 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
bpatel@1568 127 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
bpatel@1568 128 docSummaryDiv.addStyle(HtmlStyle.docSummary);
bpatel@1568 129 addSummaryComment(packageDoc, docSummaryDiv);
bpatel@1568 130 div.addContent(docSummaryDiv);
bpatel@1568 131 Content space = getSpace();
bpatel@2101 132 Content descLink = getHyperLink(getDocLink(
bpatel@2101 133 SectionName.PACKAGE_DESCRIPTION),
bpatel@1568 134 descriptionLabel, "", "");
bpatel@1568 135 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
bpatel@1568 136 div.addContent(descPara);
bpatel@1568 137 }
bpatel@1568 138 bodyTree.addContent(div);
bpatel@1568 139 return bodyTree;
bpatel@1568 140 }
bpatel@1568 141
bpatel@1568 142 /**
bpatel@1568 143 * {@inheritDoc}
bpatel@1568 144 */
bpatel@1568 145 public Content getContentHeader() {
bpatel@1568 146 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@1568 147 div.addStyle(HtmlStyle.contentContainer);
bpatel@1568 148 return div;
bpatel@1568 149 }
bpatel@1568 150
bpatel@1568 151 /**
bpatel@1568 152 * Add the package deprecation information to the documentation tree.
bpatel@1568 153 *
bpatel@1568 154 * @param div the content tree to which the deprecation information will be added
bpatel@1568 155 */
bpatel@1568 156 public void addDeprecationInfo(Content div) {
bpatel@1568 157 Tag[] deprs = packageDoc.tags("deprecated");
bpatel@1568 158 if (Util.isDeprecated(packageDoc)) {
bpatel@1568 159 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
bpatel@1568 160 deprDiv.addStyle(HtmlStyle.deprecatedContent);
bpatel@2147 161 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
bpatel@1568 162 deprDiv.addContent(deprPhrase);
bpatel@1568 163 if (deprs.length > 0) {
bpatel@1568 164 Tag[] commentTags = deprs[0].inlineTags();
bpatel@1568 165 if (commentTags.length > 0) {
bpatel@1568 166 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
bpatel@1568 167 }
bpatel@1568 168 }
bpatel@1568 169 div.addContent(deprDiv);
bpatel@1568 170 }
bpatel@1568 171 }
bpatel@1568 172
bpatel@1568 173 /**
bpatel@1568 174 * {@inheritDoc}
bpatel@1568 175 */
bpatel@1568 176 public void addClassesSummary(ClassDoc[] classes, String label,
bpatel@1568 177 String tableSummary, String[] tableHeader, Content packageSummaryContentTree) {
bpatel@2163 178 HtmlTree li = new HtmlTree(HtmlTag.LI);
bpatel@2163 179 li.addStyle(HtmlStyle.blockList);
bpatel@1568 180 addClassesSummary(classes, label, tableSummary, tableHeader,
bpatel@2163 181 li, profileValue);
bpatel@2163 182 packageSummaryContentTree.addContent(li);
bpatel@1568 183 }
bpatel@1568 184
bpatel@1568 185 /**
bpatel@1568 186 * {@inheritDoc}
bpatel@1568 187 */
bpatel@1568 188 public Content getSummaryHeader() {
bpatel@1568 189 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@1568 190 ul.addStyle(HtmlStyle.blockList);
bpatel@1568 191 return ul;
bpatel@1568 192 }
bpatel@1568 193
bpatel@1568 194 /**
bpatel@1568 195 * {@inheritDoc}
bpatel@1568 196 */
bpatel@1568 197 public void addPackageDescription(Content packageContentTree) {
bpatel@1568 198 if (packageDoc.inlineTags().length > 0) {
bpatel@2101 199 packageContentTree.addContent(
bpatel@2101 200 getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
bpatel@1568 201 Content h2Content = new StringContent(
bpatel@1568 202 configuration.getText("doclet.Package_Description",
bpatel@1568 203 packageDoc.name()));
bpatel@1568 204 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
bpatel@1568 205 true, h2Content));
bpatel@1568 206 addInlineComment(packageDoc, packageContentTree);
bpatel@1568 207 }
bpatel@1568 208 }
bpatel@1568 209
bpatel@1568 210 /**
bpatel@1568 211 * {@inheritDoc}
bpatel@1568 212 */
bpatel@1568 213 public void addPackageTags(Content packageContentTree) {
bpatel@1568 214 addTagsInfo(packageDoc, packageContentTree);
bpatel@1568 215 }
bpatel@1568 216
bpatel@1568 217 /**
bpatel@1568 218 * {@inheritDoc}
bpatel@1568 219 */
bpatel@1568 220 public void addPackageFooter(Content contentTree) {
bpatel@1568 221 addNavLinks(false, contentTree);
bpatel@1568 222 addBottom(contentTree);
bpatel@1568 223 }
bpatel@1568 224
bpatel@1568 225 /**
bpatel@1568 226 * {@inheritDoc}
bpatel@1568 227 */
bpatel@1568 228 public void printDocument(Content contentTree) throws IOException {
bpatel@1568 229 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
bpatel@1568 230 true, contentTree);
bpatel@1568 231 }
bpatel@1568 232
bpatel@1568 233 /**
bpatel@1568 234 * Get "Use" link for this package in the navigation bar.
bpatel@1568 235 *
bpatel@1568 236 * @return a content tree for the class use link
bpatel@1568 237 */
bpatel@1568 238 protected Content getNavLinkClassUse() {
bpatel@1568 239 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
bpatel@1568 240 useLabel, "", "");
bpatel@1568 241 Content li = HtmlTree.LI(useLink);
bpatel@1568 242 return li;
bpatel@1568 243 }
bpatel@1568 244
bpatel@1568 245 /**
bpatel@1568 246 * Get "PREV PACKAGE" link in the navigation bar.
bpatel@1568 247 *
bpatel@1568 248 * @return a content tree for the previous link
bpatel@1568 249 */
bpatel@1568 250 public Content getNavLinkPrevious() {
bpatel@1568 251 Content li;
bpatel@1568 252 if (prev == null) {
bpatel@1568 253 li = HtmlTree.LI(prevpackageLabel);
bpatel@1568 254 } else {
bpatel@1568 255 DocPath path = DocPath.relativePath(packageDoc, prev);
bpatel@1568 256 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.profilePackageSummary(profileName)),
bpatel@1568 257 prevpackageLabel, "", ""));
bpatel@1568 258 }
bpatel@1568 259 return li;
bpatel@1568 260 }
bpatel@1568 261
bpatel@1568 262 /**
bpatel@1568 263 * Get "NEXT PACKAGE" link in the navigation bar.
bpatel@1568 264 *
bpatel@1568 265 * @return a content tree for the next link
bpatel@1568 266 */
bpatel@1568 267 public Content getNavLinkNext() {
bpatel@1568 268 Content li;
bpatel@1568 269 if (next == null) {
bpatel@1568 270 li = HtmlTree.LI(nextpackageLabel);
bpatel@1568 271 } else {
bpatel@1568 272 DocPath path = DocPath.relativePath(packageDoc, next);
bpatel@1568 273 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.profilePackageSummary(profileName)),
bpatel@1568 274 nextpackageLabel, "", ""));
bpatel@1568 275 }
bpatel@1568 276 return li;
bpatel@1568 277 }
bpatel@1568 278
bpatel@1568 279 /**
bpatel@1568 280 * Get "Tree" link in the navigation bar. This will be link to the package
bpatel@1568 281 * tree file.
bpatel@1568 282 *
bpatel@1568 283 * @return a content tree for the tree link
bpatel@1568 284 */
bpatel@1568 285 protected Content getNavLinkTree() {
bpatel@1568 286 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
bpatel@1568 287 treeLabel, "", "");
bpatel@1568 288 Content li = HtmlTree.LI(useLink);
bpatel@1568 289 return li;
bpatel@1568 290 }
bpatel@1568 291
bpatel@1568 292 /**
bpatel@1568 293 * Highlight "Package" in the navigation bar, as this is the package page.
bpatel@1568 294 *
bpatel@1568 295 * @return a content tree for the package link
bpatel@1568 296 */
bpatel@1568 297 protected Content getNavLinkPackage() {
bpatel@1568 298 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
bpatel@1568 299 return li;
bpatel@1568 300 }
bpatel@1568 301 }

mercurial