001: /*
002: * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html;
027:
028: import com.sun.tools.doclets.internal.toolkit.util.*;
029:
030: import java.io.*;
031:
032: /**
033: * Generate Separate Index Files for all the member names with Indexing in
034: * Unicode Order. This will create "index-files" directory in the current or
035: * destination directory and will generate separate file for each unicode index.
036: *
037: * @see java.lang.Character
038: * @author Atul M Dambalkar
039: */
040: public class SplitIndexWriter extends AbstractIndexWriter {
041:
042: /**
043: * Previous unicode character index in the built index.
044: */
045: protected int prev;
046:
047: /**
048: * Next unicode character in the built index.
049: */
050: protected int next;
051:
052: /**
053: * Construct the SplitIndexWriter. Uses path to this file and relative path
054: * from this file.
055: *
056: * @param path Path to the file which is getting generated.
057: * @param filename Name of the file which is getting genrated.
058: * @param relpath Relative path from this file to the current directory.
059: * @param indexbuilder Unicode based Index from {@link IndexBuilder}
060: */
061: public SplitIndexWriter(ConfigurationImpl configuration,
062: String path, String filename, String relpath,
063: IndexBuilder indexbuilder, int prev, int next)
064: throws IOException {
065: super (configuration, path, filename, relpath, indexbuilder);
066: this .prev = prev;
067: this .next = next;
068: }
069:
070: /**
071: * Generate separate index files, for each Unicode character, listing all
072: * the members starting with the particular unicode character.
073: *
074: * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
075: * @throws DocletAbortException
076: */
077: public static void generate(ConfigurationImpl configuration,
078: IndexBuilder indexbuilder) {
079: SplitIndexWriter indexgen;
080: String filename = "";
081: String path = DirectoryManager.getPath("index-files");
082: String relpath = DirectoryManager
083: .getRelativePath("index-files");
084: try {
085: for (int i = 0; i < indexbuilder.elements().length; i++) {
086: int j = i + 1;
087: int prev = (j == 1) ? -1 : i;
088: int next = (j == indexbuilder.elements().length) ? -1
089: : j + 1;
090: filename = "index-" + j + ".html";
091: indexgen = new SplitIndexWriter(configuration, path,
092: filename, relpath, indexbuilder, prev, next);
093: indexgen.generateIndexFile((Character) indexbuilder
094: .elements()[i]);
095: indexgen.close();
096: }
097: } catch (IOException exc) {
098: configuration.standardmessage.error(
099: "doclet.exception_encountered", exc.toString(),
100: filename);
101: throw new DocletAbortException();
102: }
103: }
104:
105: /**
106: * Generate the contents of each index file, with Header, Footer,
107: * Member Field, Method and Constructor Description.
108: *
109: * @param unicode Unicode character referring to the character for the
110: * index.
111: */
112: protected void generateIndexFile(Character unicode)
113: throws IOException {
114: printHtmlHeader(configuration.getText(
115: "doclet.Window_Split_Index", unicode.toString()), null,
116: true);
117: printTop();
118: navLinks(true);
119: printLinksForIndexes();
120:
121: hr();
122:
123: generateContents(unicode, indexbuilder.getMemberList(unicode));
124:
125: navLinks(false);
126: printLinksForIndexes();
127:
128: printBottom();
129: printBodyHtmlEnd();
130: }
131:
132: /**
133: * Print Links for all the Index Files per unicode character.
134: */
135: protected void printLinksForIndexes() {
136: for (int i = 0; i < indexbuilder.elements().length; i++) {
137: int j = i + 1;
138: printHyperLink("index-" + j + ".html", indexbuilder
139: .elements()[i].toString());
140: print(' ');
141: }
142: }
143:
144: /**
145: * Print the previous unicode character index link.
146: */
147: protected void navLinkPrevious() {
148: if (prev == -1) {
149: printText("doclet.Prev_Letter");
150: } else {
151: printHyperLink("index-" + prev + ".html", "", configuration
152: .getText("doclet.Prev_Letter"), true);
153: }
154: }
155:
156: /**
157: * Print the next unicode character index link.
158: */
159: protected void navLinkNext() {
160: if (next == -1) {
161: printText("doclet.Next_Letter");
162: } else {
163: printHyperLink("index-" + next + ".html", "", configuration
164: .getText("doclet.Next_Letter"), true);
165: }
166: }
167: }
|