langtools/src/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java
author ksrini
Sun, 15 Jun 2014 08:41:57 -0700
changeset 25454 376a52c9540c
parent 22159 682da512ec17
permissions -rw-r--r--
8039028: [javadoc] refactor the usage of Util.java Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
     2
 * Copyright (c) 1998, 2014, 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: 1789
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: 1789
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: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
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
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    31
import com.sun.javadoc.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 7681
diff changeset
    32
import com.sun.tools.doclets.formats.html.markup.*;
7614
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.*;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    34
import com.sun.tools.doclets.internal.toolkit.util.*;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    35
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * Generate the file with list of all the classes in this run. This page will be
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * used in the left-hand bottom frame, when "All Classes" link is clicked in
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * the left-hand top frame. The name of the generated file is
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * "allclasses-frame.html".
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    42
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    44
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    45
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    46
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Doug Kramer
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    49
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public class AllClassesFrameWriter extends HtmlDocletWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * Index of all the classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    protected IndexBuilder indexbuilder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    59
     * BR tag to be used within a document tree.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    60
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    61
    final HtmlTree BR = new HtmlTree(HtmlTag.BR);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    62
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    63
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    64
     * Construct AllClassesFrameWriter object. Also initializes the indexbuilder
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * variable in this class.
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    66
     * @param configuration  The current configuration
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    67
     * @param filename       Path to the file which is getting generated.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    68
     * @param indexbuilder   Unicode based Index from {@link IndexBuilder}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    public AllClassesFrameWriter(ConfigurationImpl configuration,
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    73
                                 DocPath filename, IndexBuilder indexbuilder)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                              throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        super(configuration, filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        this.indexbuilder = indexbuilder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * Create AllClassesFrameWriter object. Then use it to generate the
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * "allclasses-frame.html" file. Generate the file in the current or the
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * destination directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @param indexbuilder IndexBuilder object for all classes index.
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
                                IndexBuilder indexbuilder) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        AllClassesFrameWriter allclassgen;
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    90
        DocPath filename = DocPaths.ALLCLASSES_FRAME;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            allclassgen = new AllClassesFrameWriter(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                                                    filename, indexbuilder);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    94
            allclassgen.buildAllClassesFile(true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            allclassgen.close();
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    96
            filename = DocPaths.ALLCLASSES_NOFRAME;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            allclassgen = new AllClassesFrameWriter(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                                                    filename, indexbuilder);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    99
            allclassgen.buildAllClassesFile(false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            allclassgen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            configuration.standardmessage.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                     error("doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                           exc.toString(), filename);
19667
fdfce85627a9 8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents: 17561
diff changeset
   105
            throw new DocletAbortException(exc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   110
     * Print all the classes in the file.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * @param wantFrames True if we want frames.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   113
    protected void buildAllClassesFile(boolean wantFrames) throws IOException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        String label = configuration.getText("doclet.All_Classes");
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   115
        Content body = getBody(false, getWindowTitle(label));
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   116
        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING,
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   117
                HtmlStyle.bar, allclassesLabel);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   118
        body.addContent(heading);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   119
        Content ul = new HtmlTree(HtmlTag.UL);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   120
        // Generate the class links and add it to the tdFont tree.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   121
        addAllClasses(ul, wantFrames);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   122
        Content div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   123
        body.addContent(div);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   124
        printHtmlDocument(null, false, body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   128
     * Use the sorted index of all the classes and add all the classes to the
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   129
     * content list.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   131
     * @param content HtmlTree content to which all classes information will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * @param wantFrames True if we want frames.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   134
    protected void addAllClasses(Content content, boolean wantFrames) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        for (int i = 0; i < indexbuilder.elements().length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            Character unicode = (Character)((indexbuilder.elements())[i]);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   137
            addContents(indexbuilder.getMemberList(unicode), wantFrames, content);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        }
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
     * Given a list of classes, generate links for each class or interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * If the class kind is interface, print it in the italics font. Also all
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * links should target the right-hand frame. If clicked on any class name
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * in this page, appropriate class page should get opened in the right-hand
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * frame.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param classlist Sorted list of classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * @param wantFrames True if we want frames.
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   150
     * @param content HtmlTree content to which the links will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   152
    protected void addContents(List<Doc> classlist, boolean wantFrames,
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19667
diff changeset
   153
                               Content content) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19667
diff changeset
   154
        for (Doc doc : classlist) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19667
diff changeset
   155
            ClassDoc cd = (ClassDoc) doc;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
   156
            if (!utils.isCoreClass(cd)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            }
17560
9f6771abbd1a 8011650: reduce use of RawHtml nodes in doclet
jjg
parents: 17559
diff changeset
   159
            Content label = italicsClassName(cd, false);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   160
            Content linkContent;
17560
9f6771abbd1a 8011650: reduce use of RawHtml nodes in doclet
jjg
parents: 17559
diff changeset
   161
            if (wantFrames) {
17559
87c28ee29329 8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents: 17558
diff changeset
   162
                linkContent = getLink(new LinkInfoImpl(configuration,
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19667
diff changeset
   163
                                                       LinkInfoImpl.Kind.ALL_CLASSES_FRAME, cd).label(label).target("classFrame"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            } else {
17561
9f3505f35da9 8011651: simplify LinkInfoImpl API
jjg
parents: 17560
diff changeset
   165
                linkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, cd).label(label));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
            }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   167
            Content li = HtmlTree.LI(linkContent);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   168
            content.addContent(li);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
}