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 / ConfigurationStandard.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  13.2 KB  |  385 lines

  1. /*
  2.  * @(#)ConfigurationStandard.java    1.13 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.util.*;
  20. import java.io.*;
  21.  
  22. /**
  23.  * Configure the output based on the command line options. 
  24.  * <p> 
  25.  * Also determine the length of the command line option. For example,
  26.  * for a option "-header" there will be a string argument associated, then the
  27.  * the length of option "-header" is two. But for option "-nohelp" no argument 
  28.  * is needed so it's length is 1. 
  29.  * </p>
  30.  * <p>
  31.  * Also do the error checking on the options used. For example it is illegal to
  32.  * use "-helpfile" option when already "-nohelp" option is used.
  33.  * </p> 
  34.  *
  35.  * @author Robert Field.
  36.  * @author Atul Dambalkar.
  37.  */
  38. public class ConfigurationStandard extends Configuration {
  39.  
  40.     /**
  41.      * Argument for command line option "-header".
  42.      */
  43.     public String header = "";
  44.  
  45.     /**
  46.      * Argument for command line option "-footer".
  47.      */
  48.     public String footer = "";
  49.  
  50.     /**
  51.      * Argument for command line option "-doctitle".
  52.      */
  53.     public String doctitle = "";
  54.  
  55.     /**
  56.      * Argument for command line option "-windowtitle".
  57.      */
  58.     public String windowtitle = "";
  59.  
  60.     /**
  61.      * Argument for command line option "-bottom". 
  62.      */
  63.     public String bottom = "";
  64.  
  65.     /**
  66.      * Argument for command line option "-helpfile".
  67.      */
  68.     public String helpfile = "";
  69.  
  70.     /**
  71.      * Argument for command line option "-stylesheetfile".
  72.      */
  73.     public String stylesheetfile = "";
  74.  
  75.     /**
  76.      * True if command line option "-nohelp" is used. Default value is false. 
  77.      */
  78.     public boolean nohelp = false;
  79.  
  80.     /**
  81.      * True if command line option "-splitindex" is used. Default value is
  82.      * false. 
  83.      */
  84.     public boolean splitindex = false;
  85.  
  86.     /**
  87.      * False if command line option "-noindex" is used. Default value is true.
  88.      */
  89.     public boolean createindex = true;
  90.  
  91.     /**
  92.      * True if command line option "-use" is used. Default value is false.
  93.      */
  94.     public boolean classuse = false;
  95.  
  96.     /**
  97.      * False if command line option "-notree" is used. Default value is true.
  98.      */
  99.     public boolean createtree = true;
  100.  
  101.     /**
  102.      * True if command line option "-nodeprecated" is used. Default value is
  103.      * false.
  104.      */
  105.     public boolean nodeprecatedlist = false;
  106.  
  107.     /**
  108.      * True if command line option "-nonavbar" is used. Default value is false.
  109.      */
  110.     public boolean nonavbar = false;
  111.  
  112.     /**
  113.      * True if command line option "-nooverview" is used. Default value is
  114.      * false 
  115.      */
  116.     private boolean nooverview = false;
  117.  
  118.     /**
  119.      * True if command line option "-overview" is used. Default value is false.
  120.      */
  121.     public boolean overview = false;
  122.  
  123.     /**
  124.      * This is true if option "-overview" is used or option "-overview" is not
  125.      * used and number of packages is more than one.
  126.      */
  127.     public boolean createoverview = false;
  128.  
  129.     /**
  130.      * Unique Resource Handler for this package. 
  131.      */
  132.     public static MessageRetriever standardmessage = null;
  133.  
  134.     /**
  135.      * First file to appear in the right-hand frame in the generated 
  136.      * documentation.
  137.      */
  138.     public String topFile = "";
  139.  
  140.     /**
  141.      * Constructor. Initialises resource for the
  142.      * {@link com.sun.tools.doclets.MessageRetriever}.
  143.      */
  144.     public ConfigurationStandard() {
  145.         if (standardmessage == null) {
  146.             standardmessage = 
  147.                new MessageRetriever("com.sun.tools.javadoc.resources.standard");
  148.         }
  149.     }
  150.  
  151.     /**
  152.      * Depending upon the command line options provided by the user, set 
  153.      * configure the output generation environment.
  154.      *
  155.      * @param root Used to retrieve used comand line options.
  156.      */
  157.     public void setSpecificDocletOptions(RootDoc root) {
  158.         String[][] options = root.options();
  159.         for (int oi = 0; oi < options.length; ++oi) {
  160.             String[] os = options[oi];
  161.             String opt = os[0].toLowerCase();
  162.             if (opt.equals("-footer")) {
  163.                 footer =  os[1];
  164.             } else  if (opt.equals("-header")) {
  165.                 header =  os[1];
  166.             } else  if (opt.equals("-doctitle")) {
  167.                 doctitle =  os[1];
  168.             } else  if (opt.equals("-windowtitle")) {
  169.                 windowtitle =  os[1];
  170.             } else  if (opt.equals("-bottom")) {
  171.                 bottom =  os[1];
  172.             } else  if (opt.equals("-helpfile")) {
  173.                 helpfile =  os[1];
  174.             } else  if (opt.equals("-stylesheetfile")) {
  175.                 stylesheetfile =  os[1];
  176.             } else  if (opt.equals("-nohelp")) {
  177.                 nohelp = true;
  178.             } else  if (opt.equals("-splitindex")) {
  179.                 splitindex = true;
  180.             } else  if (opt.equals("-noindex")) {
  181.                 createindex = false;
  182.             } else  if (opt.equals("-use")) {
  183.                 classuse = true;
  184.             } else  if (opt.equals("-notree")) {
  185.                 createtree = false;
  186.             } else  if (opt.equals("-nodeprecatedlist")) {
  187.                 nodeprecatedlist = true;
  188.             } else  if (opt.equals("-nonavbar")) {
  189.                 nonavbar = true;
  190.         } else  if (opt.equals("-nooverview")) {
  191.                 nooverview = true;
  192.         } else  if (opt.equals("-overview")) {
  193.                 overview = true;
  194.             } 
  195.         }
  196.         setCreateOverview();
  197.         setTopFile(root);
  198.     }
  199.  
  200.     /**
  201.      * Check for doclet added options here. This works exactly like 
  202.      * {@link com.sun.tools.doclets.Configuration#optionLength(String)}. This 
  203.      * will return the length of the options which are added by "standard" 
  204.      * doclet.
  205.      *
  206.      * @param option Option whose length is requested.
  207.      * @return number of arguments to option. Zero return means
  208.      * option not known.  Negative value means error occurred. 
  209.      */
  210.     public int specificDocletOptionLength(String option) {
  211.         if (option.equals("-nodeprecatedlist") ||
  212.             option.equals("-noindex") ||
  213.             option.equals("-notree") ||
  214.             option.equals("-nohelp") ||
  215.             option.equals("-splitindex") ||
  216.             option.equals("-use") ||
  217.             option.equals("-nonavbar") ||
  218.             option.equals("-nooverview")) {
  219.             return 1;
  220.         } else if (option.equals("-help") ) {
  221.             standardmessage.notice("doclet.usage");
  222.             return 1;
  223.         } else if (option.equals("-x") ) {
  224.             standardmessage.notice("doclet.xusage");
  225.             return -1; // so run will end
  226.         } else if (option.equals("-footer") ||
  227.                    option.equals("-header") ||
  228.                    option.equals("-doctitle") ||
  229.                    option.equals("-windowtitle") ||
  230.                    option.equals("-bottom") ||
  231.                    option.equals("-helpfile") ||
  232.                    option.equals("-stylesheetfile") ||
  233.                    option.equals("-link") ||
  234.                    option.equals("-overview")) {
  235.             return 2;
  236.         } else if (option.equals("-group") ||
  237.                    option.equals("-linkoffline")) {
  238.             return 3;
  239.         } else {
  240.             return 0;
  241.         }
  242.     }
  243.  
  244.     /**
  245.      * This checks for the validity of the options used by the user. This works 
  246.      * exactly like
  247.      * {@link com.sun.tools.doclets.Configuration#validOptions(String[][],
  248.      * DocErrorReporter)}. This will validate the options added by the 
  249.      * "standard" doclet. For example, this method will flag an error using
  250.      * the DocErrorReporter if user has used "-nohelp" and "-helpfile" option
  251.      * together.
  252.      * 
  253.      * @param options  Options used on the command line.
  254.      * @param reporter Error reporter to be used.
  255.      * @return true if all the options are valid.
  256.      */
  257.     public boolean specificDocletValidOptions(String options[][],
  258.                                               DocErrorReporter reporter) {
  259.         boolean helpfile = false;
  260.         boolean nohelp = false;
  261.         boolean overview = false;
  262.         boolean nooverview = false;
  263.         boolean splitindex = false;
  264.         boolean noindex = false;
  265.         for (int oi = 0; oi < options.length; ++oi) {
  266.             String[] os = options[oi];
  267.             String opt = os[0].toLowerCase();
  268.             if (opt.equals("-helpfile")) {
  269.                 if (nohelp == true) {
  270.                     reporter.printError(standardmessage.getText(
  271.                          "doclet.Option_conflict", "-helpfile", "-nohelp")); 
  272.                     return false;
  273.                 }
  274.                 if (helpfile == true) {
  275.                     reporter.printError(standardmessage.getText(
  276.                                          "doclet.Option_reuse", "-helpfile")); 
  277.                     return false;
  278.                 }
  279.                 File help = new File(os[1]);
  280.                 if (!help.exists()) {
  281.                     reporter.printError(standardmessage.getText(
  282.                              "doclet.File_not_found", os[1])); 
  283.                     return false;
  284.                 }                    
  285.                 helpfile = true;
  286.             } else  if (opt.equals("-nohelp")) {
  287.                 if (helpfile == true) {
  288.                     reporter.printError(standardmessage.getText(
  289.                          "doclet.Option_conflict", "-nohelp", "-helpfile")); 
  290.                     return false;
  291.                 }
  292.                 nohelp = true;
  293.             } else if (opt.equals("-overview")) {
  294.                 if (nooverview == true) {
  295.                     reporter.printError(standardmessage.getText(
  296.                         "doclet.Option_conflict", "-overview", "-nooverview")); 
  297.                     return false;
  298.                 }
  299.                 if (overview == true) {
  300.                     reporter.printError(standardmessage.getText(
  301.                                          "doclet.Option_reuse", "-overview")); 
  302.                     return false;
  303.                 }
  304.                 overview = true;
  305.             } else  if (opt.equals("-nooverview")) {
  306.                 if (overview == true) {
  307.                     reporter.printError(standardmessage.getText(
  308.                         "doclet.Option_conflict", "-nooverview", "-overview")); 
  309.                     return false;
  310.                 }
  311.                 nooverview = true; 
  312.             } else if (opt.equals("-splitindex")) {
  313.                 if (noindex == true) {
  314.                     reporter.printError(standardmessage.getText(
  315.                          "doclet.Option_conflict", "-splitindex", "-noindex")); 
  316.                     return false;
  317.                 }
  318.                 splitindex = true;
  319.             } else if (opt.equals("-noindex")) {
  320.                 if (splitindex == true) {
  321.                     reporter.printError(standardmessage.getText(
  322.                          "doclet.Option_conflict", "-noindex", "-splitindex")); 
  323.                     return false;
  324.                 }
  325.                 noindex = true;
  326.             } else if (opt.equals("-group")) {
  327.                 if (!Group.checkPackageGroups(os[1], os[2], reporter)) {
  328.                     return false;
  329.                 }
  330.             } else if (opt.equals("-link")) {
  331.                 String url = os[1];
  332.                 if (!Extern.url(url, url, reporter)) {
  333.                     return false;
  334.                 }
  335.             } else if (opt.equals("-linkoffline")) {
  336.                 String url = os[1];
  337.                 String pkglisturl = os[2];
  338.                 if (!Extern.url(url, pkglisturl, reporter)) {
  339.                     return false;
  340.                 }
  341.             }
  342.         }
  343.         return true;
  344.     }
  345.  
  346.     /**
  347.      * Decide the page which will appear first in the right-hand frame. It will
  348.      * be "overview-summary.html" if "-overview" option is used or no
  349.      * "-overview" but the number of packages is more than one. It will be 
  350.      * "package-summary.html" of the respective package if there is only one
  351.      * package to document. It will be a class page(first in the sorted order), 
  352.      * if only classes are provided on the command line.
  353.      *
  354.      * @param root Root of the program structure.
  355.      */
  356.     protected void setTopFile(RootDoc root) {
  357.         if (createoverview) {
  358.             topFile = "overview-summary.html";
  359.         } else {
  360.             if (packages.length == 0) {
  361.                 if (root.classes().length > 0) {
  362.                     ClassDoc[] classarr = root.classes();
  363.                     Arrays.sort(classarr);
  364.                     topFile = DirectoryManager.getPathToClass(classarr[0]);
  365.         }                    
  366.             } else {
  367.                 topFile = DirectoryManager.getPathToPackage(packages[0], 
  368.                                                       "package-summary.html");
  369.             }
  370.         } 
  371.     }  
  372.  
  373.     /**
  374.      * Generate "overview.html" page if option "-overview" is used or number of
  375.      * packages is more than one. Sets {@link createoverview} field to true.
  376.      */
  377.     protected void setCreateOverview() { 
  378.         if ((overview || packages.length > 1) && !nooverview) {
  379.             createoverview = true;
  380.         }
  381.     }
  382. }
  383.         
  384.  
  385.