home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / tooldocs / javadoc / source / standard / SplitIndexWriter.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  5.1 KB  |  153 lines

  1. /*
  2.  * @(#)SplitIndexWriter.java    1.11 98/08/18
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package com.sun.tools.doclets.standard;
  16.  
  17. import com.sun.tools.doclets.*;
  18. import com.sun.javadoc.*;
  19. import java.io.*;
  20. import java.lang.*;
  21. import java.util.*;
  22.  
  23. /**
  24.  * Generate Separate Index Files for all the member names with Indexing in
  25.  * Unicode Order. This will create "index-files" directory in the current or
  26.  * destination directory and will generate separate file for each unicode index.
  27.  *
  28.  * @see java.lang.Character
  29.  * @author Atul M Dambalkar
  30.  */
  31. public class SplitIndexWriter extends AbstractIndexWriter {
  32.  
  33.     /**
  34.      * Previous unicode character index in the built index.
  35.      */
  36.     protected int prev;
  37.  
  38.     /**
  39.      * Next unicode character in the built index.
  40.      */
  41.     protected int next;
  42.  
  43.     /**
  44.      * Construct the SplitIndexWriter. Uses path to this file and relative path
  45.      * from this file.
  46.      * 
  47.      * @param path       Path to the file which is getting generated.
  48.      * @param filename   Name of the file which is getting genrated.
  49.      * @param relpath    Relative path from this file to the current directory.
  50.      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
  51.      */
  52.     public SplitIndexWriter(String path, String filename, 
  53.                             String relpath, IndexBuilder indexbuilder,
  54.                             int prev, int next) throws IOException {
  55.         super(path, filename, relpath, indexbuilder);
  56.         this.prev = prev;
  57.         this.next = next;
  58.     }
  59.  
  60.     /**
  61.      * Generate separate index files, for each Unicode character, listing all
  62.      * the members starting with the particular unicode character.
  63.      * 
  64.      * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
  65.      */
  66.     public static void generate(IndexBuilder indexbuilder) 
  67.                                 throws DocletAbortException {
  68.         SplitIndexWriter indexgen;
  69.         String filename = "";
  70.         String path = DirectoryManager.getPath("index-files");
  71.         String relpath = DirectoryManager.getRelativePath("index-files");
  72.         try {
  73.             for (int i = 0; i < indexbuilder.elements().length; i++) {
  74.                 int j = i + 1;
  75.                 int prev = (j == 1)? -1: i;
  76.                 int next = (j == indexbuilder.elements().length)? -1: j + 1;
  77.                 filename = "index-" + j +".html";
  78.                 indexgen = new SplitIndexWriter(path, filename, relpath,
  79.                                                 indexbuilder, prev, next);
  80.                 indexgen.generateIndexFile((Character)indexbuilder.
  81.                                                                  elements()[i]);
  82.                 indexgen.close();
  83.             }
  84.         } catch (IOException exc) {
  85.  Standard.configuration().standardmessage.error("doclet.exception_encountered",
  86.                                                  exc.toString(), filename);
  87.             throw new DocletAbortException();
  88.         }
  89.     }
  90.  
  91.     /**
  92.      * Generate the contents of each index file, with Header, Footer, 
  93.      * Member Field, Method and Constructor Description.
  94.      *
  95.      * @param unicode Unicode character referring to the character for the
  96.      * index.
  97.      */
  98.     protected void generateIndexFile(Character unicode) throws IOException {
  99.         printHeader(getText("doclet.Window_Split_Index",
  100.                             Standard.configuration().windowtitle, 
  101.                             unicode.toString()));
  102.        
  103.         navLinks(true);
  104.         printLinksForIndexes();
  105.         
  106.         hr();
  107.         
  108.         generateContents(unicode, indexbuilder.getMemberList(unicode));
  109.  
  110.         navLinks(false);
  111.         printLinksForIndexes();
  112.         
  113.         printBottom(); 
  114.         printBodyHtmlEnd();
  115.     }
  116.  
  117.     /**
  118.      * Print Links for all the Index Files per unicode character.
  119.      */
  120.     protected void printLinksForIndexes() {
  121.         for (int i = 0; i < indexbuilder.elements().length; i++) {
  122.             int j = i + 1;
  123.             printHyperLink("index-" + j + ".html",
  124.                            indexbuilder.elements()[i].toString());
  125.             print(' ');
  126.         }
  127.     }
  128.   
  129.     /**
  130.      * Print the previous unicode character index link.
  131.      */
  132.     protected void navLinkPrevious() {
  133.         if (prev == -1) {
  134.             printText("doclet.Prev_Letter");
  135.         } else {
  136.             printHyperLink("index-" + prev + ".html", "",
  137.                             getText("doclet.Prev_Letter"), true);
  138.         }
  139.     } 
  140.  
  141.     /**
  142.      * Print the next unicode character index link.
  143.      */
  144.     protected void navLinkNext() {
  145.         if (next == -1) {
  146.             printText("doclet.Next_Letter");
  147.         } else {
  148.             printHyperLink("index-" + next + ".html","",
  149.                             getText("doclet.Next_Letter"), true);
  150.         }
  151.     } 
  152. }
  153.