langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java
author bpatel
Thu, 08 Jan 2009 16:26:59 -0800
changeset 1787 1aa079321cd2
parent 10 06bc494ca11e
child 2216 b124d5c924eb
permissions -rw-r--r--
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
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.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * Class to generate Tree page for a package. The name of the file generated is
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * "package-tree.html" and it is generated in the respective package directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
public class PackageTreeWriter extends AbstractTreeWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
     * Package for which tree is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    protected PackageDoc packagedoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
     * The previous package name in the alpha-order list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    protected PackageDoc prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * The next package name in the alpha-order list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    protected PackageDoc next;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    public PackageTreeWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
                             String path, String filename,
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
                             PackageDoc packagedoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
                             PackageDoc prev, PackageDoc next)
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
                      throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        super(configuration, path, filename,
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
              new ClassTree(
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
                configuration.classDocCatalog.allClasses(packagedoc),
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
                configuration),
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
              packagedoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        this.packagedoc = packagedoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        this.prev = prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        this.next = next;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * Construct a PackageTreeWriter object and then use it to generate the
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * package tree page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     * @param pkg      Package for which tree file is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * @param prev     Previous package in the alpha-ordered list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * @param next     Next package in the alpha-ordered list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * @param noDeprecated  If true, do not generate any information for
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * deprecated classe or interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    public static void generate(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                                PackageDoc pkg, PackageDoc prev,
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                                PackageDoc next, boolean noDeprecated) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        PackageTreeWriter packgen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        String path = DirectoryManager.getDirectoryPath(pkg);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        String filename = "package-tree.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            packgen = new PackageTreeWriter(configuration, path, filename, pkg,
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                prev, next);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            packgen.generatePackageTreeFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            packgen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            configuration.standardmessage.error(
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                        "doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                        exc.toString(), filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        }
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
     * Generate a separate tree file for each package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    protected void generatePackageTreeFile() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        printHtmlHeader(packagedoc.name() + " "
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            + configuration.getText("doclet.Window_Class_Hierarchy"), null, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        printPackageTreeHeader();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        if (configuration.packages.length > 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            printLinkToMainTree();
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        generateTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        generateTree(classtree.baseEnums(), "doclet.Enum_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        printPackageTreeFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        printBottom();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        printBodyHtmlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * Print the navigation bar header for the package tree file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    protected void printPackageTreeHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        printTop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        navLinks(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        center();
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        h2(configuration.getText("doclet.Hierarchy_For_Package",
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            Util.getPackageName(packagedoc)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        centerEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * Generate a link to the tree for all the packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    protected void printLinkToMainTree() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        dl();
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        dt();
1787
1aa079321cd2 6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents: 10
diff changeset
   147
        strongText("doclet.Package_Hierarchies");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        dd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        navLinkMainTree(configuration.getText("doclet.All_Packages"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        dlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * Print the navigation bar footer for the package tree file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    protected void printPackageTreeFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        navLinks(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * Link for the previous package tree file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    protected void navLinkPrevious() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        if (prev == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            navLinkPrevious(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
            String path = DirectoryManager.getRelativePath(packagedoc.name(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                                                           prev.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            navLinkPrevious(path + "package-tree.html");
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * Link for the next package tree file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    protected void navLinkNext() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        if (next == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            navLinkNext(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            String path = DirectoryManager.getRelativePath(packagedoc.name(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                                                           next.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            navLinkNext(path + "package-tree.html");
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Link to the package summary page for the package of this tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    protected void navLinkPackage() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        navCellStart();
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        printHyperLink("package-summary.html", "", configuration.getText("doclet.Package"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                        true, "NavBarFont1");
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        navCellEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
}