src/share/classes/com/sun/tools/doclets/formats/html/SplitIndexWriter.java

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1381
23fe1a96bc0f
child 1985
0e6577980181
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

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

mercurial