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

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 184
905e151a185a
child 766
90af8d87741f
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1998, 2008, 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 com.sun.tools.doclets.internal.toolkit.util.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    31 import com.sun.javadoc.*;
    32 import java.io.*;
    33 import java.util.*;
    34 /**
    35  * Class to generate file for each package contents in the left-hand bottom
    36  * frame. This will list all the Class Kinds in the package. A click on any
    37  * class-kind will update the right-hand frame with the clicked class-kind page.
    38  *
    39  * @author Atul M Dambalkar
    40  */
    41 public class PackageFrameWriter extends HtmlDocletWriter {
    43     /**
    44      * The package being documented.
    45      */
    46     private PackageDoc packageDoc;
    48     /**
    49      * The classes to be documented.  Use this to filter out classes
    50      * that will not be documented.
    51      */
    52     private Set<ClassDoc> documentedClasses;
    54     /**
    55      * The name of the output file.
    56      */
    57     public static final String OUTPUT_FILE_NAME = "package-frame.html";
    59     /**
    60      * Constructor to construct PackageFrameWriter object and to generate
    61      * "package-frame.html" file in the respective package directory.
    62      * For example for package "java.lang" this will generate file
    63      * "package-frame.html" file in the "java/lang" directory. It will also
    64      * create "java/lang" directory in the current or the destination directory
    65      * if it doesen't exist.
    66      *
    67      * @param configuration the configuration of the doclet.
    68      * @param packageDoc PackageDoc under consideration.
    69      */
    70     public PackageFrameWriter(ConfigurationImpl configuration,
    71                               PackageDoc packageDoc)
    72                               throws IOException {
    73         super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc));
    74         this.packageDoc = packageDoc;
    75         if (configuration.root.specifiedPackages().length == 0) {
    76             documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
    77         }
    78     }
    80     /**
    81      * Generate a package summary page for the left-hand bottom frame. Construct
    82      * the PackageFrameWriter object and then uses it generate the file.
    83      *
    84      * @param configuration the current configuration of the doclet.
    85      * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
    86      */
    87     public static void generate(ConfigurationImpl configuration,
    88                                 PackageDoc packageDoc) {
    89         PackageFrameWriter packgen;
    90         try {
    91             packgen = new PackageFrameWriter(configuration, packageDoc);
    92             String pkgName = Util.getPackageName(packageDoc);
    93             packgen.printHtmlHeader(pkgName, configuration.metakeywords.getMetaKeywords(packageDoc), false);
    94             packgen.printPackageHeader(pkgName);
    95             packgen.generateClassListing();
    96             packgen.printBodyHtmlEnd();
    97             packgen.close();
    98         } catch (IOException exc) {
    99             configuration.standardmessage.error(
   100                         "doclet.exception_encountered",
   101                         exc.toString(), OUTPUT_FILE_NAME);
   102             throw new DocletAbortException();
   103         }
   104     }
   106     /**
   107      * Generate class listing for all the classes in this package. Divide class
   108      * listing as per the class kind and generate separate listing for
   109      * Classes, Interfaces, Exceptions and Errors.
   110      */
   111     protected void generateClassListing() {
   112         Configuration config = configuration();
   113         if (packageDoc.isIncluded()) {
   114             generateClassKindListing(packageDoc.interfaces(),
   115                 configuration.getText("doclet.Interfaces"));
   116             generateClassKindListing(packageDoc.ordinaryClasses(),
   117                 configuration.getText("doclet.Classes"));
   118             generateClassKindListing(packageDoc.enums(),
   119                 configuration.getText("doclet.Enums"));
   120             generateClassKindListing(packageDoc.exceptions(),
   121                 configuration.getText("doclet.Exceptions"));
   122             generateClassKindListing(packageDoc.errors(),
   123                 configuration.getText("doclet.Errors"));
   124             generateClassKindListing(packageDoc.annotationTypes(),
   125                 configuration.getText("doclet.AnnotationTypes"));
   126         } else {
   127             String name = Util.getPackageName(packageDoc);
   128             generateClassKindListing(config.classDocCatalog.interfaces(name),
   129                 configuration.getText("doclet.Interfaces"));
   130             generateClassKindListing(config.classDocCatalog.ordinaryClasses(name),
   131                 configuration.getText("doclet.Classes"));
   132             generateClassKindListing(config.classDocCatalog.enums(name),
   133                 configuration.getText("doclet.Enums"));
   134             generateClassKindListing(config.classDocCatalog.exceptions(name),
   135                 configuration.getText("doclet.Exceptions"));
   136             generateClassKindListing(config.classDocCatalog.errors(name),
   137                 configuration.getText("doclet.Errors"));
   138             generateClassKindListing(config.classDocCatalog.annotationTypes(name),
   139                 configuration.getText("doclet.AnnotationTypes"));
   140         }
   141     }
   143     /**
   144      * Generate specific class kind listing. Also add label to the listing.
   145      *
   146      * @param arr Array of specific class kinds, namely Class or Interface or
   147      * Exception or Error.
   148      * @param label Label for the listing
   149      */
   150     protected void generateClassKindListing(ClassDoc[] arr, String label) {
   151         if(arr.length > 0) {
   152             Arrays.sort(arr);
   153             printPackageTableHeader();
   154             fontSizeStyle("+1", "FrameHeadingFont");
   155             boolean printedHeader = false;
   156             for (int i = 0; i < arr.length; i++) {
   157                 if (documentedClasses != null &&
   158                     !documentedClasses.contains(arr[i])) {
   159                     continue;
   160                 }
   161                 if (!Util.isCoreClass(arr[i]) || !
   162                     configuration.isGeneratedDoc(arr[i])) {
   163                     continue;
   164                 }
   165                 if (!printedHeader) {
   166                     print(label);
   167                     fontEnd();
   168                     println("&nbsp;");
   169                     fontStyle("FrameItemFont");
   170                     printedHeader = true;
   171                 }
   172                 br();
   173                 printLink(new LinkInfoImpl(
   174                     LinkInfoImpl.PACKAGE_FRAME,
   175                     arr[i],
   176                     (arr[i].isInterface() ?
   177                         italicsText(arr[i].name()) :
   178                         arr[i].name()),"classFrame")
   179                 );
   180             }
   181             fontEnd();
   182             printPackageTableFooter();
   183             println();
   184         }
   185     }
   187     /**
   188      * Print the package link at the top of the class kind listing. Clicking
   189      * this link, package-summary page will appear in the right hand frame.
   190      *
   191      * @param heading Top Heading to be used for the class kind listing.
   192      */
   193     protected void printPackageHeader(String heading) {
   194         fontSizeStyle("+1", "FrameTitleFont");
   195         printTargetPackageLink(packageDoc, "classFrame", heading);
   196         fontEnd();
   197     }
   199     /**
   200      * The table for the class kind listing.
   201      */
   202     protected void printPackageTableHeader() {
   203         table();
   204         tr();
   205         tdNowrap();
   206     }
   208     /**
   209      * Closing Html tags for table of class kind listing.
   210      */
   211     protected void printPackageTableFooter() {
   212         tdEnd();
   213         trEnd();
   214         tableEnd();
   215     }
   216 }

mercurial