langtools/src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.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 1997-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.*;
b124d5c924eb 6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents: 1787
diff changeset
    32
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Generate Class Hierarchy page for all the Classes in this run.  Use
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * ClassTree for building the Tree. The name of
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * the generated file is "overview-tree.html" and it is generated in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * current or the destination directory.
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 TreeWriter extends AbstractTreeWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
     * Packages in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private PackageDoc[] packages;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * True if there are no packages specified on the command line,
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * False otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    private boolean classesonly;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * Constructor to construct TreeWriter object.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * @param filename String filename
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * @param classtree the tree being built.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public TreeWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            String filename, ClassTree classtree)
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        super(configuration, filename, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        packages = configuration.packages;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    classesonly = packages.length == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * Create a TreeWriter object and use it to generate the
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * "overview-tree.html" file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * @param classtree the class tree being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @throws  DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    public static void generate(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
                                ClassTree classtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        TreeWriter treegen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        String filename = "overview-tree.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            treegen = new TreeWriter(configuration, filename, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            treegen.generateTreeFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            treegen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            configuration.standardmessage.error(
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                        "doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                        exc.toString(), filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * Print the interface hierarchy and class hierarchy in the file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    public void generateTreeFile() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        printHtmlHeader(configuration.getText("doclet.Window_Class_Hierarchy"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            null, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        printTreeHeader();
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        printPageHeading();
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        printPackageTreeLinks();
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        generateTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        generateTree(classtree.baseEnums(), "doclet.Enum_Hierarchy");
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        printTreeFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * Generate the links to all the package tree files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    protected void printPackageTreeLinks() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        //Do nothing if only unnamed package is used
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        if (packages.length == 1 && packages[0].name().length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        if (!classesonly) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            dl();
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            dt();
1787
1aa079321cd2 6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents: 10
diff changeset
   124
            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
   125
            dtEnd();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            dd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            for (int i = 0; i < packages.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                if (packages[i].name().length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                String filename = pathString(packages[i], "package-tree.html");
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                printHyperLink(filename, "", packages[i].name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                if (i < packages.length - 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                    print(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            }
2216
b124d5c924eb 6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents: 1787
diff changeset
   137
            ddEnd();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            dlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            hr();
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
     * Print the top text (from the -top option) and
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * navigation bar at the top of page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    protected void printTreeHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        printTop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        navLinks(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * Print the navigation bar and bottom text (from the -bottom option)
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * at the bottom of page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    protected void printTreeFooter() {
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
        printBottom();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        printBodyHtmlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * Print the page title "Hierarchy For All Packages" at the top of the tree
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    protected void printPageHeading() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        center();
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        h2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        printText("doclet.Hierarchy_For_All_Packages");
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        h2End();
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        centerEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
}