langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 10 06bc494ca11e
child 868 d0f233085cbb
permissions -rw-r--r--
Initial load
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
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
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Generate the package index page "overview-summary.html" for the right-hand
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * frame. A click on the package name on this page will update the same frame
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * with the "pacakge-summary.html" file for the clicked package.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
public class PackageIndexWriter extends AbstractPackageIndexWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
     * Root of the program structure. Used for "overview" documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    private RootDoc root;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * Map representing the group of packages as specified on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * @see Group
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    private Map groupPackageMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * List to store the order groups as specified on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    private List groupList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * Construct the PackageIndexWriter. Also constructs the grouping
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * information as provided on the command line by "-group" option. Stores
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * the order of groups specified by the user.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * @see Group
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    public PackageIndexWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
                              String filename)
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
                       throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        super(configuration, filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        this.root = configuration.root;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        groupPackageMap = configuration.group.groupPackages(packages);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        groupList = configuration.group.getGroupList();
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
     * Generate the package index page for the right-hand frame.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public static void generate(ConfigurationImpl configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        PackageIndexWriter packgen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        String filename = "overview-summary.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            packgen = new PackageIndexWriter(configuration, filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            packgen.generatePackageIndexFile("doclet.Window_Overview_Summary", true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            packgen.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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * Print each package in separate rows in the index table. Generate link
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * to each package.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * @param pkg Package to which link is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    protected void printIndexRow(PackageDoc pkg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        if(pkg != null && pkg.name().length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            trBgcolorStyle("white", "TableRowColor");
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            summaryRow(20);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            bold();
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            printPackageLink(pkg, Util.getPackageName(pkg), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
            boldEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            summaryRowEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            summaryRow(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            printSummaryComment(pkg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            summaryRowEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            trEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
       }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * Depending upon the grouping information and their titles, generate
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * separate table indices for each package group.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    protected void generateIndex() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        for (int i = 0; i < groupList.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        String groupname = (String)groupList.get(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        List list = (List)groupPackageMap.get(groupname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            if (list != null && list.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                printIndexContents((PackageDoc[])list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                                       toArray(new PackageDoc[list.size()]),
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                                    groupname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * Print the overview summary comment for this documentation. Print one line
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * summary at the top of the page and generate a link to the description,
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * which is generated at the end of this page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    protected void printOverviewHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        if (root.inlineTags().length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            printSummaryComment(root);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            p();
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            bold(configuration.getText("doclet.See"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            br();
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            printNbsps();
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            printHyperLink("", "overview_description",
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                configuration.getText("doclet.Description"), true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            p();
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * Print Html tags for the table for this package index.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    protected void printIndexHeader(String text) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        tableIndexSummary();
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        tableHeaderStart("#CCCCFF");
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        bold(text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        tableHeaderEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * Print Html closing tags for the table for this package index.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    protected void printIndexFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        tableEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        p();
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        space();
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Print the overview comment as provided in the file specified by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * "-overview" option on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    protected void printOverviewComment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        if (root.inlineTags().length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            anchor("overview_description");
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            p();
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            printInlineComment(root);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            p();
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * Call {@link #printOverviewComment()} and then genrate the tag information
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * as provided in the file specified by the "-overview" option on the
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    protected void printOverview() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        printOverviewComment();
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        printTags(root);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * Print the top text (from the -top option), the upper
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * navigation bar, and then the title (from the"-title"
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * option), at the top of page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    protected void printNavigationBarHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        printTop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        navLinks(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        printConfigurationTitle();
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * Print the lower navigation bar and the bottom text
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * (from the -bottom option) at the bottom of page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    protected void printNavigationBarFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        navLinks(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        printBottom();
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
}