langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageFrameWriter.java
author mcimadamore
Tue, 13 Jan 2009 13:27:14 +0000
changeset 1789 7ac8c0815000
parent 1264 076a3cde30d5
child 5520 86e4b9a9da40
permissions -rw-r--r--
6765045: Remove rawtypes warnings from langtools Summary: Removed all occurrences of rawtypes warnings from langtools Reviewed-by: jjg, bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
1264
076a3cde30d5 6754988: Update copyright year
xdono
parents: 868
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.formats.html;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.doclets.internal.toolkit.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Class to generate file for each package contents in the left-hand bottom
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * frame. This will list all the Class Kinds in the package. A click on any
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * class-kind will update the right-hand frame with the clicked class-kind page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
public class PackageFrameWriter extends HtmlDocletWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
     * The package being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private PackageDoc packageDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * The classes to be documented.  Use this to filter out classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * that will not be documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    52
    private Set<ClassDoc> documentedClasses;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * The name of the output file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    public static final String OUTPUT_FILE_NAME = "package-frame.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * Constructor to construct PackageFrameWriter object and to generate
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * "package-frame.html" file in the respective package directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * For example for package "java.lang" this will generate file
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * "package-frame.html" file in the "java/lang" directory. It will also
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * create "java/lang" directory in the current or the destination directory
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * if it doesen't exist.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * @param configuration the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * @param packageDoc PackageDoc under consideration.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    public PackageFrameWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                              PackageDoc packageDoc)
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                              throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc));
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        this.packageDoc = packageDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        if (configuration.root.specifiedPackages().length == 0) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    76
            documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * Generate a package summary page for the left-hand bottom frame. Construct
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * the PackageFrameWriter object and then uses it generate the file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public static void generate(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                                PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        PackageFrameWriter packgen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            packgen = new PackageFrameWriter(configuration, packageDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            String pkgName = Util.getPackageName(packageDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            packgen.printHtmlHeader(pkgName, configuration.metakeywords.getMetaKeywords(packageDoc), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            packgen.printPackageHeader(pkgName);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            packgen.generateClassListing();
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            packgen.printBodyHtmlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            packgen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            configuration.standardmessage.error(
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                        "doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                        exc.toString(), OUTPUT_FILE_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * Generate class listing for all the classes in this package. Divide class
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * listing as per the class kind and generate separate listing for
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * Classes, Interfaces, Exceptions and Errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    protected void generateClassListing() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        Configuration config = configuration();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        if (packageDoc.isIncluded()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            generateClassKindListing(packageDoc.interfaces(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                configuration.getText("doclet.Interfaces"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            generateClassKindListing(packageDoc.ordinaryClasses(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                configuration.getText("doclet.Classes"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            generateClassKindListing(packageDoc.enums(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                configuration.getText("doclet.Enums"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            generateClassKindListing(packageDoc.exceptions(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                configuration.getText("doclet.Exceptions"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            generateClassKindListing(packageDoc.errors(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                configuration.getText("doclet.Errors"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            generateClassKindListing(packageDoc.annotationTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                configuration.getText("doclet.AnnotationTypes"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            String name = Util.getPackageName(packageDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            generateClassKindListing(config.classDocCatalog.interfaces(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                configuration.getText("doclet.Interfaces"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            generateClassKindListing(config.classDocCatalog.ordinaryClasses(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                configuration.getText("doclet.Classes"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            generateClassKindListing(config.classDocCatalog.enums(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                configuration.getText("doclet.Enums"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            generateClassKindListing(config.classDocCatalog.exceptions(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                configuration.getText("doclet.Exceptions"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            generateClassKindListing(config.classDocCatalog.errors(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                configuration.getText("doclet.Errors"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            generateClassKindListing(config.classDocCatalog.annotationTypes(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                configuration.getText("doclet.AnnotationTypes"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * Generate specific class kind listing. Also add label to the listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * @param arr Array of specific class kinds, namely Class or Interface or
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * Exception or Error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param label Label for the listing
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    protected void generateClassKindListing(ClassDoc[] arr, String label) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        if(arr.length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            Arrays.sort(arr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            printPackageTableHeader();
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            fontSizeStyle("+1", "FrameHeadingFont");
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            boolean printedHeader = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            for (int i = 0; i < arr.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                if (documentedClasses != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                    !documentedClasses.contains(arr[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                if (!Util.isCoreClass(arr[i]) || !
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                    configuration.isGeneratedDoc(arr[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                if (!printedHeader) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                    print(label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                    fontEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                    println("&nbsp;");
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                    fontStyle("FrameItemFont");
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                    printedHeader = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                br();
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                printLink(new LinkInfoImpl(
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                    LinkInfoImpl.PACKAGE_FRAME,
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                    arr[i],
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                    (arr[i].isInterface() ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                        italicsText(arr[i].name()) :
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                        arr[i].name()),"classFrame")
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                );
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            fontEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            printPackageTableFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * Print the package link at the top of the class kind listing. Clicking
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * this link, package-summary page will appear in the right hand frame.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * @param heading Top Heading to be used for the class kind listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    protected void printPackageHeader(String heading) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        fontSizeStyle("+1", "FrameTitleFont");
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        printTargetPackageLink(packageDoc, "classFrame", heading);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        fontEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * The table for the class kind listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    protected void printPackageTableHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        table();
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        tr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        tdNowrap();
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * Closing Html tags for table of class kind listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    protected void printPackageTableFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        tdEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        trEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        tableEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
}