src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1570
f91144b7da75
child 1611
6f988040a1c8
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2013, 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.internal.toolkit;
    28 import java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.javac.sym.Profiles;
    33 import com.sun.tools.javac.jvm.Profile;
    34 import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory;
    35 import com.sun.tools.doclets.internal.toolkit.taglets.*;
    36 import com.sun.tools.doclets.internal.toolkit.util.*;
    37 import javax.tools.JavaFileManager;
    39 /**
    40  * Configure the output based on the options. Doclets should sub-class
    41  * Configuration, to configure and add their own options. This class contains
    42  * all user options which are supported by the 1.1 doclet and the standard
    43  * doclet.
    44  *
    45  *  <p><b>This is NOT part of any supported API.
    46  *  If you write code that depends on this, you do so at your own risk.
    47  *  This code and its internal interfaces are subject to change or
    48  *  deletion without notice.</b>
    49  *
    50  * @author Robert Field.
    51  * @author Atul Dambalkar.
    52  * @author Jamie Ho
    53  */
    54 public abstract class Configuration {
    56     /**
    57      * The factory for builders.
    58      */
    59     protected BuilderFactory builderFactory;
    61     /**
    62      * The taglet manager.
    63      */
    64     public TagletManager tagletManager;
    66     /**
    67      * The path to the builder XML input file.
    68      */
    69     public String builderXMLPath;
    71     /**
    72      * The default path to the builder XML.
    73      */
    74     private static final String DEFAULT_BUILDER_XML = "resources/doclet.xml";
    76     /**
    77      * The path to Taglets
    78      */
    79     public String tagletpath = "";
    81     /**
    82      * This is true if option "-serialwarn" is used. Defualt value is false to
    83      * suppress excessive warnings about serial tag.
    84      */
    85     public boolean serialwarn = false;
    87     /**
    88      * The specified amount of space between tab stops.
    89      */
    90     public int sourcetab;
    92     public String tabSpaces;
    94     /**
    95      * True if we should generate browsable sources.
    96      */
    97     public boolean linksource = false;
    99     /**
   100      * True if command line option "-nosince" is used. Default value is
   101      * false.
   102      */
   103     public boolean nosince = false;
   105     /**
   106      * True if we should recursively copy the doc-file subdirectories
   107      */
   108     public boolean copydocfilesubdirs = false;
   110     /**
   111      * The META charset tag used for cross-platform viewing.
   112      */
   113     public String charset = "";
   115     /**
   116      * True if user wants to add member names as meta keywords.
   117      * Set to false because meta keywords are ignored in general
   118      * by most Internet search engines.
   119      */
   120     public boolean keywords = false;
   122     /**
   123      * The meta tag keywords instance.
   124      */
   125     public final MetaKeywords metakeywords = new MetaKeywords(this);
   127     /**
   128      * The list of doc-file subdirectories to exclude
   129      */
   130     protected Set<String> excludedDocFileDirs;
   132     /**
   133      * The list of qualifiers to exclude
   134      */
   135     protected Set<String> excludedQualifiers;
   137     /**
   138      * The Root of the generated Program Structure from the Doclet API.
   139      */
   140     public RootDoc root;
   142     /**
   143      * Destination directory name, in which doclet will generate the entire
   144      * documentation. Default is current directory.
   145      */
   146     public String destDirName = "";
   148     /**
   149      * Destination directory name, in which doclet will copy the doc-files to.
   150      */
   151     public String docFileDestDirName = "";
   153     /**
   154      * Encoding for this document. Default is default encoding for this
   155      * platform.
   156      */
   157     public String docencoding = null;
   159     /**
   160      * True if user wants to suppress descriptions and tags.
   161      */
   162     public boolean nocomment = false;
   164     /**
   165      * Encoding for this document. Default is default encoding for this
   166      * platform.
   167      */
   168     public String encoding = null;
   170     /**
   171      * Generate author specific information for all the classes if @author
   172      * tag is used in the doc comment and if -author option is used.
   173      * <code>showauthor</code> is set to true if -author option is used.
   174      * Default is don't show author information.
   175      */
   176     public boolean showauthor = false;
   178     /**
   179      * Generate documentation for JavaFX getters and setters automatically
   180      * by copying it from the appropriate property definition.
   181      */
   182     public boolean javafx = false;
   184     /**
   185      * Generate version specific information for the all the classes
   186      * if @version tag is used in the doc comment and if -version option is
   187      * used. <code>showversion</code> is set to true if -version option is
   188      * used.Default is don't show version information.
   189      */
   190     public boolean showversion = false;
   192     /**
   193      * Sourcepath from where to read the source files. Default is classpath.
   194      *
   195      */
   196     public String sourcepath = "";
   198     /**
   199      * Argument for command line option "-Xprofilespath".
   200      */
   201     public String profilespath = "";
   203     /**
   204      * Generate profiles documentation if profilespath is set and valid profiles
   205      * are present.
   206      */
   207     public boolean showProfiles = false;
   209     /**
   210      * Don't generate deprecated API information at all, if -nodeprecated
   211      * option is used. <code>nodepracted</code> is set to true if
   212      * -nodeprecated option is used. Default is generate deprected API
   213      * information.
   214      */
   215     public boolean nodeprecated = false;
   217     /**
   218      * The catalog of classes specified on the command-line
   219      */
   220     public ClassDocCatalog classDocCatalog;
   222     /**
   223      * Message Retriever for the doclet, to retrieve message from the resource
   224      * file for this Configuration, which is common for 1.1 and standard
   225      * doclets.
   226      *
   227      * TODO:  Make this private!!!
   228      */
   229     public MessageRetriever message = null;
   231     /**
   232      * True if user wants to suppress time stamp in output.
   233      * Default is false.
   234      */
   235     public boolean notimestamp= false;
   237     /**
   238      * The package grouping instance.
   239      */
   240     public final Group group = new Group(this);
   242     /**
   243      * The tracker of external package links.
   244      */
   245     public final Extern extern = new Extern(this);
   247     /**
   248      * Return the build date for the doclet.
   249      */
   250     public abstract String getDocletSpecificBuildDate();
   252     /**
   253      * This method should be defined in all those doclets(configurations),
   254      * which want to derive themselves from this Configuration. This method
   255      * can be used to set its own command line options.
   256      *
   257      * @param options The array of option names and values.
   258      * @throws DocletAbortException
   259      */
   260     public abstract void setSpecificDocletOptions(String[][] options);
   262     /**
   263      * Return the doclet specific {@link MessageRetriever}
   264      * @return the doclet specific MessageRetriever.
   265      */
   266     public abstract MessageRetriever getDocletSpecificMsg();
   268     /**
   269      * A profiles object used to access profiles across various pages.
   270      */
   271     public Profiles profiles;
   273     /**
   274      * An map of the profiles to packages.
   275      */
   276     public Map<String,PackageDoc[]> profilePackages;
   278     /**
   279      * An array of the packages specified on the command-line merged
   280      * with the array of packages that contain the classes specified on the
   281      * command-line.  The array is sorted.
   282      */
   283     public PackageDoc[] packages;
   285     /**
   286      * Constructor. Constructs the message retriever with resource file.
   287      */
   288     public Configuration() {
   289         message =
   290             new MessageRetriever(this,
   291             "com.sun.tools.doclets.internal.toolkit.resources.doclets");
   292         excludedDocFileDirs = new HashSet<String>();
   293         excludedQualifiers = new HashSet<String>();
   294         setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
   295     }
   297     /**
   298      * Return the builder factory for this doclet.
   299      *
   300      * @return the builder factory for this doclet.
   301      */
   302     public BuilderFactory getBuilderFactory() {
   303         if (builderFactory == null) {
   304             builderFactory = new BuilderFactory(this);
   305         }
   306         return builderFactory;
   307     }
   309     /**
   310      * This method should be defined in all those doclets
   311      * which want to inherit from this Configuration. This method
   312      * should return the number of arguments to the command line
   313      * option (including the option name).  For example,
   314      * -notimestamp is a single-argument option, so this method would
   315      * return 1.
   316      *
   317      * @param option Command line option under consideration.
   318      * @return number of arguments to option (including the
   319      * option name). Zero return means option not known.
   320      * Negative value means error occurred.
   321      */
   322     public int optionLength(String option) {
   323         option = option.toLowerCase();
   324         if (option.equals("-author") ||
   325             option.equals("-docfilessubdirs") ||
   326             option.equals("-javafx") ||
   327             option.equals("-keywords") ||
   328             option.equals("-linksource") ||
   329             option.equals("-nocomment") ||
   330             option.equals("-nodeprecated") ||
   331             option.equals("-nosince") ||
   332             option.equals("-notimestamp") ||
   333             option.equals("-quiet") ||
   334             option.equals("-xnodate") ||
   335             option.equals("-version")) {
   336             return 1;
   337         } else if (option.equals("-d") ||
   338                    option.equals("-docencoding") ||
   339                    option.equals("-encoding") ||
   340                    option.equals("-excludedocfilessubdir") ||
   341                    option.equals("-link") ||
   342                    option.equals("-sourcetab") ||
   343                    option.equals("-noqualifier") ||
   344                    option.equals("-output") ||
   345                    option.equals("-sourcepath") ||
   346                    option.equals("-tag") ||
   347                    option.equals("-taglet") ||
   348                    option.equals("-tagletpath") ||
   349                    option.equals("-xprofilespath")) {
   350             return 2;
   351         } else if (option.equals("-group") ||
   352                    option.equals("-linkoffline")) {
   353             return 3;
   354         } else {
   355             return -1;  // indicate we don't know about it
   356         }
   357     }
   359     /**
   360      * Perform error checking on the given options.
   361      *
   362      * @param options  the given options to check.
   363      * @param reporter the reporter used to report errors.
   364      */
   365     public abstract boolean validOptions(String options[][],
   366         DocErrorReporter reporter);
   368     private void initProfiles() throws IOException {
   369         profiles = Profiles.read(new File(profilespath));
   370         // Generate profiles documentation only is profilespath is set and if
   371         // profiles is not null and profiles count is 1 or more.
   372         showProfiles = (!profilespath.isEmpty() && profiles != null &&
   373                 profiles.getProfileCount() > 0);
   374     }
   376     private void initProfilePackages() throws IOException {
   377         profilePackages = new HashMap<String,PackageDoc[]>();
   378         ArrayList<PackageDoc> results;
   379         Map<String,PackageDoc> packageIndex = new HashMap<String,PackageDoc>();
   380         for (int i = 0; i < packages.length; i++) {
   381             PackageDoc pkg = packages[i];
   382             packageIndex.put(pkg.name(), pkg);
   383         }
   384         for (int i = 1; i < profiles.getProfileCount(); i++) {
   385             Set<String> profPkgs = profiles.getPackages(i);
   386             results = new ArrayList<PackageDoc>();
   387             for (String packageName : profPkgs) {
   388                 packageName = packageName.replace("/", ".");
   389                 PackageDoc profPkg = packageIndex.get(packageName);
   390                 if (profPkg != null) {
   391                     results.add(profPkg);
   392                 }
   393             }
   394             Collections.sort(results);
   395             PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{});
   396             profilePackages.put(Profile.lookup(i).name, profilePkgs);
   397         }
   398     }
   400     private void initPackageArray() {
   401         Set<PackageDoc> set = new HashSet<PackageDoc>(Arrays.asList(root.specifiedPackages()));
   402         ClassDoc[] classes = root.specifiedClasses();
   403         for (int i = 0; i < classes.length; i++) {
   404             set.add(classes[i].containingPackage());
   405         }
   406         ArrayList<PackageDoc> results = new ArrayList<PackageDoc>(set);
   407         Collections.sort(results);
   408         packages = results.toArray(new PackageDoc[] {});
   409     }
   411     /**
   412      * Set the command line options supported by this configuration.
   413      *
   414      * @param options the two dimensional array of options.
   415      */
   416     public void setOptions(String[][] options) {
   417         LinkedHashSet<String[]> customTagStrs = new LinkedHashSet<String[]>();
   418         for (int oi = 0; oi < options.length; ++oi) {
   419             String[] os = options[oi];
   420             String opt = os[0].toLowerCase();
   421             if (opt.equals("-d")) {
   422                 destDirName = addTrailingFileSep(os[1]);
   423                 docFileDestDirName = destDirName;
   424             } else if (opt.equals("-docfilessubdirs")) {
   425                 copydocfilesubdirs = true;
   426             } else if (opt.equals("-docencoding")) {
   427                 docencoding = os[1];
   428             } else if (opt.equals("-encoding")) {
   429                 encoding = os[1];
   430             } else if (opt.equals("-author")) {
   431                 showauthor = true;
   432             } else  if (opt.equals("-javafx")) {
   433                 javafx = true;
   434             } else if (opt.equals("-nosince")) {
   435                 nosince = true;
   436             } else if (opt.equals("-version")) {
   437                 showversion = true;
   438             } else if (opt.equals("-nodeprecated")) {
   439                 nodeprecated = true;
   440             } else if (opt.equals("-sourcepath")) {
   441                 sourcepath = os[1];
   442             } else if (opt.equals("-classpath") &&
   443                        sourcepath.length() == 0) {
   444                 sourcepath = os[1];
   445             } else if (opt.equals("-excludedocfilessubdir")) {
   446                 addToSet(excludedDocFileDirs, os[1]);
   447             } else if (opt.equals("-noqualifier")) {
   448                 addToSet(excludedQualifiers, os[1]);
   449             } else if (opt.equals("-linksource")) {
   450                 linksource = true;
   451             } else if (opt.equals("-sourcetab")) {
   452                 linksource = true;
   453                 try {
   454                     setTabWidth(Integer.parseInt(os[1]));
   455                 } catch (NumberFormatException e) {
   456                     //Set to -1 so that warning will be printed
   457                     //to indicate what is valid argument.
   458                     sourcetab = -1;
   459                 }
   460                 if (sourcetab <= 0) {
   461                     message.warning("doclet.sourcetab_warning");
   462                     setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
   463                 }
   464             } else if (opt.equals("-notimestamp")) {
   465                 notimestamp = true;
   466             } else if (opt.equals("-nocomment")) {
   467                 nocomment = true;
   468             } else if (opt.equals("-tag") || opt.equals("-taglet")) {
   469                 customTagStrs.add(os);
   470             } else if (opt.equals("-tagletpath")) {
   471                 tagletpath = os[1];
   472             }  else if (opt.equals("-xprofilespath")) {
   473                 profilespath = os[1];
   474             } else if (opt.equals("-keywords")) {
   475                 keywords = true;
   476             } else if (opt.equals("-serialwarn")) {
   477                 serialwarn = true;
   478             } else if (opt.equals("-group")) {
   479                 group.checkPackageGroups(os[1], os[2]);
   480             } else if (opt.equals("-link")) {
   481                 String url = os[1];
   482                 extern.link(url, url, root, false);
   483             } else if (opt.equals("-linkoffline")) {
   484                 String url = os[1];
   485                 String pkglisturl = os[2];
   486                 extern.link(url, pkglisturl, root, true);
   487             }
   488         }
   489         if (sourcepath.length() == 0) {
   490             sourcepath = System.getProperty("env.class.path") == null ? "" :
   491                 System.getProperty("env.class.path");
   492         }
   493         if (docencoding == null) {
   494             docencoding = encoding;
   495         }
   497         classDocCatalog = new ClassDocCatalog(root.specifiedClasses(), this);
   498         initTagletManager(customTagStrs);
   499     }
   501     /**
   502      * Set the command line options supported by this configuration.
   503      *
   504      * @throws DocletAbortException
   505      */
   506     public void setOptions() {
   507         initPackageArray();
   508         setOptions(root.options());
   509         if (!profilespath.isEmpty()) {
   510             try {
   511                 initProfiles();
   512                 initProfilePackages();
   513             } catch (Exception e) {
   514                 throw new DocletAbortException();
   515             }
   516         }
   517         setSpecificDocletOptions(root.options());
   518     }
   521     /**
   522      * Initialize the taglet manager.  The strings to initialize the simple custom tags should
   523      * be in the following format:  "[tag name]:[location str]:[heading]".
   524      * @param customTagStrs the set two dimensional arrays of strings.  These arrays contain
   525      * either -tag or -taglet arguments.
   526      */
   527     private void initTagletManager(Set<String[]> customTagStrs) {
   528         tagletManager = tagletManager == null ?
   529             new TagletManager(nosince, showversion, showauthor, javafx, message) :
   530             tagletManager;
   531         String[] args;
   532         for (Iterator<String[]> it = customTagStrs.iterator(); it.hasNext(); ) {
   533             args = it.next();
   534             if (args[0].equals("-taglet")) {
   535                 tagletManager.addCustomTag(args[1], getFileManager(), tagletpath);
   536                 continue;
   537             }
   538             String[] tokens = tokenize(args[1],
   539                 TagletManager.SIMPLE_TAGLET_OPT_SEPARATOR, 3);
   540             if (tokens.length == 1) {
   541                 String tagName = args[1];
   542                 if (tagletManager.isKnownCustomTag(tagName)) {
   543                     //reorder a standard tag
   544                     tagletManager.addNewSimpleCustomTag(tagName, null, "");
   545                 } else {
   546                     //Create a simple tag with the heading that has the same name as the tag.
   547                     StringBuilder heading = new StringBuilder(tagName + ":");
   548                     heading.setCharAt(0, Character.toUpperCase(tagName.charAt(0)));
   549                     tagletManager.addNewSimpleCustomTag(tagName, heading.toString(), "a");
   550                 }
   551             } else if (tokens.length == 2) {
   552                 //Add simple taglet without heading, probably to excluding it in the output.
   553                 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[1], "");
   554             } else if (tokens.length >= 3) {
   555                 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[2], tokens[1]);
   556             } else {
   557                 message.error("doclet.Error_invalid_custom_tag_argument", args[1]);
   558             }
   559         }
   560     }
   562     /**
   563      * Given a string, return an array of tokens.  The separator can be escaped
   564      * with the '\' character.  The '\' character may also be escaped by the
   565      * '\' character.
   566      *
   567      * @param s         the string to tokenize.
   568      * @param separator the separator char.
   569      * @param maxTokens the maximum number of tokens returned.  If the
   570      *                  max is reached, the remaining part of s is appended
   571      *                  to the end of the last token.
   572      *
   573      * @return an array of tokens.
   574      */
   575     private String[] tokenize(String s, char separator, int maxTokens) {
   576         List<String> tokens = new ArrayList<String>();
   577         StringBuilder  token = new StringBuilder ();
   578         boolean prevIsEscapeChar = false;
   579         for (int i = 0; i < s.length(); i += Character.charCount(i)) {
   580             int currentChar = s.codePointAt(i);
   581             if (prevIsEscapeChar) {
   582                 // Case 1:  escaped character
   583                 token.appendCodePoint(currentChar);
   584                 prevIsEscapeChar = false;
   585             } else if (currentChar == separator && tokens.size() < maxTokens-1) {
   586                 // Case 2:  separator
   587                 tokens.add(token.toString());
   588                 token = new StringBuilder();
   589             } else if (currentChar == '\\') {
   590                 // Case 3:  escape character
   591                 prevIsEscapeChar = true;
   592             } else {
   593                 // Case 4:  regular character
   594                 token.appendCodePoint(currentChar);
   595             }
   596         }
   597         if (token.length() > 0) {
   598             tokens.add(token.toString());
   599         }
   600         return tokens.toArray(new String[] {});
   601     }
   603     private void addToSet(Set<String> s, String str){
   604         StringTokenizer st = new StringTokenizer(str, ":");
   605         String current;
   606         while(st.hasMoreTokens()){
   607             current = st.nextToken();
   608             s.add(current);
   609         }
   610     }
   612     /**
   613      * Add a trailing file separator, if not found. Remove superfluous
   614      * file separators if any. Preserve the front double file separator for
   615      * UNC paths.
   616      *
   617      * @param path Path under consideration.
   618      * @return String Properly constructed path string.
   619      */
   620     public static String addTrailingFileSep(String path) {
   621         String fs = System.getProperty("file.separator");
   622         String dblfs = fs + fs;
   623         int indexDblfs;
   624         while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) {
   625             path = path.substring(0, indexDblfs) +
   626                 path.substring(indexDblfs + fs.length());
   627         }
   628         if (!path.endsWith(fs))
   629             path += fs;
   630         return path;
   631     }
   633     /**
   634      * This checks for the validity of the options used by the user.
   635      * This works exactly like
   636      * {@link com.sun.javadoc.Doclet#validOptions(String[][],
   637      * DocErrorReporter)}. This will validate the options which are shared
   638      * by our doclets. For example, this method will flag an error using
   639      * the DocErrorReporter if user has used "-nohelp" and "-helpfile" option
   640      * together.
   641      *
   642      * @param options  options used on the command line.
   643      * @param reporter used to report errors.
   644      * @return true if all the options are valid.
   645      */
   646     public boolean generalValidOptions(String options[][],
   647             DocErrorReporter reporter) {
   648         boolean docencodingfound = false;
   649         String encoding = "";
   650         for (int oi = 0; oi < options.length; oi++) {
   651             String[] os = options[oi];
   652             String opt = os[0].toLowerCase();
   653             if (opt.equals("-d")) {
   654                 String destdirname = addTrailingFileSep(os[1]);
   655                 DocFile destDir = DocFile.createFileForDirectory(this, destdirname);
   656                 if (!destDir.exists()) {
   657                     //Create the output directory (in case it doesn't exist yet)
   658                     reporter.printNotice(getText("doclet.dest_dir_create",
   659                         destdirname));
   660                     destDir.mkdirs();
   661                 } else if (!destDir.isDirectory()) {
   662                     reporter.printError(getText(
   663                         "doclet.destination_directory_not_directory_0",
   664                         destDir.getPath()));
   665                     return false;
   666                 } else if (!destDir.canWrite()) {
   667                     reporter.printError(getText(
   668                         "doclet.destination_directory_not_writable_0",
   669                         destDir.getPath()));
   670                     return false;
   671                 }
   672             } else if (opt.equals("-docencoding")) {
   673                 docencodingfound = true;
   674                 if (!checkOutputFileEncoding(os[1], reporter)) {
   675                     return false;
   676                 }
   677             } else if (opt.equals("-encoding")) {
   678                 encoding = os[1];
   679             }
   680         }
   681         if (!docencodingfound && encoding.length() > 0) {
   682             if (!checkOutputFileEncoding(encoding, reporter)) {
   683                 return false;
   684             }
   685         }
   686         return true;
   687     }
   689     /**
   690      * Check the validity of the given Source or Output File encoding on this
   691      * platform.
   692      *
   693      * @param docencoding output file encoding.
   694      * @param reporter    used to report errors.
   695      */
   696     private boolean checkOutputFileEncoding(String docencoding,
   697             DocErrorReporter reporter) {
   698         OutputStream ost= new ByteArrayOutputStream();
   699         OutputStreamWriter osw = null;
   700         try {
   701             osw = new OutputStreamWriter(ost, docencoding);
   702         } catch (UnsupportedEncodingException exc) {
   703             reporter.printError(getText("doclet.Encoding_not_supported",
   704                 docencoding));
   705             return false;
   706         } finally {
   707             try {
   708                 if (osw != null) {
   709                     osw.close();
   710                 }
   711             } catch (IOException exc) {
   712             }
   713         }
   714         return true;
   715     }
   717     /**
   718      * Return true if the given doc-file subdirectory should be excluded and
   719      * false otherwise.
   720      * @param docfilesubdir the doc-files subdirectory to check.
   721      */
   722     public boolean shouldExcludeDocFileDir(String docfilesubdir){
   723         if (excludedDocFileDirs.contains(docfilesubdir)) {
   724             return true;
   725         } else {
   726             return false;
   727         }
   728     }
   730     /**
   731      * Return true if the given qualifier should be excluded and false otherwise.
   732      * @param qualifier the qualifier to check.
   733      */
   734     public boolean shouldExcludeQualifier(String qualifier){
   735         if (excludedQualifiers.contains("all") ||
   736             excludedQualifiers.contains(qualifier) ||
   737             excludedQualifiers.contains(qualifier + ".*")) {
   738             return true;
   739         } else {
   740             int index = -1;
   741             while ((index = qualifier.indexOf(".", index + 1)) != -1) {
   742                 if (excludedQualifiers.contains(qualifier.substring(0, index + 1) + "*")) {
   743                     return true;
   744                 }
   745             }
   746             return false;
   747         }
   748     }
   750     /**
   751      * Return the qualified name of the <code>ClassDoc</code> if it's qualifier is not excluded.  Otherwise,
   752      * return the unqualified <code>ClassDoc</code> name.
   753      * @param cd the <code>ClassDoc</code> to check.
   754      */
   755     public String getClassName(ClassDoc cd) {
   756         PackageDoc pd = cd.containingPackage();
   757         if (pd != null && shouldExcludeQualifier(cd.containingPackage().name())) {
   758             return cd.name();
   759         } else {
   760             return cd.qualifiedName();
   761         }
   762     }
   764     public String getText(String key) {
   765         try {
   766             //Check the doclet specific properties file.
   767             return getDocletSpecificMsg().getText(key);
   768         } catch (Exception e) {
   769             //Check the shared properties file.
   770             return message.getText(key);
   771         }
   772     }
   774     public String getText(String key, String a1) {
   775         try {
   776             //Check the doclet specific properties file.
   777             return getDocletSpecificMsg().getText(key, a1);
   778         } catch (Exception e) {
   779             //Check the shared properties file.
   780             return message.getText(key, a1);
   781         }
   782     }
   784     public String getText(String key, String a1, String a2) {
   785         try {
   786             //Check the doclet specific properties file.
   787             return getDocletSpecificMsg().getText(key, a1, a2);
   788         } catch (Exception e) {
   789             //Check the shared properties file.
   790             return message.getText(key, a1, a2);
   791         }
   792     }
   794     public String getText(String key, String a1, String a2, String a3) {
   795         try {
   796             //Check the doclet specific properties file.
   797             return getDocletSpecificMsg().getText(key, a1, a2, a3);
   798         } catch (Exception e) {
   799             //Check the shared properties file.
   800             return message.getText(key, a1, a2, a3);
   801         }
   802     }
   804     /**
   805      * Return true if the ClassDoc element is getting documented, depending upon
   806      * -nodeprecated option and the deprecation information. Return true if
   807      * -nodeprecated is not used. Return false if -nodeprecated is used and if
   808      * either ClassDoc element is deprecated or the containing package is deprecated.
   809      *
   810      * @param cd the ClassDoc for which the page generation is checked
   811      */
   812     public boolean isGeneratedDoc(ClassDoc cd) {
   813         if (!nodeprecated) {
   814             return true;
   815         }
   816         return !(Util.isDeprecated(cd) || Util.isDeprecated(cd.containingPackage()));
   817     }
   819     /**
   820      * Return the doclet specific instance of a writer factory.
   821      * @return the {@link WriterFactory} for the doclet.
   822      */
   823     public abstract WriterFactory getWriterFactory();
   825     /**
   826      * Return the input stream to the builder XML.
   827      *
   828      * @return the input steam to the builder XML.
   829      * @throws FileNotFoundException when the given XML file cannot be found.
   830      */
   831     public InputStream getBuilderXML() throws IOException {
   832         return builderXMLPath == null ?
   833             Configuration.class.getResourceAsStream(DEFAULT_BUILDER_XML) :
   834             DocFile.createFileForInput(this, builderXMLPath).openInputStream();
   835     }
   837     /**
   838      * Return the Locale for this document.
   839      */
   840     public abstract Locale getLocale();
   842     /**
   843      * Return the current file manager.
   844      */
   845     public abstract JavaFileManager getFileManager();
   847     /**
   848      * Return the comparator that will be used to sort member documentation.
   849      * To no do any sorting, return null.
   850      *
   851      * @return the {@link java.util.Comparator} used to sort members.
   852      */
   853     public abstract Comparator<ProgramElementDoc> getMemberComparator();
   855     private void setTabWidth(int n) {
   856         sourcetab = n;
   857         tabSpaces = String.format("%" + n + "s", "");
   858     }
   860     public abstract boolean showMessage(SourcePosition pos, String key);
   861 }

mercurial