duke@1: /* jjg@1357: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. 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 ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle 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: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@766: import java.io.*; jjg@1357: bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.util.*; 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: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @see java.lang.Character duke@1: * @author Atul M Dambalkar bpatel@766: * @author Bhavesh Patel (Modified) 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 indexbuilder Unicode based Index from {@link IndexBuilder} duke@1: */ duke@1: public SplitIndexWriter(ConfigurationImpl configuration, jjg@1372: DocPath path, jjg@1372: IndexBuilder indexbuilder, duke@1: int prev, int next) throws IOException { jjg@1372: super(configuration, path, 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; jjg@1372: DocPath filename = DocPath.empty; jjg@1372: DocPath path = DocPaths.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; jjg@1372: filename = DocPaths.indexN(j); duke@1: indexgen = new SplitIndexWriter(configuration, jjg@1372: path.resolve(filename), 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", jjg@1372: exc.toString(), filename.getPath()); 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 { bpatel@766: String title = configuration.getText("doclet.Window_Split_Index", bpatel@766: unicode.toString()); bpatel@766: Content body = getBody(true, getWindowTitle(title)); bpatel@766: addTop(body); bpatel@766: addNavLinks(true, body); bpatel@766: HtmlTree divTree = new HtmlTree(HtmlTag.DIV); bpatel@766: divTree.addStyle(HtmlStyle.contentContainer); bpatel@766: addLinksForIndexes(divTree); bpatel@766: addContents(unicode, indexbuilder.getMemberList(unicode), divTree); bpatel@766: addLinksForIndexes(divTree); bpatel@766: body.addContent(divTree); bpatel@766: addNavLinks(false, body); bpatel@766: addBottom(body); bpatel@766: printHtmlDocument(null, true, body); duke@1: } duke@1: duke@1: /** bpatel@766: * Add links for all the Index Files per unicode character. bpatel@766: * bpatel@766: * @param contentTree the content tree to which the links for indexes will be added duke@1: */ bpatel@766: protected void addLinksForIndexes(Content contentTree) { bpatel@766: Object[] unicodeChars = indexbuilder.elements(); bpatel@766: for (int i = 0; i < unicodeChars.length; i++) { duke@1: int j = i + 1; jjg@1372: contentTree.addContent(getHyperLink(DocPaths.indexN(j), bpatel@766: new StringContent(unicodeChars[i].toString()))); bpatel@766: contentTree.addContent(getSpace()); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get link to the previous unicode character. bpatel@766: * bpatel@766: * @return a content tree for the link duke@1: */ bpatel@766: public Content getNavLinkPrevious() { bpatel@766: Content prevletterLabel = getResource("doclet.Prev_Letter"); duke@1: if (prev == -1) { bpatel@766: return HtmlTree.LI(prevletterLabel); bpatel@766: } bpatel@766: else { jjg@1373: Content prevLink = getHyperLink(DocPaths.indexN(prev), bpatel@766: prevletterLabel); bpatel@766: return HtmlTree.LI(prevLink); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get link to the next unicode character. bpatel@766: * bpatel@766: * @return a content tree for the link duke@1: */ bpatel@766: public Content getNavLinkNext() { bpatel@766: Content nextletterLabel = getResource("doclet.Next_Letter"); duke@1: if (next == -1) { bpatel@766: return HtmlTree.LI(nextletterLabel); bpatel@766: } bpatel@766: else { jjg@1373: Content nextLink = getHyperLink(DocPaths.indexN(next), bpatel@766: nextletterLabel); bpatel@766: return HtmlTree.LI(nextLink); duke@1: } duke@1: } duke@1: }