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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 1324
fa85af323d97
child 1358
fc123bdeddb8
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     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.*;
    29 import java.net.*;
    30 import java.util.*;
    32 import com.sun.javadoc.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Configure the output based on the command line options.
    38  * <p>
    39  * Also determine the length of the command line option. For example,
    40  * for a option "-header" there will be a string argument associated, then the
    41  * the length of option "-header" is two. But for option "-nohelp" no argument
    42  * is needed so it's length is 1.
    43  * </p>
    44  * <p>
    45  * Also do the error checking on the options used. For example it is illegal to
    46  * use "-helpfile" option when already "-nohelp" option is used.
    47  * </p>
    48  *
    49  * @author Robert Field.
    50  * @author Atul Dambalkar.
    51  * @author Jamie Ho
    52  * @author Bhavesh Patel (Modified)
    53  */
    54 public class ConfigurationImpl extends Configuration {
    56     private static ConfigurationImpl instance = new ConfigurationImpl();
    58     /**
    59      * The build date.  Note: For now, we will use
    60      * a version number instead of a date.
    61      */
    62     public static final String BUILD_DATE = System.getProperty("java.version");
    64     /**
    65      * The name of the constant values file.
    66      */
    67     public static final String CONSTANTS_FILE_NAME = "constant-values.html";
    69     /**
    70      * Argument for command line option "-header".
    71      */
    72     public String header = "";
    74     /**
    75      * Argument for command line option "-packagesheader".
    76      */
    77     public String packagesheader = "";
    79     /**
    80      * Argument for command line option "-footer".
    81      */
    82     public String footer = "";
    84     /**
    85      * Argument for command line option "-doctitle".
    86      */
    87     public String doctitle = "";
    89     /**
    90      * Argument for command line option "-windowtitle".
    91      */
    92     public String windowtitle = "";
    94     /**
    95      * Argument for command line option "-top".
    96      */
    97     public String top = "";
    99     /**
   100      * Argument for command line option "-bottom".
   101      */
   102     public String bottom = "";
   104     /**
   105      * Argument for command line option "-helpfile".
   106      */
   107     public String helpfile = "";
   109     /**
   110      * Argument for command line option "-stylesheetfile".
   111      */
   112     public String stylesheetfile = "";
   114     /**
   115      * Argument for command line option "-Xdocrootparent".
   116      */
   117     public String docrootparent = "";
   119     /**
   120      * True if command line option "-nohelp" is used. Default value is false.
   121      */
   122     public boolean nohelp = false;
   124     /**
   125      * True if command line option "-splitindex" is used. Default value is
   126      * false.
   127      */
   128     public boolean splitindex = false;
   130     /**
   131      * False if command line option "-noindex" is used. Default value is true.
   132      */
   133     public boolean createindex = true;
   135     /**
   136      * True if command line option "-use" is used. Default value is false.
   137      */
   138     public boolean classuse = false;
   140     /**
   141      * False if command line option "-notree" is used. Default value is true.
   142      */
   143     public boolean createtree = true;
   145     /**
   146      * True if command line option "-nodeprecated" is used. Default value is
   147      * false.
   148      */
   149     public boolean nodeprecatedlist = false;
   151     /**
   152      * True if command line option "-nonavbar" is used. Default value is false.
   153      */
   154     public boolean nonavbar = false;
   156     /**
   157      * True if command line option "-nooverview" is used. Default value is
   158      * false
   159      */
   160     private boolean nooverview = false;
   162     /**
   163      * True if command line option "-overview" is used. Default value is false.
   164      */
   165     public boolean overview = false;
   167     /**
   168      * This is true if option "-overview" is used or option "-overview" is not
   169      * used and number of packages is more than one.
   170      */
   171     public boolean createoverview = false;
   173     /**
   174      * Unique Resource Handler for this package.
   175      */
   176     public final MessageRetriever standardmessage;
   178     /**
   179      * First file to appear in the right-hand frame in the generated
   180      * documentation.
   181      */
   182     public String topFile = "";
   184     /**
   185      * The classdoc for the class file getting generated.
   186      */
   187     public ClassDoc currentcd = null;  // Set this classdoc in the
   188     // ClassWriter.
   190     /**
   191      * Constructor. Initialises resource for the
   192      * {@link com.sun.tools.doclets.MessageRetriever}.
   193      */
   194     private ConfigurationImpl() {
   195         standardmessage = new MessageRetriever(this,
   196             "com.sun.tools.doclets.formats.html.resources.standard");
   197     }
   199     /**
   200      * Reset to a fresh new ConfigurationImpl, to allow multiple invocations
   201      * of javadoc within a single VM. It would be better not to be using
   202      * static fields at all, but .... (sigh).
   203      */
   204     public static void reset() {
   205         instance = new ConfigurationImpl();
   206     }
   208     public static ConfigurationImpl getInstance() {
   209         return instance;
   210     }
   212     /**
   213      * Return the build date for the doclet.
   214      */
   215     public String getDocletSpecificBuildDate() {
   216         return BUILD_DATE;
   217     }
   219     /**
   220      * Depending upon the command line options provided by the user, set
   221      * configure the output generation environment.
   222      *
   223      * @param options The array of option names and values.
   224      */
   225     public void setSpecificDocletOptions(String[][] options) {
   226         for (int oi = 0; oi < options.length; ++oi) {
   227             String[] os = options[oi];
   228             String opt = os[0].toLowerCase();
   229             if (opt.equals("-footer")) {
   230                 footer = os[1];
   231             } else if (opt.equals("-header")) {
   232                 header = os[1];
   233             } else if (opt.equals("-packagesheader")) {
   234                 packagesheader = os[1];
   235             } else if (opt.equals("-doctitle")) {
   236                 doctitle = os[1];
   237             } else if (opt.equals("-windowtitle")) {
   238                 windowtitle = os[1];
   239             } else if (opt.equals("-top")) {
   240                 top = os[1];
   241             } else if (opt.equals("-bottom")) {
   242                 bottom = os[1];
   243             } else if (opt.equals("-helpfile")) {
   244                 helpfile = os[1];
   245             } else if (opt.equals("-stylesheetfile")) {
   246                 stylesheetfile = os[1];
   247             } else if (opt.equals("-charset")) {
   248                 charset = os[1];
   249             } else if (opt.equals("-xdocrootparent")) {
   250                 docrootparent = os[1];
   251             } else if (opt.equals("-nohelp")) {
   252                 nohelp = true;
   253             } else if (opt.equals("-splitindex")) {
   254                 splitindex = true;
   255             } else if (opt.equals("-noindex")) {
   256                 createindex = false;
   257             } else if (opt.equals("-use")) {
   258                 classuse = true;
   259             } else if (opt.equals("-notree")) {
   260                 createtree = false;
   261             } else if (opt.equals("-nodeprecatedlist")) {
   262                 nodeprecatedlist = true;
   263             } else if (opt.equals("-nonavbar")) {
   264                 nonavbar = true;
   265             } else if (opt.equals("-nooverview")) {
   266                 nooverview = true;
   267             } else if (opt.equals("-overview")) {
   268                 overview = true;
   269             }
   270         }
   271         if (root.specifiedClasses().length > 0) {
   272             Map<String,PackageDoc> map = new HashMap<String,PackageDoc>();
   273             PackageDoc pd;
   274             ClassDoc[] classes = root.classes();
   275             for (int i = 0; i < classes.length; i++) {
   276                 pd = classes[i].containingPackage();
   277                 if(! map.containsKey(pd.name())) {
   278                     map.put(pd.name(), pd);
   279                 }
   280             }
   281         }
   282         setCreateOverview();
   283         setTopFile(root);
   284     }
   286     /**
   287      * Returns the "length" of a given option. If an option takes no
   288      * arguments, its length is one. If it takes one argument, it's
   289      * length is two, and so on. This method is called by JavaDoc to
   290      * parse the options it does not recognize. It then calls
   291      * {@link #validOptions(String[][], DocErrorReporter)} to
   292      * validate them.
   293      * <b>Note:</b><br>
   294      * The options arrive as case-sensitive strings. For options that
   295      * are not case-sensitive, use toLowerCase() on the option string
   296      * before comparing it.
   297      * </blockquote>
   298      *
   299      * @return number of arguments + 1 for a option. Zero return means
   300      * option not known.  Negative value means error occurred.
   301      */
   302     public int optionLength(String option) {
   303         int result = -1;
   304         if ((result = super.optionLength(option)) > 0) {
   305             return result;
   306         }
   307         // otherwise look for the options we have added
   308         option = option.toLowerCase();
   309         if (option.equals("-nodeprecatedlist") ||
   310             option.equals("-noindex") ||
   311             option.equals("-notree") ||
   312             option.equals("-nohelp") ||
   313             option.equals("-splitindex") ||
   314             option.equals("-serialwarn") ||
   315             option.equals("-use") ||
   316             option.equals("-nonavbar") ||
   317             option.equals("-nooverview")) {
   318             return 1;
   319         } else if (option.equals("-help")) {
   320             System.out.println(getText("doclet.usage"));
   321             return 1;
   322         } else if (option.equals("-footer") ||
   323                    option.equals("-header") ||
   324                    option.equals("-packagesheader") ||
   325                    option.equals("-doctitle") ||
   326                    option.equals("-windowtitle") ||
   327                    option.equals("-top") ||
   328                    option.equals("-bottom") ||
   329                    option.equals("-helpfile") ||
   330                    option.equals("-stylesheetfile") ||
   331                    option.equals("-charset") ||
   332                    option.equals("-overview") ||
   333                    option.equals("-xdocrootparent")) {
   334             return 2;
   335         } else {
   336             return 0;
   337         }
   338     }
   340     /**
   341      * {@inheritDoc}
   342      */
   343     public boolean validOptions(String options[][],
   344             DocErrorReporter reporter) {
   345         boolean helpfile = false;
   346         boolean nohelp = false;
   347         boolean overview = false;
   348         boolean nooverview = false;
   349         boolean splitindex = false;
   350         boolean noindex = false;
   351         // check shared options
   352         if (!generalValidOptions(options, reporter)) {
   353             return false;
   354         }
   355         // otherwise look at our options
   356         for (int oi = 0; oi < options.length; ++oi) {
   357             String[] os = options[oi];
   358             String opt = os[0].toLowerCase();
   359             if (opt.equals("-helpfile")) {
   360                 if (nohelp == true) {
   361                     reporter.printError(getText("doclet.Option_conflict",
   362                         "-helpfile", "-nohelp"));
   363                     return false;
   364                 }
   365                 if (helpfile == true) {
   366                     reporter.printError(getText("doclet.Option_reuse",
   367                         "-helpfile"));
   368                     return false;
   369                 }
   370                 File help = new File(os[1]);
   371                 if (!help.exists()) {
   372                     reporter.printError(getText("doclet.File_not_found", os[1]));
   373                     return false;
   374                 }
   375                 helpfile = true;
   376             } else  if (opt.equals("-nohelp")) {
   377                 if (helpfile == true) {
   378                     reporter.printError(getText("doclet.Option_conflict",
   379                         "-nohelp", "-helpfile"));
   380                     return false;
   381                 }
   382                 nohelp = true;
   383             } else if (opt.equals("-xdocrootparent")) {
   384                 try {
   385                     new URL(os[1]);
   386                 } catch (MalformedURLException e) {
   387                     reporter.printError(getText("doclet.MalformedURL", os[1]));
   388                     return false;
   389                 }
   390             } else if (opt.equals("-overview")) {
   391                 if (nooverview == true) {
   392                     reporter.printError(getText("doclet.Option_conflict",
   393                         "-overview", "-nooverview"));
   394                     return false;
   395                 }
   396                 if (overview == true) {
   397                     reporter.printError(getText("doclet.Option_reuse",
   398                         "-overview"));
   399                     return false;
   400                 }
   401                 overview = true;
   402             } else  if (opt.equals("-nooverview")) {
   403                 if (overview == true) {
   404                     reporter.printError(getText("doclet.Option_conflict",
   405                         "-nooverview", "-overview"));
   406                     return false;
   407                 }
   408                 nooverview = true;
   409             } else if (opt.equals("-splitindex")) {
   410                 if (noindex == true) {
   411                     reporter.printError(getText("doclet.Option_conflict",
   412                         "-splitindex", "-noindex"));
   413                     return false;
   414                 }
   415                 splitindex = true;
   416             } else if (opt.equals("-noindex")) {
   417                 if (splitindex == true) {
   418                     reporter.printError(getText("doclet.Option_conflict",
   419                         "-noindex", "-splitindex"));
   420                     return false;
   421                 }
   422                 noindex = true;
   423             }
   424         }
   425         return true;
   426     }
   428     /**
   429      * {@inheritDoc}
   430      */
   431     public MessageRetriever getDocletSpecificMsg() {
   432         return standardmessage;
   433     }
   435     /**
   436      * Decide the page which will appear first in the right-hand frame. It will
   437      * be "overview-summary.html" if "-overview" option is used or no
   438      * "-overview" but the number of packages is more than one. It will be
   439      * "package-summary.html" of the respective package if there is only one
   440      * package to document. It will be a class page(first in the sorted order),
   441      * if only classes are provided on the command line.
   442      *
   443      * @param root Root of the program structure.
   444      */
   445     protected void setTopFile(RootDoc root) {
   446         if (!checkForDeprecation(root)) {
   447             return;
   448         }
   449         if (createoverview) {
   450             topFile = "overview-summary.html";
   451         } else {
   452             if (packages.length == 1 && packages[0].name().equals("")) {
   453                 if (root.classes().length > 0) {
   454                     ClassDoc[] classarr = root.classes();
   455                     Arrays.sort(classarr);
   456                     ClassDoc cd = getValidClass(classarr);
   457                     topFile = DirectoryManager.getPathToClass(cd);
   458                 }
   459             } else {
   460                 topFile = DirectoryManager.getPathToPackage(packages[0],
   461                                                             "package-summary.html");
   462             }
   463         }
   464     }
   466     protected ClassDoc getValidClass(ClassDoc[] classarr) {
   467         if (!nodeprecated) {
   468             return classarr[0];
   469         }
   470         for (int i = 0; i < classarr.length; i++) {
   471             if (classarr[i].tags("deprecated").length == 0) {
   472                 return classarr[i];
   473             }
   474         }
   475         return null;
   476     }
   478     protected boolean checkForDeprecation(RootDoc root) {
   479         ClassDoc[] classarr = root.classes();
   480         for (int i = 0; i < classarr.length; i++) {
   481             if (isGeneratedDoc(classarr[i])) {
   482                 return true;
   483             }
   484         }
   485         return false;
   486     }
   488     /**
   489      * Generate "overview.html" page if option "-overview" is used or number of
   490      * packages is more than one. Sets {@link #createoverview} field to true.
   491      */
   492     protected void setCreateOverview() {
   493         if ((overview || packages.length > 1) && !nooverview) {
   494             createoverview = true;
   495         }
   496     }
   498     /**
   499      * {@inheritDoc}
   500      */
   501     public WriterFactory getWriterFactory() {
   502         return new WriterFactoryImpl(this);
   503     }
   505     /**
   506      * {@inheritDoc}
   507      */
   508     public Comparator<ProgramElementDoc> getMemberComparator() {
   509         return null;
   510     }
   512     /**
   513      * {@inheritDoc}
   514      */
   515     public Locale getLocale() {
   516         if (root instanceof com.sun.tools.javadoc.RootDocImpl)
   517             return ((com.sun.tools.javadoc.RootDocImpl)root).getLocale();
   518         else
   519             return Locale.getDefault();
   520     }
   521 }

mercurial