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 com.sun.tools.doclets.internal.toolkit.util.*;
30 import com.sun.tools.doclets.formats.html.markup.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
33 /**
34 * Generate Separate Index Files for all the member names with Indexing in
35 * Unicode Order. This will create "index-files" directory in the current or
36 * destination directory and will generate separate file for each unicode index.
37 *
38 * @see java.lang.Character
39 * @author Atul M Dambalkar
40 * @author Bhavesh Patel (Modified)
41 */
42 public class SplitIndexWriter extends AbstractIndexWriter {
44 /**
45 * Previous unicode character index in the built index.
46 */
47 protected int prev;
49 /**
50 * Next unicode character in the built index.
51 */
52 protected int next;
54 /**
55 * Construct the SplitIndexWriter. Uses path to this file and relative path
56 * from this file.
57 *
58 * @param path Path to the file which is getting generated.
59 * @param filename Name of the file which is getting genrated.
60 * @param relpath Relative path from this file to the current directory.
61 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
62 */
63 public SplitIndexWriter(ConfigurationImpl configuration,
64 String path, String filename,
65 String relpath, IndexBuilder indexbuilder,
66 int prev, int next) throws IOException {
67 super(configuration, path, filename, relpath, indexbuilder);
68 this.prev = prev;
69 this.next = next;
70 }
72 /**
73 * Generate separate index files, for each Unicode character, listing all
74 * the members starting with the particular unicode character.
75 *
76 * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
77 * @throws DocletAbortException
78 */
79 public static void generate(ConfigurationImpl configuration,
80 IndexBuilder indexbuilder) {
81 SplitIndexWriter indexgen;
82 String filename = "";
83 String path = DirectoryManager.getPath("index-files");
84 String relpath = DirectoryManager.getRelativePath("index-files");
85 try {
86 for (int i = 0; i < indexbuilder.elements().length; i++) {
87 int j = i + 1;
88 int prev = (j == 1)? -1: i;
89 int next = (j == indexbuilder.elements().length)? -1: j + 1;
90 filename = "index-" + j +".html";
91 indexgen = new SplitIndexWriter(configuration,
92 path, filename, relpath,
93 indexbuilder, prev, next);
94 indexgen.generateIndexFile((Character)indexbuilder.
95 elements()[i]);
96 indexgen.close();
97 }
98 } catch (IOException exc) {
99 configuration.standardmessage.error(
100 "doclet.exception_encountered",
101 exc.toString(), filename);
102 throw new DocletAbortException();
103 }
104 }
106 /**
107 * Generate the contents of each index file, with Header, Footer,
108 * Member Field, Method and Constructor Description.
109 *
110 * @param unicode Unicode character referring to the character for the
111 * index.
112 */
113 protected void generateIndexFile(Character unicode) throws IOException {
114 String title = configuration.getText("doclet.Window_Split_Index",
115 unicode.toString());
116 Content body = getBody(true, getWindowTitle(title));
117 addTop(body);
118 addNavLinks(true, body);
119 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
120 divTree.addStyle(HtmlStyle.contentContainer);
121 addLinksForIndexes(divTree);
122 addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
123 addLinksForIndexes(divTree);
124 body.addContent(divTree);
125 addNavLinks(false, body);
126 addBottom(body);
127 printHtmlDocument(null, true, body);
128 }
130 /**
131 * Add links for all the Index Files per unicode character.
132 *
133 * @param contentTree the content tree to which the links for indexes will be added
134 */
135 protected void addLinksForIndexes(Content contentTree) {
136 Object[] unicodeChars = indexbuilder.elements();
137 for (int i = 0; i < unicodeChars.length; i++) {
138 int j = i + 1;
139 contentTree.addContent(getHyperLink("index-" + j + ".html",
140 new StringContent(unicodeChars[i].toString())));
141 contentTree.addContent(getSpace());
142 }
143 }
145 /**
146 * Get link to the previous unicode character.
147 *
148 * @return a content tree for the link
149 */
150 public Content getNavLinkPrevious() {
151 Content prevletterLabel = getResource("doclet.Prev_Letter");
152 if (prev == -1) {
153 return HtmlTree.LI(prevletterLabel);
154 }
155 else {
156 Content prevLink = getHyperLink("index-" + prev + ".html", "",
157 prevletterLabel);
158 return HtmlTree.LI(prevLink);
159 }
160 }
162 /**
163 * Get link to the next unicode character.
164 *
165 * @return a content tree for the link
166 */
167 public Content getNavLinkNext() {
168 Content nextletterLabel = getResource("doclet.Next_Letter");
169 if (next == -1) {
170 return HtmlTree.LI(nextletterLabel);
171 }
172 else {
173 Content nextLink = getHyperLink("index-" + next + ".html","",
174 nextletterLabel);
175 return HtmlTree.LI(nextLink);
176 }
177 }
178 }