duke@1: /* bpatel@1324: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: jjg@1357: import java.net.*; jjg@1357: import java.util.*; jjg@1357: jjg@1357: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Configure the output based on the command line options. duke@1: *

duke@1: * Also determine the length of the command line option. For example, duke@1: * for a option "-header" there will be a string argument associated, then the duke@1: * the length of option "-header" is two. But for option "-nohelp" no argument duke@1: * is needed so it's length is 1. duke@1: *

duke@1: *

duke@1: * Also do the error checking on the options used. For example it is illegal to duke@1: * use "-helpfile" option when already "-nohelp" option is used. duke@1: *

duke@1: * jjg@1383: *

This is NOT part of any supported API. jjg@1383: * If you write code that depends on this, you do so at your own risk. jjg@1383: * This code and its internal interfaces are subject to change or jjg@1383: * deletion without notice. jjg@1383: * duke@1: * @author Robert Field. duke@1: * @author Atul Dambalkar. duke@1: * @author Jamie Ho bpatel@997: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class ConfigurationImpl extends Configuration { duke@1: jjg@140: private static ConfigurationImpl instance = new ConfigurationImpl(); duke@1: duke@1: /** duke@1: * The build date. Note: For now, we will use duke@1: * a version number instead of a date. duke@1: */ duke@1: public static final String BUILD_DATE = System.getProperty("java.version"); duke@1: duke@1: /** duke@1: * Argument for command line option "-header". duke@1: */ duke@1: public String header = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-packagesheader". duke@1: */ duke@1: public String packagesheader = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-footer". duke@1: */ duke@1: public String footer = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-doctitle". duke@1: */ duke@1: public String doctitle = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-windowtitle". duke@1: */ duke@1: public String windowtitle = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-top". duke@1: */ duke@1: public String top = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-bottom". duke@1: */ duke@1: public String bottom = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-helpfile". duke@1: */ duke@1: public String helpfile = ""; duke@1: duke@1: /** duke@1: * Argument for command line option "-stylesheetfile". duke@1: */ duke@1: public String stylesheetfile = ""; duke@1: duke@1: /** bpatel@997: * Argument for command line option "-Xdocrootparent". bpatel@997: */ bpatel@997: public String docrootparent = ""; bpatel@997: bpatel@997: /** duke@1: * True if command line option "-nohelp" is used. Default value is false. duke@1: */ duke@1: public boolean nohelp = false; duke@1: duke@1: /** duke@1: * True if command line option "-splitindex" is used. Default value is duke@1: * false. duke@1: */ duke@1: public boolean splitindex = false; duke@1: duke@1: /** duke@1: * False if command line option "-noindex" is used. Default value is true. duke@1: */ duke@1: public boolean createindex = true; duke@1: duke@1: /** duke@1: * True if command line option "-use" is used. Default value is false. duke@1: */ duke@1: public boolean classuse = false; duke@1: duke@1: /** duke@1: * False if command line option "-notree" is used. Default value is true. duke@1: */ duke@1: public boolean createtree = true; duke@1: duke@1: /** duke@1: * True if command line option "-nodeprecated" is used. Default value is duke@1: * false. duke@1: */ duke@1: public boolean nodeprecatedlist = false; duke@1: duke@1: /** duke@1: * True if command line option "-nonavbar" is used. Default value is false. duke@1: */ duke@1: public boolean nonavbar = false; duke@1: duke@1: /** duke@1: * True if command line option "-nooverview" is used. Default value is duke@1: * false duke@1: */ duke@1: private boolean nooverview = false; duke@1: duke@1: /** duke@1: * True if command line option "-overview" is used. Default value is false. duke@1: */ duke@1: public boolean overview = false; duke@1: duke@1: /** duke@1: * This is true if option "-overview" is used or option "-overview" is not duke@1: * used and number of packages is more than one. duke@1: */ duke@1: public boolean createoverview = false; duke@1: duke@1: /** duke@1: * Unique Resource Handler for this package. duke@1: */ duke@1: public final MessageRetriever standardmessage; duke@1: duke@1: /** duke@1: * First file to appear in the right-hand frame in the generated duke@1: * documentation. duke@1: */ jjg@1372: public DocPath topFile = DocPath.empty; duke@1: duke@1: /** duke@1: * The classdoc for the class file getting generated. duke@1: */ duke@1: public ClassDoc currentcd = null; // Set this classdoc in the duke@1: // ClassWriter. duke@1: duke@1: /** jjg@1358: * Constructor. Initializes resource for the jjg@1358: * {@link com.sun.tools.doclets.internal.toolkit.util.MessageRetriever MessageRetriever}. duke@1: */ duke@1: private ConfigurationImpl() { duke@1: standardmessage = new MessageRetriever(this, duke@1: "com.sun.tools.doclets.formats.html.resources.standard"); duke@1: } duke@1: jjg@140: /** jjg@140: * Reset to a fresh new ConfigurationImpl, to allow multiple invocations jjg@140: * of javadoc within a single VM. It would be better not to be using jjg@140: * static fields at all, but .... (sigh). jjg@140: */ jjg@140: public static void reset() { jjg@140: instance = new ConfigurationImpl(); jjg@140: } jjg@140: duke@1: public static ConfigurationImpl getInstance() { duke@1: return instance; duke@1: } duke@1: duke@1: /** duke@1: * Return the build date for the doclet. duke@1: */ duke@1: public String getDocletSpecificBuildDate() { duke@1: return BUILD_DATE; duke@1: } duke@1: duke@1: /** duke@1: * Depending upon the command line options provided by the user, set duke@1: * configure the output generation environment. duke@1: * duke@1: * @param options The array of option names and values. duke@1: */ duke@1: public void setSpecificDocletOptions(String[][] options) { duke@1: for (int oi = 0; oi < options.length; ++oi) { duke@1: String[] os = options[oi]; duke@1: String opt = os[0].toLowerCase(); duke@1: if (opt.equals("-footer")) { bpatel@1324: footer = os[1]; bpatel@1324: } else if (opt.equals("-header")) { bpatel@1324: header = os[1]; bpatel@1324: } else if (opt.equals("-packagesheader")) { bpatel@1324: packagesheader = os[1]; bpatel@1324: } else if (opt.equals("-doctitle")) { bpatel@1324: doctitle = os[1]; bpatel@1324: } else if (opt.equals("-windowtitle")) { bpatel@1324: windowtitle = os[1]; bpatel@1324: } else if (opt.equals("-top")) { bpatel@1324: top = os[1]; bpatel@1324: } else if (opt.equals("-bottom")) { bpatel@1324: bottom = os[1]; bpatel@1324: } else if (opt.equals("-helpfile")) { bpatel@1324: helpfile = os[1]; bpatel@1324: } else if (opt.equals("-stylesheetfile")) { bpatel@1324: stylesheetfile = os[1]; bpatel@1324: } else if (opt.equals("-charset")) { bpatel@1324: charset = os[1]; bpatel@997: } else if (opt.equals("-xdocrootparent")) { bpatel@997: docrootparent = os[1]; bpatel@1324: } else if (opt.equals("-nohelp")) { duke@1: nohelp = true; bpatel@1324: } else if (opt.equals("-splitindex")) { duke@1: splitindex = true; bpatel@1324: } else if (opt.equals("-noindex")) { duke@1: createindex = false; bpatel@1324: } else if (opt.equals("-use")) { duke@1: classuse = true; bpatel@1324: } else if (opt.equals("-notree")) { duke@1: createtree = false; bpatel@1324: } else if (opt.equals("-nodeprecatedlist")) { duke@1: nodeprecatedlist = true; bpatel@1324: } else if (opt.equals("-nonavbar")) { duke@1: nonavbar = true; bpatel@1324: } else if (opt.equals("-nooverview")) { duke@1: nooverview = true; bpatel@1324: } else if (opt.equals("-overview")) { duke@1: overview = true; duke@1: } duke@1: } duke@1: if (root.specifiedClasses().length > 0) { jjg@74: Map map = new HashMap(); duke@1: PackageDoc pd; duke@1: ClassDoc[] classes = root.classes(); duke@1: for (int i = 0; i < classes.length; i++) { duke@1: pd = classes[i].containingPackage(); duke@1: if(! map.containsKey(pd.name())) { duke@1: map.put(pd.name(), pd); duke@1: } duke@1: } duke@1: } duke@1: setCreateOverview(); duke@1: setTopFile(root); duke@1: } duke@1: duke@1: /** duke@1: * Returns the "length" of a given option. If an option takes no duke@1: * arguments, its length is one. If it takes one argument, it's duke@1: * length is two, and so on. This method is called by JavaDoc to duke@1: * parse the options it does not recognize. It then calls duke@1: * {@link #validOptions(String[][], DocErrorReporter)} to duke@1: * validate them. duke@1: * Note:
duke@1: * The options arrive as case-sensitive strings. For options that duke@1: * are not case-sensitive, use toLowerCase() on the option string duke@1: * before comparing it. duke@1: * duke@1: * duke@1: * @return number of arguments + 1 for a option. Zero return means duke@1: * option not known. Negative value means error occurred. duke@1: */ duke@1: public int optionLength(String option) { duke@1: int result = -1; duke@1: if ((result = super.optionLength(option)) > 0) { duke@1: return result; duke@1: } duke@1: // otherwise look for the options we have added duke@1: option = option.toLowerCase(); duke@1: if (option.equals("-nodeprecatedlist") || duke@1: option.equals("-noindex") || duke@1: option.equals("-notree") || duke@1: option.equals("-nohelp") || duke@1: option.equals("-splitindex") || duke@1: option.equals("-serialwarn") || duke@1: option.equals("-use") || duke@1: option.equals("-nonavbar") || duke@1: option.equals("-nooverview")) { duke@1: return 1; duke@1: } else if (option.equals("-help")) { duke@1: System.out.println(getText("doclet.usage")); duke@1: return 1; duke@1: } else if (option.equals("-footer") || duke@1: option.equals("-header") || duke@1: option.equals("-packagesheader") || duke@1: option.equals("-doctitle") || duke@1: option.equals("-windowtitle") || duke@1: option.equals("-top") || duke@1: option.equals("-bottom") || duke@1: option.equals("-helpfile") || duke@1: option.equals("-stylesheetfile") || duke@1: option.equals("-charset") || bpatel@997: option.equals("-overview") || bpatel@997: option.equals("-xdocrootparent")) { duke@1: return 2; duke@1: } else { duke@1: return 0; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public boolean validOptions(String options[][], duke@1: DocErrorReporter reporter) { duke@1: boolean helpfile = false; duke@1: boolean nohelp = false; duke@1: boolean overview = false; duke@1: boolean nooverview = false; duke@1: boolean splitindex = false; duke@1: boolean noindex = false; duke@1: // check shared options duke@1: if (!generalValidOptions(options, reporter)) { duke@1: return false; duke@1: } duke@1: // otherwise look at our options duke@1: for (int oi = 0; oi < options.length; ++oi) { duke@1: String[] os = options[oi]; duke@1: String opt = os[0].toLowerCase(); duke@1: if (opt.equals("-helpfile")) { duke@1: if (nohelp == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-helpfile", "-nohelp")); duke@1: return false; duke@1: } duke@1: if (helpfile == true) { duke@1: reporter.printError(getText("doclet.Option_reuse", duke@1: "-helpfile")); duke@1: return false; duke@1: } jjg@1383: DocFile help = DocFile.createFileForInput(this, os[1]); duke@1: if (!help.exists()) { duke@1: reporter.printError(getText("doclet.File_not_found", os[1])); duke@1: return false; duke@1: } duke@1: helpfile = true; duke@1: } else if (opt.equals("-nohelp")) { duke@1: if (helpfile == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-nohelp", "-helpfile")); duke@1: return false; duke@1: } duke@1: nohelp = true; bpatel@997: } else if (opt.equals("-xdocrootparent")) { bpatel@997: try { bpatel@997: new URL(os[1]); bpatel@997: } catch (MalformedURLException e) { bpatel@997: reporter.printError(getText("doclet.MalformedURL", os[1])); bpatel@997: return false; bpatel@997: } duke@1: } else if (opt.equals("-overview")) { duke@1: if (nooverview == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-overview", "-nooverview")); duke@1: return false; duke@1: } duke@1: if (overview == true) { duke@1: reporter.printError(getText("doclet.Option_reuse", duke@1: "-overview")); duke@1: return false; duke@1: } duke@1: overview = true; duke@1: } else if (opt.equals("-nooverview")) { duke@1: if (overview == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-nooverview", "-overview")); duke@1: return false; duke@1: } duke@1: nooverview = true; duke@1: } else if (opt.equals("-splitindex")) { duke@1: if (noindex == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-splitindex", "-noindex")); duke@1: return false; duke@1: } duke@1: splitindex = true; duke@1: } else if (opt.equals("-noindex")) { duke@1: if (splitindex == true) { duke@1: reporter.printError(getText("doclet.Option_conflict", duke@1: "-noindex", "-splitindex")); duke@1: return false; duke@1: } duke@1: noindex = true; duke@1: } duke@1: } duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public MessageRetriever getDocletSpecificMsg() { duke@1: return standardmessage; duke@1: } duke@1: duke@1: /** duke@1: * Decide the page which will appear first in the right-hand frame. It will duke@1: * be "overview-summary.html" if "-overview" option is used or no duke@1: * "-overview" but the number of packages is more than one. It will be duke@1: * "package-summary.html" of the respective package if there is only one duke@1: * package to document. It will be a class page(first in the sorted order), duke@1: * if only classes are provided on the command line. duke@1: * duke@1: * @param root Root of the program structure. duke@1: */ duke@1: protected void setTopFile(RootDoc root) { duke@1: if (!checkForDeprecation(root)) { duke@1: return; duke@1: } duke@1: if (createoverview) { jjg@1372: topFile = DocPaths.OVERVIEW_SUMMARY; duke@1: } else { duke@1: if (packages.length == 1 && packages[0].name().equals("")) { duke@1: if (root.classes().length > 0) { duke@1: ClassDoc[] classarr = root.classes(); duke@1: Arrays.sort(classarr); duke@1: ClassDoc cd = getValidClass(classarr); jjg@1372: topFile = DocPath.forClass(cd); duke@1: } duke@1: } else { jjg@1372: topFile = DocPath.forPackage(packages[0]).resolve(DocPaths.PACKAGE_SUMMARY); duke@1: } duke@1: } duke@1: } duke@1: duke@1: protected ClassDoc getValidClass(ClassDoc[] classarr) { duke@1: if (!nodeprecated) { duke@1: return classarr[0]; duke@1: } duke@1: for (int i = 0; i < classarr.length; i++) { duke@1: if (classarr[i].tags("deprecated").length == 0) { duke@1: return classarr[i]; duke@1: } duke@1: } duke@1: return null; duke@1: } duke@1: duke@1: protected boolean checkForDeprecation(RootDoc root) { duke@1: ClassDoc[] classarr = root.classes(); duke@1: for (int i = 0; i < classarr.length; i++) { duke@1: if (isGeneratedDoc(classarr[i])) { duke@1: return true; duke@1: } duke@1: } duke@1: return false; duke@1: } duke@1: duke@1: /** duke@1: * Generate "overview.html" page if option "-overview" is used or number of duke@1: * packages is more than one. Sets {@link #createoverview} field to true. duke@1: */ duke@1: protected void setCreateOverview() { duke@1: if ((overview || packages.length > 1) && !nooverview) { duke@1: createoverview = true; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public WriterFactory getWriterFactory() { jjg@140: return new WriterFactoryImpl(this); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ jjg@74: public Comparator getMemberComparator() { duke@1: return null; duke@1: } bpatel@191: bpatel@191: /** bpatel@191: * {@inheritDoc} bpatel@191: */ bpatel@191: public Locale getLocale() { bpatel@191: if (root instanceof com.sun.tools.javadoc.RootDocImpl) bpatel@191: return ((com.sun.tools.javadoc.RootDocImpl)root).getLocale(); bpatel@191: else bpatel@191: return Locale.getDefault(); bpatel@191: } duke@1: }