langtools/src/share/classes/com/sun/tools/doclets/formats/html/SingleIndexWriter.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 10 06bc494ca11e
child 5520 86e4b9a9da40
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.formats.html;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * Generate only one index file for all the Member Names with Indexing in
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Unicode Order. The name of the generated file is "index-all.html" and it is
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * generated in current or the destination directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * @see java.lang.Character
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
public class SingleIndexWriter extends AbstractIndexWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
     * Construct the SingleIndexWriter with filename "index-all.html" and the
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
     * {@link IndexBuilder}
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
     * @param filename     Name of the index file to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     * @param indexbuilder Unicode based Index from {@link IndexBuilder}
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    public SingleIndexWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
                             String filename,
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
                             IndexBuilder indexbuilder) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        super(configuration, filename, indexbuilder);
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        relativepathNoSlash = ".";
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        relativePath = "./";
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * Generate single index file, for all Unicode characters.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public static void generate(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
                                IndexBuilder indexbuilder) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        SingleIndexWriter indexgen;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        String filename = "index-all.html";
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            indexgen = new SingleIndexWriter(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
                                             filename, indexbuilder);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            indexgen.generateIndexFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            indexgen.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            configuration.standardmessage.error(
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                        "doclet.exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
                        exc.toString(), filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * Generate the contents of each index file, with Header, Footer,
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * Member Field, Method and Constructor Description.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    protected void generateIndexFile() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        printHtmlHeader(configuration.getText("doclet.Window_Single_Index"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            null, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        printTop();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        navLinks(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        printLinksForIndexes();
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        hr();
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        for (int i = 0; i < indexbuilder.elements().length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            Character unicode = (Character)((indexbuilder.elements())[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            generateContents(unicode, indexbuilder.getMemberList(unicode));
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        printLinksForIndexes();
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        navLinks(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        printBottom();
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        printBodyHtmlEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Print Links for all the Index Files per unicode character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    protected void printLinksForIndexes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        for (int i = 0; i < indexbuilder.elements().length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            String unicode = (indexbuilder.elements())[i].toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            printHyperLink("#_" + unicode + "_", unicode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            print(' ');
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
}