AllClassesFrameWriter.java revision 2571:10fc81ac75b4
1/*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.tools.doclets.formats.html;
27
28import java.io.*;
29import java.util.*;
30
31import com.sun.javadoc.*;
32import com.sun.tools.doclets.formats.html.markup.*;
33import com.sun.tools.doclets.internal.toolkit.*;
34import com.sun.tools.doclets.internal.toolkit.util.*;
35
36/**
37 * Generate the file with list of all the classes in this run. This page will be
38 * used in the left-hand bottom frame, when "All Classes" link is clicked in
39 * the left-hand top frame. The name of the generated file is
40 * "allclasses-frame.html".
41 *
42 *  <p><b>This is NOT part of any supported API.
43 *  If you write code that depends on this, you do so at your own risk.
44 *  This code and its internal interfaces are subject to change or
45 *  deletion without notice.</b>
46 *
47 * @author Atul M Dambalkar
48 * @author Doug Kramer
49 * @author Bhavesh Patel (Modified)
50 */
51public class AllClassesFrameWriter extends HtmlDocletWriter {
52
53    /**
54     * Index of all the classes.
55     */
56    protected IndexBuilder indexbuilder;
57
58    /**
59     * BR tag to be used within a document tree.
60     */
61    final HtmlTree BR = new HtmlTree(HtmlTag.BR);
62
63    /**
64     * Construct AllClassesFrameWriter object. Also initializes the indexbuilder
65     * variable in this class.
66     * @param configuration  The current configuration
67     * @param filename       Path to the file which is getting generated.
68     * @param indexbuilder   Unicode based Index from {@link IndexBuilder}
69     * @throws IOException
70     * @throws DocletAbortException
71     */
72    public AllClassesFrameWriter(ConfigurationImpl configuration,
73                                 DocPath filename, IndexBuilder indexbuilder)
74                              throws IOException {
75        super(configuration, filename);
76        this.indexbuilder = indexbuilder;
77    }
78
79    /**
80     * Create AllClassesFrameWriter object. Then use it to generate the
81     * "allclasses-frame.html" file. Generate the file in the current or the
82     * destination directory.
83     *
84     * @param indexbuilder IndexBuilder object for all classes index.
85     * @throws DocletAbortException
86     */
87    public static void generate(ConfigurationImpl configuration,
88                                IndexBuilder indexbuilder) {
89        AllClassesFrameWriter allclassgen;
90        DocPath filename = DocPaths.ALLCLASSES_FRAME;
91        try {
92            allclassgen = new AllClassesFrameWriter(configuration,
93                                                    filename, indexbuilder);
94            allclassgen.buildAllClassesFile(true);
95            allclassgen.close();
96            filename = DocPaths.ALLCLASSES_NOFRAME;
97            allclassgen = new AllClassesFrameWriter(configuration,
98                                                    filename, indexbuilder);
99            allclassgen.buildAllClassesFile(false);
100            allclassgen.close();
101        } catch (IOException exc) {
102            configuration.standardmessage.
103                     error("doclet.exception_encountered",
104                           exc.toString(), filename);
105            throw new DocletAbortException(exc);
106        }
107    }
108
109    /**
110     * Print all the classes in the file.
111     * @param wantFrames True if we want frames.
112     */
113    protected void buildAllClassesFile(boolean wantFrames) throws IOException {
114        String label = configuration.getText("doclet.All_Classes");
115        Content body = getBody(false, getWindowTitle(label));
116        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING,
117                HtmlStyle.bar, allclassesLabel);
118        body.addContent(heading);
119        Content ul = new HtmlTree(HtmlTag.UL);
120        // Generate the class links and add it to the tdFont tree.
121        addAllClasses(ul, wantFrames);
122        Content div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
123        body.addContent(div);
124        printHtmlDocument(null, false, body);
125    }
126
127    /**
128     * Use the sorted index of all the classes and add all the classes to the
129     * content list.
130     *
131     * @param content HtmlTree content to which all classes information will be added
132     * @param wantFrames True if we want frames.
133     */
134    protected void addAllClasses(Content content, boolean wantFrames) {
135        for (int i = 0; i < indexbuilder.elements().length; i++) {
136            Character unicode = (Character)((indexbuilder.elements())[i]);
137            addContents(indexbuilder.getMemberList(unicode), wantFrames, content);
138        }
139    }
140
141    /**
142     * Given a list of classes, generate links for each class or interface.
143     * If the class kind is interface, print it in the italics font. Also all
144     * links should target the right-hand frame. If clicked on any class name
145     * in this page, appropriate class page should get opened in the right-hand
146     * frame.
147     *
148     * @param classlist Sorted list of classes.
149     * @param wantFrames True if we want frames.
150     * @param content HtmlTree content to which the links will be added
151     */
152    protected void addContents(List<Doc> classlist, boolean wantFrames,
153                               Content content) {
154        for (Doc doc : classlist) {
155            ClassDoc cd = (ClassDoc) doc;
156            if (!utils.isCoreClass(cd)) {
157                continue;
158            }
159            Content label = italicsClassName(cd, false);
160            Content linkContent;
161            if (wantFrames) {
162                linkContent = getLink(new LinkInfoImpl(configuration,
163                                                       LinkInfoImpl.Kind.ALL_CLASSES_FRAME, cd).label(label).target("classFrame"));
164            } else {
165                linkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, cd).label(label));
166            }
167            Content li = HtmlTree.LI(linkContent);
168            content.addContent(li);
169        }
170    }
171}
172