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

Thu, 15 Nov 2012 19:54:20 -0800

author
jjg
date
Thu, 15 Nov 2012 19:54:20 -0800
changeset 1412
400a4e8accd3
parent 1372
78962d89f283
child 1985
0e6577980181
permissions
-rw-r--r--

8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy

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 only one index file for all the Member Names with Indexing in
duke@1 36 * Unicode Order. The name of the generated file is "index-all.html" and it is
duke@1 37 * generated in current or the destination directory.
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 SingleIndexWriter extends AbstractIndexWriter {
duke@1 49
duke@1 50 /**
duke@1 51 * Construct the SingleIndexWriter with filename "index-all.html" and the
duke@1 52 * {@link IndexBuilder}
duke@1 53 *
duke@1 54 * @param filename Name of the index file to be generated.
duke@1 55 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
duke@1 56 */
duke@1 57 public SingleIndexWriter(ConfigurationImpl configuration,
jjg@1372 58 DocPath filename,
duke@1 59 IndexBuilder indexbuilder) throws IOException {
duke@1 60 super(configuration, filename, indexbuilder);
duke@1 61 }
duke@1 62
duke@1 63 /**
duke@1 64 * Generate single index file, for all Unicode characters.
duke@1 65 *
duke@1 66 * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
duke@1 67 * @throws DocletAbortException
duke@1 68 */
duke@1 69 public static void generate(ConfigurationImpl configuration,
duke@1 70 IndexBuilder indexbuilder) {
duke@1 71 SingleIndexWriter indexgen;
jjg@1372 72 DocPath filename = DocPaths.INDEX_ALL;
duke@1 73 try {
duke@1 74 indexgen = new SingleIndexWriter(configuration,
duke@1 75 filename, indexbuilder);
duke@1 76 indexgen.generateIndexFile();
duke@1 77 indexgen.close();
duke@1 78 } catch (IOException exc) {
duke@1 79 configuration.standardmessage.error(
duke@1 80 "doclet.exception_encountered",
duke@1 81 exc.toString(), filename);
duke@1 82 throw new DocletAbortException();
duke@1 83 }
duke@1 84 }
duke@1 85
duke@1 86 /**
duke@1 87 * Generate the contents of each index file, with Header, Footer,
duke@1 88 * Member Field, Method and Constructor Description.
duke@1 89 */
duke@1 90 protected void generateIndexFile() throws IOException {
bpatel@766 91 String title = configuration.getText("doclet.Window_Single_Index");
bpatel@766 92 Content body = getBody(true, getWindowTitle(title));
bpatel@766 93 addTop(body);
bpatel@766 94 addNavLinks(true, body);
bpatel@766 95 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
bpatel@766 96 divTree.addStyle(HtmlStyle.contentContainer);
bpatel@766 97 addLinksForIndexes(divTree);
duke@1 98 for (int i = 0; i < indexbuilder.elements().length; i++) {
duke@1 99 Character unicode = (Character)((indexbuilder.elements())[i]);
bpatel@766 100 addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
duke@1 101 }
bpatel@766 102 addLinksForIndexes(divTree);
bpatel@766 103 body.addContent(divTree);
bpatel@766 104 addNavLinks(false, body);
bpatel@766 105 addBottom(body);
bpatel@766 106 printHtmlDocument(null, true, body);
duke@1 107 }
duke@1 108
duke@1 109 /**
bpatel@766 110 * Add links for all the Index Files per unicode character.
bpatel@766 111 *
bpatel@766 112 * @param contentTree the content tree to which the links for indexes will be added
duke@1 113 */
bpatel@766 114 protected void addLinksForIndexes(Content contentTree) {
duke@1 115 for (int i = 0; i < indexbuilder.elements().length; i++) {
duke@1 116 String unicode = (indexbuilder.elements())[i].toString();
bpatel@766 117 contentTree.addContent(
jjg@1372 118 getHyperLink("_" + unicode + "_", new StringContent(unicode)));
bpatel@766 119 contentTree.addContent(getSpace());
duke@1 120 }
duke@1 121 }
duke@1 122 }

mercurial