langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SplitIndexWriter.java
changeset 40587 1c355ea550ed
parent 40303 96a1226aca18
child 45417 f7479ee8de69
equal deleted inserted replaced
40519:e17429a7e843 40587:1c355ea550ed
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.formats.html;
    26 package jdk.javadoc.internal.doclets.formats.html;
    27 
    27 
    28 import java.io.*;
       
    29 import java.util.ArrayList;
    28 import java.util.ArrayList;
    30 import java.util.Collection;
    29 import java.util.Collection;
    31 import java.util.List;
    30 import java.util.List;
    32 import java.util.ListIterator;
    31 import java.util.ListIterator;
    33 import java.util.Set;
    32 import java.util.Set;
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    39 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
    38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
    40 import jdk.javadoc.internal.doclets.toolkit.Content;
    39 import jdk.javadoc.internal.doclets.toolkit.Content;
    41 import jdk.javadoc.internal.doclets.toolkit.Messages;
    40 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
    42 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    41 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    43 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    42 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    44 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
       
    45 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
    43 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
    46 
    44 
    47 
    45 
    48 /**
    46 /**
    49  * Generate Separate Index Files for all the member names with Indexing in
    47  * Generate Separate Index Files for all the member names with Indexing in
    69     /**
    67     /**
    70      * Next unicode character in the built index.
    68      * Next unicode character in the built index.
    71      */
    69      */
    72     protected int next;
    70     protected int next;
    73 
    71 
    74     private List<Character> indexElements;
    72     private final List<Character> indexElements;
    75 
    73 
    76     /**
    74     /**
    77      * Construct the SplitIndexWriter. Uses path to this file and relative path
    75      * Construct the SplitIndexWriter. Uses path to this file and relative path
    78      * from this file.
    76      * from this file.
    79      *
    77      *
       
    78      * @param configuration the configuration for this doclet
    80      * @param path       Path to the file which is getting generated.
    79      * @param path       Path to the file which is getting generated.
    81      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
    80      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
       
    81      * @param elements the collection of characters for which to generate index files
       
    82      * @param prev  the previous character that was indexed
       
    83      * @param next  the next character to be indexed
    82      */
    84      */
    83     public SplitIndexWriter(ConfigurationImpl configuration,
    85     public SplitIndexWriter(ConfigurationImpl configuration,
    84                             DocPath path,
    86                             DocPath path,
    85                             IndexBuilder indexbuilder,
    87                             IndexBuilder indexbuilder,
    86                             Collection<Character> elements,
    88                             Collection<Character> elements,
    87                             int prev, int next) throws IOException {
    89                             int prev, int next) {
    88         super(configuration, path, indexbuilder);
    90         super(configuration, path, indexbuilder);
    89         this.indexElements = new ArrayList<>(elements);
    91         this.indexElements = new ArrayList<>(elements);
    90         this.prev = prev;
    92         this.prev = prev;
    91         this.next = next;
    93         this.next = next;
    92     }
    94     }
    93 
    95 
    94     /**
    96     /**
    95      * Generate separate index files, for each Unicode character, listing all
    97      * Generate separate index files, for each Unicode character, listing all
    96      * the members starting with the particular unicode character.
    98      * the members starting with the particular unicode character.
    97      *
    99      *
       
   100      * @param configuration the configuration for this doclet
    98      * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
   101      * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
    99      * @throws DocletAbortException
   102      * @throws DocFileIOException if there is a problem generating the index files
   100      */
   103      */
   101     public static void generate(ConfigurationImpl configuration,
   104     public static void generate(ConfigurationImpl configuration,
   102                                 IndexBuilder indexbuilder) {
   105                                 IndexBuilder indexbuilder) throws DocFileIOException {
   103         SplitIndexWriter indexgen;
       
   104         DocPath filename = DocPath.empty;
       
   105         DocPath path = DocPaths.INDEX_FILES;
   106         DocPath path = DocPaths.INDEX_FILES;
   106         try {
   107         Set<Character> keys = new TreeSet<>(indexbuilder.getIndexMap().keySet());
   107             Set<Character> keys = new TreeSet<>(indexbuilder.getIndexMap().keySet());
   108         keys.addAll(configuration.tagSearchIndexKeys);
   108             keys.addAll(configuration.tagSearchIndexKeys);
   109         ListIterator<Character> li = new ArrayList<>(keys).listIterator();
   109             ListIterator<Character> li = new ArrayList<>(keys).listIterator();
   110         while (li.hasNext()) {
   110             while (li.hasNext()) {
   111             Object ch = li.next();
   111                 Object ch = li.next();
   112             DocPath filename = DocPaths.indexN(li.nextIndex());
   112                 filename = DocPaths.indexN(li.nextIndex());
   113             SplitIndexWriter indexgen = new SplitIndexWriter(configuration,
   113                 indexgen = new SplitIndexWriter(configuration,
   114                     path.resolve(filename),
   114                         path.resolve(filename),
   115                     indexbuilder, keys, li.previousIndex(), li.nextIndex());
   115                         indexbuilder, keys, li.previousIndex(), li.nextIndex());
   116             indexgen.generateIndexFile((Character) ch);
   116                 indexgen.generateIndexFile((Character) ch);
   117             if (!li.hasNext()) {
   117                 if (!li.hasNext()) {
   118                 indexgen.createSearchIndexFiles();
   118                     indexgen.createSearchIndexFiles();
       
   119                 }
       
   120             }
   119             }
   121         } catch (IOException exc) {
       
   122             Messages messages = configuration.getMessages();
       
   123             messages.error("doclet.exception_encountered",
       
   124                         exc.toString(), filename.getPath());
       
   125             throw new DocletAbortException(exc);
       
   126         }
   120         }
   127     }
   121     }
   128 
   122 
   129     /**
   123     /**
   130      * Generate the contents of each index file, with Header, Footer,
   124      * Generate the contents of each index file, with Header, Footer,
   131      * Member Field, Method and Constructor Description.
   125      * Member Field, Method and Constructor Description.
   132      *
   126      *
   133      * @param unicode Unicode character referring to the character for the
   127      * @param unicode Unicode character referring to the character for the
   134      * index.
   128      * index.
   135      */
   129      * @throws DocFileIOException if there is a problem generating an index file
   136     protected void generateIndexFile(Character unicode) throws IOException {
   130      */
       
   131     protected void generateIndexFile(Character unicode) throws DocFileIOException {
   137         String title = configuration.getText("doclet.Window_Split_Index",
   132         String title = configuration.getText("doclet.Window_Split_Index",
   138                 unicode.toString());
   133                 unicode.toString());
   139         HtmlTree body = getBody(true, getWindowTitle(title));
   134         HtmlTree body = getBody(true, getWindowTitle(title));
   140         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
   135         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
   141                 ? HtmlTree.HEADER()
   136                 ? HtmlTree.HEADER()
   186     /**
   181     /**
   187      * Get link to the previous unicode character.
   182      * Get link to the previous unicode character.
   188      *
   183      *
   189      * @return a content tree for the link
   184      * @return a content tree for the link
   190      */
   185      */
       
   186     @Override
   191     public Content getNavLinkPrevious() {
   187     public Content getNavLinkPrevious() {
   192         Content prevletterLabel = contents.prevLetter;
   188         Content prevletterLabel = contents.prevLetter;
   193         if (prev == -1) {
   189         if (prev == -1) {
   194             return HtmlTree.LI(prevletterLabel);
   190             return HtmlTree.LI(prevletterLabel);
   195         }
   191         }
   203     /**
   199     /**
   204      * Get link to the next unicode character.
   200      * Get link to the next unicode character.
   205      *
   201      *
   206      * @return a content tree for the link
   202      * @return a content tree for the link
   207      */
   203      */
       
   204     @Override
   208     public Content getNavLinkNext() {
   205     public Content getNavLinkNext() {
   209         Content nextletterLabel = contents.nextLetter;
   206         Content nextletterLabel = contents.nextLetter;
   210         if (next == -1) {
   207         if (next == -1) {
   211             return HtmlTree.LI(nextletterLabel);
   208             return HtmlTree.LI(nextletterLabel);
   212         }
   209         }