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 only one index file for all the Member Names with Indexing in
35 * Unicode Order. The name of the generated file is "index-all.html" and it is
36 * generated in current or the destination directory.
37 *
38 * @see java.lang.Character
39 * @author Atul M Dambalkar
40 * @author Bhavesh Patel (Modified)
41 */
42 public class SingleIndexWriter extends AbstractIndexWriter {
44 /**
45 * Construct the SingleIndexWriter with filename "index-all.html" and the
46 * {@link IndexBuilder}
47 *
48 * @param filename Name of the index file to be generated.
49 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
50 */
51 public SingleIndexWriter(ConfigurationImpl configuration,
52 String filename,
53 IndexBuilder indexbuilder) throws IOException {
54 super(configuration, filename, indexbuilder);
55 relativepathNoSlash = ".";
56 relativePath = "./";
57 }
59 /**
60 * Generate single index file, for all Unicode characters.
61 *
62 * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
63 * @throws DocletAbortException
64 */
65 public static void generate(ConfigurationImpl configuration,
66 IndexBuilder indexbuilder) {
67 SingleIndexWriter indexgen;
68 String filename = "index-all.html";
69 try {
70 indexgen = new SingleIndexWriter(configuration,
71 filename, indexbuilder);
72 indexgen.generateIndexFile();
73 indexgen.close();
74 } catch (IOException exc) {
75 configuration.standardmessage.error(
76 "doclet.exception_encountered",
77 exc.toString(), filename);
78 throw new DocletAbortException();
79 }
80 }
82 /**
83 * Generate the contents of each index file, with Header, Footer,
84 * Member Field, Method and Constructor Description.
85 */
86 protected void generateIndexFile() throws IOException {
87 String title = configuration.getText("doclet.Window_Single_Index");
88 Content body = getBody(true, getWindowTitle(title));
89 addTop(body);
90 addNavLinks(true, body);
91 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
92 divTree.addStyle(HtmlStyle.contentContainer);
93 addLinksForIndexes(divTree);
94 for (int i = 0; i < indexbuilder.elements().length; i++) {
95 Character unicode = (Character)((indexbuilder.elements())[i]);
96 addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
97 }
98 addLinksForIndexes(divTree);
99 body.addContent(divTree);
100 addNavLinks(false, body);
101 addBottom(body);
102 printHtmlDocument(null, true, body);
103 }
105 /**
106 * Add links for all the Index Files per unicode character.
107 *
108 * @param contentTree the content tree to which the links for indexes will be added
109 */
110 protected void addLinksForIndexes(Content contentTree) {
111 for (int i = 0; i < indexbuilder.elements().length; i++) {
112 String unicode = (indexbuilder.elements())[i].toString();
113 contentTree.addContent(
114 getHyperLink("#_" + unicode + "_", new StringContent(unicode)));
115 contentTree.addContent(getSpace());
116 }
117 }
118 }