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