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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1410
bfec2a1cc869
child 1735
8ea30d59ac41
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

     1 /*
     2  * Copyright (c) 1998, 2013, 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  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.markup.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Class to generate file for each package contents in the left-hand bottom
    38  * frame. This will list all the Class Kinds in the package. A click on any
    39  * class-kind will update the right-hand frame with the clicked class-kind page.
    40  *
    41  *  <p><b>This is NOT part of any supported API.
    42  *  If you write code that depends on this, you do so at your own risk.
    43  *  This code and its internal interfaces are subject to change or
    44  *  deletion without notice.</b>
    45  *
    46  * @author Atul M Dambalkar
    47  * @author Bhavesh Patel (Modified)
    48  */
    49 public class PackageFrameWriter extends HtmlDocletWriter {
    51     /**
    52      * The package being documented.
    53      */
    54     private PackageDoc packageDoc;
    56     /**
    57      * The classes to be documented.  Use this to filter out classes
    58      * that will not be documented.
    59      */
    60     private Set<ClassDoc> documentedClasses;
    62     /**
    63      * Constructor to construct PackageFrameWriter object and to generate
    64      * "package-frame.html" file in the respective package directory.
    65      * For example for package "java.lang" this will generate file
    66      * "package-frame.html" file in the "java/lang" directory. It will also
    67      * create "java/lang" directory in the current or the destination directory
    68      * if it doesn't exist.
    69      *
    70      * @param configuration the configuration of the doclet.
    71      * @param packageDoc PackageDoc under consideration.
    72      */
    73     public PackageFrameWriter(ConfigurationImpl configuration,
    74                               PackageDoc packageDoc)
    75                               throws IOException {
    76         super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_FRAME));
    77         this.packageDoc = packageDoc;
    78         if (configuration.root.specifiedPackages().length == 0) {
    79             documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
    80         }
    81     }
    83     /**
    84      * Generate a package summary page for the left-hand bottom frame. Construct
    85      * the PackageFrameWriter object and then uses it generate the file.
    86      *
    87      * @param configuration the current configuration of the doclet.
    88      * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
    89      */
    90     public static void generate(ConfigurationImpl configuration,
    91             PackageDoc packageDoc) {
    92         PackageFrameWriter packgen;
    93         try {
    94             packgen = new PackageFrameWriter(configuration, packageDoc);
    95             String pkgName = Util.getPackageName(packageDoc);
    96             Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
    97             Content pkgNameContent = new RawHtml(pkgName);
    98             Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
    99                     packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
   100             body.addContent(heading);
   101             HtmlTree div = new HtmlTree(HtmlTag.DIV);
   102             div.addStyle(HtmlStyle.indexContainer);
   103             packgen.addClassListing(div);
   104             body.addContent(div);
   105             packgen.printHtmlDocument(
   106                     configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
   107             packgen.close();
   108         } catch (IOException exc) {
   109             configuration.standardmessage.error(
   110                     "doclet.exception_encountered",
   111                     exc.toString(), DocPaths.PACKAGE_FRAME.getPath());
   112             throw new DocletAbortException();
   113         }
   114     }
   116     /**
   117      * Add class listing for all the classes in this package. Divide class
   118      * listing as per the class kind and generate separate listing for
   119      * Classes, Interfaces, Exceptions and Errors.
   120      *
   121      * @param contentTree the content tree to which the listing will be added
   122      */
   123     protected void addClassListing(Content contentTree) {
   124         Configuration config = configuration;
   125         if (packageDoc.isIncluded()) {
   126             addClassKindListing(packageDoc.interfaces(),
   127                 getResource("doclet.Interfaces"), contentTree);
   128             addClassKindListing(packageDoc.ordinaryClasses(),
   129                 getResource("doclet.Classes"), contentTree);
   130             addClassKindListing(packageDoc.enums(),
   131                 getResource("doclet.Enums"), contentTree);
   132             addClassKindListing(packageDoc.exceptions(),
   133                 getResource("doclet.Exceptions"), contentTree);
   134             addClassKindListing(packageDoc.errors(),
   135                 getResource("doclet.Errors"), contentTree);
   136             addClassKindListing(packageDoc.annotationTypes(),
   137                 getResource("doclet.AnnotationTypes"), contentTree);
   138         } else {
   139             String name = Util.getPackageName(packageDoc);
   140             addClassKindListing(config.classDocCatalog.interfaces(name),
   141                 getResource("doclet.Interfaces"), contentTree);
   142             addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
   143                 getResource("doclet.Classes"), contentTree);
   144             addClassKindListing(config.classDocCatalog.enums(name),
   145                 getResource("doclet.Enums"), contentTree);
   146             addClassKindListing(config.classDocCatalog.exceptions(name),
   147                 getResource("doclet.Exceptions"), contentTree);
   148             addClassKindListing(config.classDocCatalog.errors(name),
   149                 getResource("doclet.Errors"), contentTree);
   150             addClassKindListing(config.classDocCatalog.annotationTypes(name),
   151                 getResource("doclet.AnnotationTypes"), contentTree);
   152         }
   153     }
   155     /**
   156      * Add specific class kind listing. Also add label to the listing.
   157      *
   158      * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
   159      * @param labelContent content tree of the label to be added
   160      * @param contentTree the content tree to which the class kind listing will be added
   161      */
   162     protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
   163             Content contentTree) {
   164         arr = Util.filterOutPrivateClasses(arr, configuration.javafx);
   165         if(arr.length > 0) {
   166             Arrays.sort(arr);
   167             boolean printedHeader = false;
   168             HtmlTree ul = new HtmlTree(HtmlTag.UL);
   169             ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
   170             for (int i = 0; i < arr.length; i++) {
   171                 if (documentedClasses != null &&
   172                         !documentedClasses.contains(arr[i])) {
   173                     continue;
   174                 }
   175                 if (!Util.isCoreClass(arr[i]) || !
   176                         configuration.isGeneratedDoc(arr[i])) {
   177                     continue;
   178                 }
   179                 if (!printedHeader) {
   180                     Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
   181                             true, labelContent);
   182                     contentTree.addContent(heading);
   183                     printedHeader = true;
   184                 }
   185                 Content link = new RawHtml (getLink(new LinkInfoImpl(configuration,
   186                         LinkInfoImpl.PACKAGE_FRAME, arr[i],
   187                         (arr[i].isInterface() ? italicsText(arr[i].name()) :
   188                             arr[i].name()),"classFrame")));
   189                 Content li = HtmlTree.LI(link);
   190                 ul.addContent(li);
   191             }
   192             contentTree.addContent(ul);
   193         }
   194     }
   195 }

mercurial