langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java
changeset 36526 3b41f1c69604
parent 36525 4caf88912b7f
child 36527 e2de042a3820
equal deleted inserted replaced
36525:4caf88912b7f 36526:3b41f1c69604
     1 /*
       
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.tools.doclets.formats.html;
       
    27 
       
    28 import java.io.*;
       
    29 import java.util.*;
       
    30 
       
    31 import com.sun.javadoc.*;
       
    32 import com.sun.tools.javac.jvm.Profile;
       
    33 import com.sun.tools.doclets.formats.html.markup.*;
       
    34 import com.sun.tools.doclets.internal.toolkit.*;
       
    35 import com.sun.tools.doclets.internal.toolkit.util.*;
       
    36 
       
    37 /**
       
    38  * Class to generate file for each package contents of a profile in the left-hand bottom
       
    39  * frame. This will list all the Class Kinds in the package for a profile. A click on any
       
    40  * class-kind will update the right-hand frame with the clicked class-kind page.
       
    41  *
       
    42  *  <p><b>This is NOT part of any supported API.
       
    43  *  If you write code that depends on this, you do so at your own risk.
       
    44  *  This code and its internal interfaces are subject to change or
       
    45  *  deletion without notice.</b>
       
    46  *
       
    47  * @author Bhavesh Patel
       
    48  */
       
    49 public class ProfilePackageFrameWriter extends HtmlDocletWriter {
       
    50 
       
    51     /**
       
    52      * The package being documented.
       
    53      */
       
    54     private PackageDoc packageDoc;
       
    55 
       
    56     /**
       
    57      * Constructor to construct ProfilePackageFrameWriter object and to generate
       
    58      * "profilename-package-frame.html" file in the respective package directory.
       
    59      * For example for profile compact1 and package "java.lang" this will generate file
       
    60      * "compact1-package-frame.html" file in the "java/lang" directory. It will also
       
    61      * create "java/lang" directory in the current or the destination directory
       
    62      * if it doesn't exist.
       
    63      *
       
    64      * @param configuration the configuration of the doclet.
       
    65      * @param packageDoc PackageDoc under consideration.
       
    66      * @param profileName the name of the profile being documented
       
    67      */
       
    68     public ProfilePackageFrameWriter(ConfigurationImpl configuration,
       
    69             PackageDoc packageDoc, String profileName)
       
    70             throws IOException {
       
    71         super(configuration, DocPath.forPackage(packageDoc).resolve(
       
    72                 DocPaths.profilePackageFrame(profileName)));
       
    73         this.packageDoc = packageDoc;
       
    74     }
       
    75 
       
    76     /**
       
    77      * Generate a profile package summary page for the left-hand bottom frame. Construct
       
    78      * the ProfilePackageFrameWriter object and then uses it generate the file.
       
    79      *
       
    80      * @param configuration the current configuration of the doclet.
       
    81      * @param packageDoc The package for which "profilename-package-frame.html" is to be generated.
       
    82      * @param profileValue the value of the profile being documented
       
    83      */
       
    84     public static void generate(ConfigurationImpl configuration,
       
    85             PackageDoc packageDoc, int profileValue) {
       
    86         ProfilePackageFrameWriter profpackgen;
       
    87         try {
       
    88             String profileName = Profile.lookup(profileValue).name;
       
    89             profpackgen = new ProfilePackageFrameWriter(configuration, packageDoc,
       
    90                     profileName);
       
    91             StringBuilder winTitle = new StringBuilder(profileName);
       
    92             String sep = " - ";
       
    93             winTitle.append(sep);
       
    94             String pkgName = configuration.utils.getPackageName(packageDoc);
       
    95             winTitle.append(pkgName);
       
    96             HtmlTree body = profpackgen.getBody(false,
       
    97                     profpackgen.getWindowTitle(winTitle.toString()));
       
    98             Content profName = new StringContent(profileName);
       
    99             Content sepContent = new StringContent(sep);
       
   100             Content pkgNameContent = new RawHtml(pkgName);
       
   101             HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
       
   102                     ? HtmlTree.MAIN()
       
   103                     : body;
       
   104             Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
       
   105                     profpackgen.getTargetProfileLink("classFrame", profName, profileName));
       
   106             heading.addContent(sepContent);
       
   107             heading.addContent(profpackgen.getTargetProfilePackageLink(packageDoc,
       
   108                     "classFrame", pkgNameContent, profileName));
       
   109             htmlTree.addContent(heading);
       
   110             HtmlTree div = new HtmlTree(HtmlTag.DIV);
       
   111             div.addStyle(HtmlStyle.indexContainer);
       
   112             profpackgen.addClassListing(div, profileValue);
       
   113             htmlTree.addContent(div);
       
   114             if (configuration.allowTag(HtmlTag.MAIN)) {
       
   115                 body.addContent(htmlTree);
       
   116             }
       
   117             profpackgen.printHtmlDocument(
       
   118                     configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
       
   119             profpackgen.close();
       
   120         } catch (IOException exc) {
       
   121             configuration.standardmessage.error(
       
   122                     "doclet.exception_encountered",
       
   123                     exc.toString(), DocPaths.PACKAGE_FRAME.getPath());
       
   124             throw new DocletAbortException(exc);
       
   125         }
       
   126     }
       
   127 
       
   128     /**
       
   129      * Add class listing for all the classes in this package. Divide class
       
   130      * listing as per the class kind and generate separate listing for
       
   131      * Classes, Interfaces, Exceptions and Errors.
       
   132      *
       
   133      * @param contentTree the content tree to which the listing will be added
       
   134      * @param profileValue the value of the profile being documented
       
   135      */
       
   136     protected void addClassListing(HtmlTree contentTree, int profileValue) {
       
   137         if (packageDoc.isIncluded()) {
       
   138             addClassKindListing(packageDoc.interfaces(),
       
   139                 getResource("doclet.Interfaces"), contentTree, profileValue);
       
   140             addClassKindListing(packageDoc.ordinaryClasses(),
       
   141                 getResource("doclet.Classes"), contentTree, profileValue);
       
   142             addClassKindListing(packageDoc.enums(),
       
   143                 getResource("doclet.Enums"), contentTree, profileValue);
       
   144             addClassKindListing(packageDoc.exceptions(),
       
   145                 getResource("doclet.Exceptions"), contentTree, profileValue);
       
   146             addClassKindListing(packageDoc.errors(),
       
   147                 getResource("doclet.Errors"), contentTree, profileValue);
       
   148             addClassKindListing(packageDoc.annotationTypes(),
       
   149                 getResource("doclet.AnnotationTypes"), contentTree, profileValue);
       
   150         }
       
   151     }
       
   152 
       
   153     /**
       
   154      * Add specific class kind listing. Also add label to the listing.
       
   155      *
       
   156      * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
       
   157      * @param labelContent content tree of the label to be added
       
   158      * @param contentTree the content tree to which the class kind listing will be added
       
   159      * @param profileValue the value of the profile being documented
       
   160      */
       
   161     protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
       
   162             HtmlTree contentTree, int profileValue) {
       
   163         if(arr.length > 0) {
       
   164             Arrays.sort(arr);
       
   165             boolean printedHeader = false;
       
   166             HtmlTree htmlTree = (configuration.allowTag(HtmlTag.SECTION))
       
   167                     ? HtmlTree.SECTION()
       
   168                     : contentTree;
       
   169             HtmlTree ul = new HtmlTree(HtmlTag.UL);
       
   170             ul.setTitle(labelContent);
       
   171             for (ClassDoc classDoc : arr) {
       
   172                 if (!isTypeInProfile(classDoc, profileValue)) {
       
   173                     continue;
       
   174                 }
       
   175                 if (!utils.isCoreClass(classDoc) || !
       
   176                         configuration.isGeneratedDoc(classDoc)) {
       
   177                     continue;
       
   178                 }
       
   179                 if (!printedHeader) {
       
   180                     Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
       
   181                                                        true, labelContent);
       
   182                     htmlTree.addContent(heading);
       
   183                     printedHeader = true;
       
   184                 }
       
   185                 Content arr_i_name = new StringContent(classDoc.name());
       
   186                 if (classDoc.isInterface())
       
   187                     arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name);
       
   188                 Content link = getLink(new LinkInfoImpl(configuration,
       
   189                                                         LinkInfoImpl.Kind.PACKAGE_FRAME, classDoc).label(arr_i_name).target("classFrame"));
       
   190                 Content li = HtmlTree.LI(link);
       
   191                 ul.addContent(li);
       
   192             }
       
   193             htmlTree.addContent(ul);
       
   194             if (configuration.allowTag(HtmlTag.SECTION)) {
       
   195                 contentTree.addContent(htmlTree);
       
   196             }
       
   197         }
       
   198     }
       
   199 }