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

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1372
78962d89f283
child 1985
0e6577980181
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    30 import com.sun.tools.doclets.formats.html.markup.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * Generate only one index file for all the Member Names with Indexing in
    36  * Unicode Order. The name of the generated file is "index-all.html" and it is
    37  * generated in current or the destination directory.
    38  *
    39  *  <p><b>This is NOT part of any supported API.
    40  *  If you write code that depends on this, you do so at your own risk.
    41  *  This code and its internal interfaces are subject to change or
    42  *  deletion without notice.</b>
    43  *
    44  * @see java.lang.Character
    45  * @author Atul M Dambalkar
    46  * @author Bhavesh Patel (Modified)
    47  */
    48 public class SingleIndexWriter extends AbstractIndexWriter {
    50     /**
    51      * Construct the SingleIndexWriter with filename "index-all.html" and the
    52      * {@link IndexBuilder}
    53      *
    54      * @param filename     Name of the index file to be generated.
    55      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
    56      */
    57     public SingleIndexWriter(ConfigurationImpl configuration,
    58                              DocPath filename,
    59                              IndexBuilder indexbuilder) throws IOException {
    60         super(configuration, filename, indexbuilder);
    61     }
    63     /**
    64      * Generate single index file, for all Unicode characters.
    65      *
    66      * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
    67      * @throws DocletAbortException
    68      */
    69     public static void generate(ConfigurationImpl configuration,
    70                                 IndexBuilder indexbuilder) {
    71         SingleIndexWriter indexgen;
    72         DocPath filename = DocPaths.INDEX_ALL;
    73         try {
    74             indexgen = new SingleIndexWriter(configuration,
    75                                              filename, indexbuilder);
    76             indexgen.generateIndexFile();
    77             indexgen.close();
    78         } catch (IOException exc) {
    79             configuration.standardmessage.error(
    80                         "doclet.exception_encountered",
    81                         exc.toString(), filename);
    82             throw new DocletAbortException();
    83         }
    84     }
    86     /**
    87      * Generate the contents of each index file, with Header, Footer,
    88      * Member Field, Method and Constructor Description.
    89      */
    90     protected void generateIndexFile() throws IOException {
    91         String title = configuration.getText("doclet.Window_Single_Index");
    92         Content body = getBody(true, getWindowTitle(title));
    93         addTop(body);
    94         addNavLinks(true, body);
    95         HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
    96         divTree.addStyle(HtmlStyle.contentContainer);
    97         addLinksForIndexes(divTree);
    98         for (int i = 0; i < indexbuilder.elements().length; i++) {
    99             Character unicode = (Character)((indexbuilder.elements())[i]);
   100             addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
   101         }
   102         addLinksForIndexes(divTree);
   103         body.addContent(divTree);
   104         addNavLinks(false, body);
   105         addBottom(body);
   106         printHtmlDocument(null, true, body);
   107     }
   109     /**
   110      * Add links for all the Index Files per unicode character.
   111      *
   112      * @param contentTree the content tree to which the links for indexes will be added
   113      */
   114     protected void addLinksForIndexes(Content contentTree) {
   115         for (int i = 0; i < indexbuilder.elements().length; i++) {
   116             String unicode = (indexbuilder.elements())[i].toString();
   117             contentTree.addContent(
   118                     getHyperLink("_" + unicode + "_", new StringContent(unicode)));
   119             contentTree.addContent(getSpace());
   120         }
   121     }
   122 }

mercurial