langtools/src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java
author bpatel
Wed, 01 Dec 2010 11:02:38 -0800
changeset 7614 cfadc977ca75
parent 5520 86e4b9a9da40
child 7681 1f0819a3341f
permissions -rw-r--r--
6851834: Javadoc doclet needs a structured approach to generate the output HTML. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
     2
 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. 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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    23
 * questions.
10
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.*;
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    32
import com.sun.tools.doclets.formats.html.markup.*;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    33
import com.sun.tools.doclets.internal.toolkit.*;
2216
b124d5c924eb 6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents: 1787
diff changeset
    34
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Generate Class Hierarchy page for all the Classes in this run.  Use
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * ClassTree for building the Tree. The name of
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * the generated file is "overview-tree.html" and it is generated in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * current or the destination directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * @author Atul M Dambalkar
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    42
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class TreeWriter extends AbstractTreeWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     * Packages in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    private PackageDoc[] packages;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * True if there are no packages specified on the command line,
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * False otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    private boolean classesonly;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * Constructor to construct TreeWriter object.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * @param filename String filename
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * @param classtree the tree being built.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    public TreeWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
            String filename, ClassTree classtree)
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        super(configuration, filename, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        packages = configuration.packages;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    classesonly = packages.length == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * Create a TreeWriter object and use it to generate the
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * "overview-tree.html" file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @param classtree the class tree being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @throws  DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public static void generate(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                                ClassTree classtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        TreeWriter treegen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        String filename = "overview-tree.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            treegen = new TreeWriter(configuration, filename, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            treegen.generateTreeFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            treegen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            configuration.standardmessage.error(
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                        "doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                        exc.toString(), filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    96
     * Generate the interface hierarchy and class hierarchy.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public void generateTreeFile() throws IOException {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    99
        Content body = getTreeHeader();
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   100
        Content headContent = getResource("doclet.Hierarchy_For_All_Packages");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   101
        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   102
                HtmlStyle.title, headContent);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   103
        Content div = HtmlTree.DIV(HtmlStyle.header, heading);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   104
        addPackageTreeLinks(div);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   105
        body.addContent(div);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   106
        HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   107
        divTree.addStyle(HtmlStyle.contentContainer);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   108
        addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   109
        addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   110
        addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   111
        addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   112
        body.addContent(divTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   113
        addNavLinks(false, body);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   114
        addBottom(body);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   115
        printHtmlDocument(null, true, body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   119
     * Add the links to all the package tree files.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   120
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   121
     * @param contentTree the content tree to which the links will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   123
    protected void addPackageTreeLinks(Content contentTree) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        //Do nothing if only unnamed package is used
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        if (packages.length == 1 && packages[0].name().length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        if (!classesonly) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   129
            Content span = HtmlTree.SPAN(HtmlStyle.strong,
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   130
                    getResource("doclet.Package_Hierarchies"));
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   131
            contentTree.addContent(span);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   132
            HtmlTree ul = new HtmlTree(HtmlTag.UL);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   133
            ul.addStyle(HtmlStyle.horizontal);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            for (int i = 0; i < packages.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                if (packages[i].name().length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   138
                String link = pathString(packages[i], "package-tree.html");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   139
                Content li = HtmlTree.LI(getHyperLink(
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   140
                        link, "", new StringContent(packages[i].name())));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                if (i < packages.length - 1) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   142
                    li.addContent(", ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   144
                ul.addContent(li);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   146
            contentTree.addContent(ul);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   151
     * Get the tree header.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   152
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   153
     * @return a content tree for the tree header
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   155
    protected Content getTreeHeader() {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   156
        String title = configuration.getText("doclet.Window_Class_Hierarchy");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   157
        Content bodyTree = getBody(true, getWindowTitle(title));
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   158
        addTop(bodyTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   159
        addNavLinks(true, bodyTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   160
        return bodyTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
}