duke@1: /* duke@1: * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: import java.io.*; duke@1: duke@1: /** duke@1: * Generate Separate Index Files for all the member names with Indexing in duke@1: * Unicode Order. This will create "index-files" directory in the current or duke@1: * destination directory and will generate separate file for each unicode index. duke@1: * duke@1: * @see java.lang.Character duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public class SplitIndexWriter extends AbstractIndexWriter { duke@1: duke@1: /** duke@1: * Previous unicode character index in the built index. duke@1: */ duke@1: protected int prev; duke@1: duke@1: /** duke@1: * Next unicode character in the built index. duke@1: */ duke@1: protected int next; duke@1: duke@1: /** duke@1: * Construct the SplitIndexWriter. Uses path to this file and relative path duke@1: * from this file. duke@1: * duke@1: * @param path Path to the file which is getting generated. duke@1: * @param filename Name of the file which is getting genrated. duke@1: * @param relpath Relative path from this file to the current directory. duke@1: * @param indexbuilder Unicode based Index from {@link IndexBuilder} duke@1: */ duke@1: public SplitIndexWriter(ConfigurationImpl configuration, duke@1: String path, String filename, duke@1: String relpath, IndexBuilder indexbuilder, duke@1: int prev, int next) throws IOException { duke@1: super(configuration, path, filename, relpath, indexbuilder); duke@1: this.prev = prev; duke@1: this.next = next; duke@1: } duke@1: duke@1: /** duke@1: * Generate separate index files, for each Unicode character, listing all duke@1: * the members starting with the particular unicode character. duke@1: * duke@1: * @param indexbuilder IndexBuilder built by {@link IndexBuilder} duke@1: * @throws DocletAbortException duke@1: */ duke@1: public static void generate(ConfigurationImpl configuration, duke@1: IndexBuilder indexbuilder) { duke@1: SplitIndexWriter indexgen; duke@1: String filename = ""; duke@1: String path = DirectoryManager.getPath("index-files"); duke@1: String relpath = DirectoryManager.getRelativePath("index-files"); duke@1: try { duke@1: for (int i = 0; i < indexbuilder.elements().length; i++) { duke@1: int j = i + 1; duke@1: int prev = (j == 1)? -1: i; duke@1: int next = (j == indexbuilder.elements().length)? -1: j + 1; duke@1: filename = "index-" + j +".html"; duke@1: indexgen = new SplitIndexWriter(configuration, duke@1: path, filename, relpath, duke@1: indexbuilder, prev, next); duke@1: indexgen.generateIndexFile((Character)indexbuilder. duke@1: elements()[i]); duke@1: indexgen.close(); duke@1: } duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( duke@1: "doclet.exception_encountered", duke@1: exc.toString(), filename); duke@1: throw new DocletAbortException(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate the contents of each index file, with Header, Footer, duke@1: * Member Field, Method and Constructor Description. duke@1: * duke@1: * @param unicode Unicode character referring to the character for the duke@1: * index. duke@1: */ duke@1: protected void generateIndexFile(Character unicode) throws IOException { duke@1: printHtmlHeader(configuration.getText("doclet.Window_Split_Index", duke@1: unicode.toString()), null, true); duke@1: printTop(); duke@1: navLinks(true); duke@1: printLinksForIndexes(); duke@1: duke@1: hr(); duke@1: duke@1: generateContents(unicode, indexbuilder.getMemberList(unicode)); duke@1: duke@1: navLinks(false); duke@1: printLinksForIndexes(); duke@1: duke@1: printBottom(); duke@1: printBodyHtmlEnd(); duke@1: } duke@1: duke@1: /** duke@1: * Print Links for all the Index Files per unicode character. duke@1: */ duke@1: protected void printLinksForIndexes() { duke@1: for (int i = 0; i < indexbuilder.elements().length; i++) { duke@1: int j = i + 1; duke@1: printHyperLink("index-" + j + ".html", duke@1: indexbuilder.elements()[i].toString()); duke@1: print(' '); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the previous unicode character index link. duke@1: */ duke@1: protected void navLinkPrevious() { duke@1: if (prev == -1) { duke@1: printText("doclet.Prev_Letter"); duke@1: } else { duke@1: printHyperLink("index-" + prev + ".html", "", duke@1: configuration.getText("doclet.Prev_Letter"), true); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the next unicode character index link. duke@1: */ duke@1: protected void navLinkNext() { duke@1: if (next == -1) { duke@1: printText("doclet.Next_Letter"); duke@1: } else { duke@1: printHyperLink("index-" + next + ".html","", duke@1: configuration.getText("doclet.Next_Letter"), true); duke@1: } duke@1: } duke@1: }