Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 30 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 31 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 32 | |
duke@1 | 33 | /** |
duke@1 | 34 | * Generate Separate Index Files for all the member names with Indexing in |
duke@1 | 35 | * Unicode Order. This will create "index-files" directory in the current or |
duke@1 | 36 | * destination directory and will generate separate file for each unicode index. |
duke@1 | 37 | * |
duke@1 | 38 | * @see java.lang.Character |
duke@1 | 39 | * @author Atul M Dambalkar |
bpatel@766 | 40 | * @author Bhavesh Patel (Modified) |
duke@1 | 41 | */ |
duke@1 | 42 | public class SplitIndexWriter extends AbstractIndexWriter { |
duke@1 | 43 | |
duke@1 | 44 | /** |
duke@1 | 45 | * Previous unicode character index in the built index. |
duke@1 | 46 | */ |
duke@1 | 47 | protected int prev; |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * Next unicode character in the built index. |
duke@1 | 51 | */ |
duke@1 | 52 | protected int next; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * Construct the SplitIndexWriter. Uses path to this file and relative path |
duke@1 | 56 | * from this file. |
duke@1 | 57 | * |
duke@1 | 58 | * @param path Path to the file which is getting generated. |
duke@1 | 59 | * @param filename Name of the file which is getting genrated. |
duke@1 | 60 | * @param relpath Relative path from this file to the current directory. |
duke@1 | 61 | * @param indexbuilder Unicode based Index from {@link IndexBuilder} |
duke@1 | 62 | */ |
duke@1 | 63 | public SplitIndexWriter(ConfigurationImpl configuration, |
duke@1 | 64 | String path, String filename, |
duke@1 | 65 | String relpath, IndexBuilder indexbuilder, |
duke@1 | 66 | int prev, int next) throws IOException { |
duke@1 | 67 | super(configuration, path, filename, relpath, indexbuilder); |
duke@1 | 68 | this.prev = prev; |
duke@1 | 69 | this.next = next; |
duke@1 | 70 | } |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Generate separate index files, for each Unicode character, listing all |
duke@1 | 74 | * the members starting with the particular unicode character. |
duke@1 | 75 | * |
duke@1 | 76 | * @param indexbuilder IndexBuilder built by {@link IndexBuilder} |
duke@1 | 77 | * @throws DocletAbortException |
duke@1 | 78 | */ |
duke@1 | 79 | public static void generate(ConfigurationImpl configuration, |
duke@1 | 80 | IndexBuilder indexbuilder) { |
duke@1 | 81 | SplitIndexWriter indexgen; |
duke@1 | 82 | String filename = ""; |
duke@1 | 83 | String path = DirectoryManager.getPath("index-files"); |
duke@1 | 84 | String relpath = DirectoryManager.getRelativePath("index-files"); |
duke@1 | 85 | try { |
duke@1 | 86 | for (int i = 0; i < indexbuilder.elements().length; i++) { |
duke@1 | 87 | int j = i + 1; |
duke@1 | 88 | int prev = (j == 1)? -1: i; |
duke@1 | 89 | int next = (j == indexbuilder.elements().length)? -1: j + 1; |
duke@1 | 90 | filename = "index-" + j +".html"; |
duke@1 | 91 | indexgen = new SplitIndexWriter(configuration, |
duke@1 | 92 | path, filename, relpath, |
duke@1 | 93 | indexbuilder, prev, next); |
duke@1 | 94 | indexgen.generateIndexFile((Character)indexbuilder. |
duke@1 | 95 | elements()[i]); |
duke@1 | 96 | indexgen.close(); |
duke@1 | 97 | } |
duke@1 | 98 | } catch (IOException exc) { |
duke@1 | 99 | configuration.standardmessage.error( |
duke@1 | 100 | "doclet.exception_encountered", |
duke@1 | 101 | exc.toString(), filename); |
duke@1 | 102 | throw new DocletAbortException(); |
duke@1 | 103 | } |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * Generate the contents of each index file, with Header, Footer, |
duke@1 | 108 | * Member Field, Method and Constructor Description. |
duke@1 | 109 | * |
duke@1 | 110 | * @param unicode Unicode character referring to the character for the |
duke@1 | 111 | * index. |
duke@1 | 112 | */ |
duke@1 | 113 | protected void generateIndexFile(Character unicode) throws IOException { |
bpatel@766 | 114 | String title = configuration.getText("doclet.Window_Split_Index", |
bpatel@766 | 115 | unicode.toString()); |
bpatel@766 | 116 | Content body = getBody(true, getWindowTitle(title)); |
bpatel@766 | 117 | addTop(body); |
bpatel@766 | 118 | addNavLinks(true, body); |
bpatel@766 | 119 | HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 120 | divTree.addStyle(HtmlStyle.contentContainer); |
bpatel@766 | 121 | addLinksForIndexes(divTree); |
bpatel@766 | 122 | addContents(unicode, indexbuilder.getMemberList(unicode), divTree); |
bpatel@766 | 123 | addLinksForIndexes(divTree); |
bpatel@766 | 124 | body.addContent(divTree); |
bpatel@766 | 125 | addNavLinks(false, body); |
bpatel@766 | 126 | addBottom(body); |
bpatel@766 | 127 | printHtmlDocument(null, true, body); |
duke@1 | 128 | } |
duke@1 | 129 | |
duke@1 | 130 | /** |
bpatel@766 | 131 | * Add links for all the Index Files per unicode character. |
bpatel@766 | 132 | * |
bpatel@766 | 133 | * @param contentTree the content tree to which the links for indexes will be added |
duke@1 | 134 | */ |
bpatel@766 | 135 | protected void addLinksForIndexes(Content contentTree) { |
bpatel@766 | 136 | Object[] unicodeChars = indexbuilder.elements(); |
bpatel@766 | 137 | for (int i = 0; i < unicodeChars.length; i++) { |
duke@1 | 138 | int j = i + 1; |
bpatel@766 | 139 | contentTree.addContent(getHyperLink("index-" + j + ".html", |
bpatel@766 | 140 | new StringContent(unicodeChars[i].toString()))); |
bpatel@766 | 141 | contentTree.addContent(getSpace()); |
duke@1 | 142 | } |
duke@1 | 143 | } |
duke@1 | 144 | |
duke@1 | 145 | /** |
bpatel@766 | 146 | * Get link to the previous unicode character. |
bpatel@766 | 147 | * |
bpatel@766 | 148 | * @return a content tree for the link |
duke@1 | 149 | */ |
bpatel@766 | 150 | public Content getNavLinkPrevious() { |
bpatel@766 | 151 | Content prevletterLabel = getResource("doclet.Prev_Letter"); |
duke@1 | 152 | if (prev == -1) { |
bpatel@766 | 153 | return HtmlTree.LI(prevletterLabel); |
bpatel@766 | 154 | } |
bpatel@766 | 155 | else { |
bpatel@766 | 156 | Content prevLink = getHyperLink("index-" + prev + ".html", "", |
bpatel@766 | 157 | prevletterLabel); |
bpatel@766 | 158 | return HtmlTree.LI(prevLink); |
duke@1 | 159 | } |
duke@1 | 160 | } |
duke@1 | 161 | |
duke@1 | 162 | /** |
bpatel@766 | 163 | * Get link to the next unicode character. |
bpatel@766 | 164 | * |
bpatel@766 | 165 | * @return a content tree for the link |
duke@1 | 166 | */ |
bpatel@766 | 167 | public Content getNavLinkNext() { |
bpatel@766 | 168 | Content nextletterLabel = getResource("doclet.Next_Letter"); |
duke@1 | 169 | if (next == -1) { |
bpatel@766 | 170 | return HtmlTree.LI(nextletterLabel); |
bpatel@766 | 171 | } |
bpatel@766 | 172 | else { |
bpatel@766 | 173 | Content nextLink = getHyperLink("index-" + next + ".html","", |
bpatel@766 | 174 | nextletterLabel); |
bpatel@766 | 175 | return HtmlTree.LI(nextLink); |
duke@1 | 176 | } |
duke@1 | 177 | } |
duke@1 | 178 | } |