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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,317 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.formats.html;
    1.30 +
    1.31 +import java.io.*;
    1.32 +import java.util.*;
    1.33 +
    1.34 +import com.sun.javadoc.*;
    1.35 +import com.sun.tools.doclets.formats.html.markup.*;
    1.36 +import com.sun.tools.doclets.internal.toolkit.*;
    1.37 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.38 +
    1.39 +/**
    1.40 + * Class to generate file for each package contents in the right-hand
    1.41 + * frame. This will list all the Class Kinds in the package. A click on any
    1.42 + * class-kind will update the frame with the clicked class-kind page.
    1.43 + *
    1.44 + *  <p><b>This is NOT part of any supported API.
    1.45 + *  If you write code that depends on this, you do so at your own risk.
    1.46 + *  This code and its internal interfaces are subject to change or
    1.47 + *  deletion without notice.</b>
    1.48 + *
    1.49 + * @author Atul M Dambalkar
    1.50 + * @author Bhavesh Patel (Modified)
    1.51 + */
    1.52 +public class PackageWriterImpl extends HtmlDocletWriter
    1.53 +    implements PackageSummaryWriter {
    1.54 +
    1.55 +    /**
    1.56 +     * The prev package name in the alpha-order list.
    1.57 +     */
    1.58 +    protected PackageDoc prev;
    1.59 +
    1.60 +    /**
    1.61 +     * The next package name in the alpha-order list.
    1.62 +     */
    1.63 +    protected PackageDoc next;
    1.64 +
    1.65 +    /**
    1.66 +     * The package being documented.
    1.67 +     */
    1.68 +    protected PackageDoc packageDoc;
    1.69 +
    1.70 +    /**
    1.71 +     * Constructor to construct PackageWriter object and to generate
    1.72 +     * "package-summary.html" file in the respective package directory.
    1.73 +     * For example for package "java.lang" this will generate file
    1.74 +     * "package-summary.html" file in the "java/lang" directory. It will also
    1.75 +     * create "java/lang" directory in the current or the destination directory
    1.76 +     * if it doesn't exist.
    1.77 +     *
    1.78 +     * @param configuration the configuration of the doclet.
    1.79 +     * @param packageDoc    PackageDoc under consideration.
    1.80 +     * @param prev          Previous package in the sorted array.
    1.81 +     * @param next            Next package in the sorted array.
    1.82 +     */
    1.83 +    public PackageWriterImpl(ConfigurationImpl configuration,
    1.84 +            PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
    1.85 +            throws IOException {
    1.86 +        super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY));
    1.87 +        this.prev = prev;
    1.88 +        this.next = next;
    1.89 +        this.packageDoc = packageDoc;
    1.90 +    }
    1.91 +
    1.92 +    /**
    1.93 +     * {@inheritDoc}
    1.94 +     */
    1.95 +    public Content getPackageHeader(String heading) {
    1.96 +        String pkgName = packageDoc.name();
    1.97 +        Content bodyTree = getBody(true, getWindowTitle(pkgName));
    1.98 +        addTop(bodyTree);
    1.99 +        addNavLinks(true, bodyTree);
   1.100 +        HtmlTree div = new HtmlTree(HtmlTag.DIV);
   1.101 +        div.addStyle(HtmlStyle.header);
   1.102 +        Content annotationContent = new HtmlTree(HtmlTag.P);
   1.103 +        addAnnotationInfo(packageDoc, annotationContent);
   1.104 +        div.addContent(annotationContent);
   1.105 +        Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
   1.106 +                HtmlStyle.title, packageLabel);
   1.107 +        tHeading.addContent(getSpace());
   1.108 +        Content packageHead = new StringContent(heading);
   1.109 +        tHeading.addContent(packageHead);
   1.110 +        div.addContent(tHeading);
   1.111 +        addDeprecationInfo(div);
   1.112 +        if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
   1.113 +            HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
   1.114 +            docSummaryDiv.addStyle(HtmlStyle.docSummary);
   1.115 +            addSummaryComment(packageDoc, docSummaryDiv);
   1.116 +            div.addContent(docSummaryDiv);
   1.117 +            Content space = getSpace();
   1.118 +            Content descLink = getHyperLink(getDocLink(
   1.119 +                    SectionName.PACKAGE_DESCRIPTION),
   1.120 +                    descriptionLabel, "", "");
   1.121 +            Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
   1.122 +            div.addContent(descPara);
   1.123 +        }
   1.124 +        bodyTree.addContent(div);
   1.125 +        return bodyTree;
   1.126 +    }
   1.127 +
   1.128 +    /**
   1.129 +     * {@inheritDoc}
   1.130 +     */
   1.131 +    public Content getContentHeader() {
   1.132 +        HtmlTree div = new HtmlTree(HtmlTag.DIV);
   1.133 +        div.addStyle(HtmlStyle.contentContainer);
   1.134 +        return div;
   1.135 +    }
   1.136 +
   1.137 +    /**
   1.138 +     * Add the package deprecation information to the documentation tree.
   1.139 +     *
   1.140 +     * @param div the content tree to which the deprecation information will be added
   1.141 +     */
   1.142 +    public void addDeprecationInfo(Content div) {
   1.143 +        Tag[] deprs = packageDoc.tags("deprecated");
   1.144 +        if (Util.isDeprecated(packageDoc)) {
   1.145 +            HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
   1.146 +            deprDiv.addStyle(HtmlStyle.deprecatedContent);
   1.147 +            Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
   1.148 +            deprDiv.addContent(deprPhrase);
   1.149 +            if (deprs.length > 0) {
   1.150 +                Tag[] commentTags = deprs[0].inlineTags();
   1.151 +                if (commentTags.length > 0) {
   1.152 +                    addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
   1.153 +                }
   1.154 +            }
   1.155 +            div.addContent(deprDiv);
   1.156 +        }
   1.157 +    }
   1.158 +
   1.159 +    /**
   1.160 +     * {@inheritDoc}
   1.161 +     */
   1.162 +    public Content getSummaryHeader() {
   1.163 +        HtmlTree ul = new HtmlTree(HtmlTag.UL);
   1.164 +        ul.addStyle(HtmlStyle.blockList);
   1.165 +        return ul;
   1.166 +    }
   1.167 +
   1.168 +    /**
   1.169 +     * {@inheritDoc}
   1.170 +     */
   1.171 +    public void addClassesSummary(ClassDoc[] classes, String label,
   1.172 +            String tableSummary, String[] tableHeader, Content summaryContentTree) {
   1.173 +        if(classes.length > 0) {
   1.174 +            Arrays.sort(classes);
   1.175 +            Content caption = getTableCaption(new RawHtml(label));
   1.176 +            Content table = HtmlTree.TABLE(HtmlStyle.typeSummary, 0, 3, 0,
   1.177 +                    tableSummary, caption);
   1.178 +            table.addContent(getSummaryTableHeader(tableHeader, "col"));
   1.179 +            Content tbody = new HtmlTree(HtmlTag.TBODY);
   1.180 +            for (int i = 0; i < classes.length; i++) {
   1.181 +                if (!Util.isCoreClass(classes[i]) ||
   1.182 +                    !configuration.isGeneratedDoc(classes[i])) {
   1.183 +                    continue;
   1.184 +                }
   1.185 +                Content classContent = getLink(new LinkInfoImpl(
   1.186 +                        configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
   1.187 +                Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
   1.188 +                HtmlTree tr = HtmlTree.TR(tdClass);
   1.189 +                if (i%2 == 0)
   1.190 +                    tr.addStyle(HtmlStyle.altColor);
   1.191 +                else
   1.192 +                    tr.addStyle(HtmlStyle.rowColor);
   1.193 +                HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
   1.194 +                tdClassDescription.addStyle(HtmlStyle.colLast);
   1.195 +                if (Util.isDeprecated(classes[i])) {
   1.196 +                    tdClassDescription.addContent(deprecatedLabel);
   1.197 +                    if (classes[i].tags("deprecated").length > 0) {
   1.198 +                        addSummaryDeprecatedComment(classes[i],
   1.199 +                            classes[i].tags("deprecated")[0], tdClassDescription);
   1.200 +                    }
   1.201 +                }
   1.202 +                else
   1.203 +                    addSummaryComment(classes[i], tdClassDescription);
   1.204 +                tr.addContent(tdClassDescription);
   1.205 +                tbody.addContent(tr);
   1.206 +            }
   1.207 +            table.addContent(tbody);
   1.208 +            Content li = HtmlTree.LI(HtmlStyle.blockList, table);
   1.209 +            summaryContentTree.addContent(li);
   1.210 +        }
   1.211 +    }
   1.212 +
   1.213 +    /**
   1.214 +     * {@inheritDoc}
   1.215 +     */
   1.216 +    public void addPackageDescription(Content packageContentTree) {
   1.217 +        if (packageDoc.inlineTags().length > 0) {
   1.218 +            packageContentTree.addContent(
   1.219 +                    getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
   1.220 +            Content h2Content = new StringContent(
   1.221 +                    configuration.getText("doclet.Package_Description",
   1.222 +                    packageDoc.name()));
   1.223 +            packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
   1.224 +                    true, h2Content));
   1.225 +            addInlineComment(packageDoc, packageContentTree);
   1.226 +        }
   1.227 +    }
   1.228 +
   1.229 +    /**
   1.230 +     * {@inheritDoc}
   1.231 +     */
   1.232 +    public void addPackageTags(Content packageContentTree) {
   1.233 +        addTagsInfo(packageDoc, packageContentTree);
   1.234 +    }
   1.235 +
   1.236 +    /**
   1.237 +     * {@inheritDoc}
   1.238 +     */
   1.239 +    public void addPackageFooter(Content contentTree) {
   1.240 +        addNavLinks(false, contentTree);
   1.241 +        addBottom(contentTree);
   1.242 +    }
   1.243 +
   1.244 +    /**
   1.245 +     * {@inheritDoc}
   1.246 +     */
   1.247 +    public void printDocument(Content contentTree) throws IOException {
   1.248 +        printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
   1.249 +                true, contentTree);
   1.250 +    }
   1.251 +
   1.252 +    /**
   1.253 +     * Get "Use" link for this pacakge in the navigation bar.
   1.254 +     *
   1.255 +     * @return a content tree for the class use link
   1.256 +     */
   1.257 +    protected Content getNavLinkClassUse() {
   1.258 +        Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
   1.259 +                useLabel, "", "");
   1.260 +        Content li = HtmlTree.LI(useLink);
   1.261 +        return li;
   1.262 +    }
   1.263 +
   1.264 +    /**
   1.265 +     * Get "PREV PACKAGE" link in the navigation bar.
   1.266 +     *
   1.267 +     * @return a content tree for the previous link
   1.268 +     */
   1.269 +    public Content getNavLinkPrevious() {
   1.270 +        Content li;
   1.271 +        if (prev == null) {
   1.272 +            li = HtmlTree.LI(prevpackageLabel);
   1.273 +        } else {
   1.274 +            DocPath path = DocPath.relativePath(packageDoc, prev);
   1.275 +            li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
   1.276 +                prevpackageLabel, "", ""));
   1.277 +        }
   1.278 +        return li;
   1.279 +    }
   1.280 +
   1.281 +    /**
   1.282 +     * Get "NEXT PACKAGE" link in the navigation bar.
   1.283 +     *
   1.284 +     * @return a content tree for the next link
   1.285 +     */
   1.286 +    public Content getNavLinkNext() {
   1.287 +        Content li;
   1.288 +        if (next == null) {
   1.289 +            li = HtmlTree.LI(nextpackageLabel);
   1.290 +        } else {
   1.291 +            DocPath path = DocPath.relativePath(packageDoc, next);
   1.292 +            li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
   1.293 +                nextpackageLabel, "", ""));
   1.294 +        }
   1.295 +        return li;
   1.296 +    }
   1.297 +
   1.298 +    /**
   1.299 +     * Get "Tree" link in the navigation bar. This will be link to the package
   1.300 +     * tree file.
   1.301 +     *
   1.302 +     * @return a content tree for the tree link
   1.303 +     */
   1.304 +    protected Content getNavLinkTree() {
   1.305 +        Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
   1.306 +                treeLabel, "", "");
   1.307 +        Content li = HtmlTree.LI(useLink);
   1.308 +        return li;
   1.309 +    }
   1.310 +
   1.311 +    /**
   1.312 +     * Highlight "Package" in the navigation bar, as this is the package page.
   1.313 +     *
   1.314 +     * @return a content tree for the package link
   1.315 +     */
   1.316 +    protected Content getNavLinkPackage() {
   1.317 +        Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
   1.318 +        return li;
   1.319 +    }
   1.320 +}

mercurial