Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, 2010, 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 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.internal.toolkit.util.*;
34 import com.sun.tools.doclets.formats.html.markup.*;
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 * @author Atul M Dambalkar
43 * @author Doug Kramer
44 * @author Bhavesh Patel (Modified)
45 */
46 public class AllClassesFrameWriter extends HtmlDocletWriter {
48 /**
49 * The name of the output file with frames
50 */
51 public static final String OUTPUT_FILE_NAME_FRAMES = "allclasses-frame.html";
53 /**
54 * The name of the output file without frames
55 */
56 public static final String OUTPUT_FILE_NAME_NOFRAMES = "allclasses-noframe.html";
58 /**
59 * Index of all the classes.
60 */
61 protected IndexBuilder indexbuilder;
63 /**
64 * BR tag to be used within a document tree.
65 */
66 final HtmlTree BR = new HtmlTree(HtmlTag.BR);
68 /**
69 * Construct AllClassesFrameWriter object. Also initilises the indexbuilder
70 * variable in this class.
71 * @throws IOException
72 * @throws DocletAbortException
73 */
74 public AllClassesFrameWriter(ConfigurationImpl configuration,
75 String filename, IndexBuilder indexbuilder)
76 throws IOException {
77 super(configuration, filename);
78 this.indexbuilder = indexbuilder;
79 }
81 /**
82 * Create AllClassesFrameWriter object. Then use it to generate the
83 * "allclasses-frame.html" file. Generate the file in the current or the
84 * destination directory.
85 *
86 * @param indexbuilder IndexBuilder object for all classes index.
87 * @throws DocletAbortException
88 */
89 public static void generate(ConfigurationImpl configuration,
90 IndexBuilder indexbuilder) {
91 AllClassesFrameWriter allclassgen;
92 String filename = OUTPUT_FILE_NAME_FRAMES;
93 try {
94 allclassgen = new AllClassesFrameWriter(configuration,
95 filename, indexbuilder);
96 allclassgen.buildAllClassesFile(true);
97 allclassgen.close();
98 filename = OUTPUT_FILE_NAME_NOFRAMES;
99 allclassgen = new AllClassesFrameWriter(configuration,
100 filename, indexbuilder);
101 allclassgen.buildAllClassesFile(false);
102 allclassgen.close();
103 } catch (IOException exc) {
104 configuration.standardmessage.
105 error("doclet.exception_encountered",
106 exc.toString(), filename);
107 throw new DocletAbortException();
108 }
109 }
111 /**
112 * Print all the classes in the file.
113 * @param wantFrames True if we want frames.
114 */
115 protected void buildAllClassesFile(boolean wantFrames) throws IOException {
116 String label = configuration.getText("doclet.All_Classes");
117 Content body = getBody(false, getWindowTitle(label));
118 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING,
119 HtmlStyle.bar, allclassesLabel);
120 body.addContent(heading);
121 Content ul = new HtmlTree(HtmlTag.UL);
122 // Generate the class links and add it to the tdFont tree.
123 addAllClasses(ul, wantFrames);
124 Content div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
125 body.addContent(div);
126 printHtmlDocument(null, false, body);
127 }
129 /**
130 * Use the sorted index of all the classes and add all the classes to the
131 * content list.
132 *
133 * @param content HtmlTree content to which all classes information will be added
134 * @param wantFrames True if we want frames.
135 */
136 protected void addAllClasses(Content content, boolean wantFrames) {
137 for (int i = 0; i < indexbuilder.elements().length; i++) {
138 Character unicode = (Character)((indexbuilder.elements())[i]);
139 addContents(indexbuilder.getMemberList(unicode), wantFrames, content);
140 }
141 }
143 /**
144 * Given a list of classes, generate links for each class or interface.
145 * If the class kind is interface, print it in the italics font. Also all
146 * links should target the right-hand frame. If clicked on any class name
147 * in this page, appropriate class page should get opened in the right-hand
148 * frame.
149 *
150 * @param classlist Sorted list of classes.
151 * @param wantFrames True if we want frames.
152 * @param content HtmlTree content to which the links will be added
153 */
154 protected void addContents(List<Doc> classlist, boolean wantFrames,
155 Content content) {
156 for (int i = 0; i < classlist.size(); i++) {
157 ClassDoc cd = (ClassDoc)classlist.get(i);
158 if (!Util.isCoreClass(cd)) {
159 continue;
160 }
161 String label = italicsClassName(cd, false);
162 Content linkContent;
163 if(wantFrames){
164 linkContent = new RawHtml(getLink(new LinkInfoImpl(
165 LinkInfoImpl.ALL_CLASSES_FRAME, cd, label, "classFrame")));
166 } else {
167 linkContent = new RawHtml(getLink(new LinkInfoImpl(cd, label)));
168 }
169 Content li = HtmlTree.LI(linkContent);
170 content.addContent(li);
171 }
172 }
173 }