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

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 1998-2005 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package com.sun.tools.doclets.formats.html;
27
28 import com.sun.tools.doclets.internal.toolkit.util.*;
29
30 import java.io.*;
31
32 /**
33 * Generate Separate Index Files for all the member names with Indexing in
34 * Unicode Order. This will create "index-files" directory in the current or
35 * destination directory and will generate separate file for each unicode index.
36 *
37 * @see java.lang.Character
38 * @author Atul M Dambalkar
39 */
40 public class SplitIndexWriter extends AbstractIndexWriter {
41
42 /**
43 * Previous unicode character index in the built index.
44 */
45 protected int prev;
46
47 /**
48 * Next unicode character in the built index.
49 */
50 protected int next;
51
52 /**
53 * Construct the SplitIndexWriter. Uses path to this file and relative path
54 * from this file.
55 *
56 * @param path Path to the file which is getting generated.
57 * @param filename Name of the file which is getting genrated.
58 * @param relpath Relative path from this file to the current directory.
59 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
60 */
61 public SplitIndexWriter(ConfigurationImpl configuration,
62 String path, String filename,
63 String relpath, IndexBuilder indexbuilder,
64 int prev, int next) throws IOException {
65 super(configuration, path, filename, relpath, indexbuilder);
66 this.prev = prev;
67 this.next = next;
68 }
69
70 /**
71 * Generate separate index files, for each Unicode character, listing all
72 * the members starting with the particular unicode character.
73 *
74 * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
75 * @throws DocletAbortException
76 */
77 public static void generate(ConfigurationImpl configuration,
78 IndexBuilder indexbuilder) {
79 SplitIndexWriter indexgen;
80 String filename = "";
81 String path = DirectoryManager.getPath("index-files");
82 String relpath = DirectoryManager.getRelativePath("index-files");
83 try {
84 for (int i = 0; i < indexbuilder.elements().length; i++) {
85 int j = i + 1;
86 int prev = (j == 1)? -1: i;
87 int next = (j == indexbuilder.elements().length)? -1: j + 1;
88 filename = "index-" + j +".html";
89 indexgen = new SplitIndexWriter(configuration,
90 path, filename, relpath,
91 indexbuilder, prev, next);
92 indexgen.generateIndexFile((Character)indexbuilder.
93 elements()[i]);
94 indexgen.close();
95 }
96 } catch (IOException exc) {
97 configuration.standardmessage.error(
98 "doclet.exception_encountered",
99 exc.toString(), filename);
100 throw new DocletAbortException();
101 }
102 }
103
104 /**
105 * Generate the contents of each index file, with Header, Footer,
106 * Member Field, Method and Constructor Description.
107 *
108 * @param unicode Unicode character referring to the character for the
109 * index.
110 */
111 protected void generateIndexFile(Character unicode) throws IOException {
112 printHtmlHeader(configuration.getText("doclet.Window_Split_Index",
113 unicode.toString()), null, true);
114 printTop();
115 navLinks(true);
116 printLinksForIndexes();
117
118 hr();
119
120 generateContents(unicode, indexbuilder.getMemberList(unicode));
121
122 navLinks(false);
123 printLinksForIndexes();
124
125 printBottom();
126 printBodyHtmlEnd();
127 }
128
129 /**
130 * Print Links for all the Index Files per unicode character.
131 */
132 protected void printLinksForIndexes() {
133 for (int i = 0; i < indexbuilder.elements().length; i++) {
134 int j = i + 1;
135 printHyperLink("index-" + j + ".html",
136 indexbuilder.elements()[i].toString());
137 print(' ');
138 }
139 }
140
141 /**
142 * Print the previous unicode character index link.
143 */
144 protected void navLinkPrevious() {
145 if (prev == -1) {
146 printText("doclet.Prev_Letter");
147 } else {
148 printHyperLink("index-" + prev + ".html", "",
149 configuration.getText("doclet.Prev_Letter"), true);
150 }
151 }
152
153 /**
154 * Print the next unicode character index link.
155 */
156 protected void navLinkNext() {
157 if (next == -1) {
158 printText("doclet.Next_Letter");
159 } else {
160 printHyperLink("index-" + next + ".html","",
161 configuration.getText("doclet.Next_Letter"), true);
162 }
163 }
164 }

mercurial