1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,487 @@ 1.4 +/* 1.5 + * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import com.sun.tools.doclets.internal.toolkit.*; 1.32 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.33 + 1.34 +import com.sun.javadoc.*; 1.35 +import java.util.*; 1.36 +import java.io.*; 1.37 + 1.38 +/** 1.39 + * Configure the output based on the command line options. 1.40 + * <p> 1.41 + * Also determine the length of the command line option. For example, 1.42 + * for a option "-header" there will be a string argument associated, then the 1.43 + * the length of option "-header" is two. But for option "-nohelp" no argument 1.44 + * is needed so it's length is 1. 1.45 + * </p> 1.46 + * <p> 1.47 + * Also do the error checking on the options used. For example it is illegal to 1.48 + * use "-helpfile" option when already "-nohelp" option is used. 1.49 + * </p> 1.50 + * 1.51 + * @author Robert Field. 1.52 + * @author Atul Dambalkar. 1.53 + * @author Jamie Ho 1.54 + */ 1.55 +public class ConfigurationImpl extends Configuration { 1.56 + 1.57 + private static final ConfigurationImpl instance = new ConfigurationImpl(); 1.58 + 1.59 + /** 1.60 + * The build date. Note: For now, we will use 1.61 + * a version number instead of a date. 1.62 + */ 1.63 + public static final String BUILD_DATE = System.getProperty("java.version"); 1.64 + 1.65 + /** 1.66 + * The name of the constant values file. 1.67 + */ 1.68 + public static final String CONSTANTS_FILE_NAME = "constant-values.html"; 1.69 + 1.70 + /** 1.71 + * Argument for command line option "-header". 1.72 + */ 1.73 + public String header = ""; 1.74 + 1.75 + /** 1.76 + * Argument for command line option "-packagesheader". 1.77 + */ 1.78 + public String packagesheader = ""; 1.79 + 1.80 + /** 1.81 + * Argument for command line option "-footer". 1.82 + */ 1.83 + public String footer = ""; 1.84 + 1.85 + /** 1.86 + * Argument for command line option "-doctitle". 1.87 + */ 1.88 + public String doctitle = ""; 1.89 + 1.90 + /** 1.91 + * Argument for command line option "-windowtitle". 1.92 + */ 1.93 + public String windowtitle = ""; 1.94 + 1.95 + /** 1.96 + * Argument for command line option "-top". 1.97 + */ 1.98 + public String top = ""; 1.99 + 1.100 + /** 1.101 + * Argument for command line option "-bottom". 1.102 + */ 1.103 + public String bottom = ""; 1.104 + 1.105 + /** 1.106 + * Argument for command line option "-helpfile". 1.107 + */ 1.108 + public String helpfile = ""; 1.109 + 1.110 + /** 1.111 + * Argument for command line option "-stylesheetfile". 1.112 + */ 1.113 + public String stylesheetfile = ""; 1.114 + 1.115 + /** 1.116 + * True if command line option "-nohelp" is used. Default value is false. 1.117 + */ 1.118 + public boolean nohelp = false; 1.119 + 1.120 + /** 1.121 + * True if command line option "-splitindex" is used. Default value is 1.122 + * false. 1.123 + */ 1.124 + public boolean splitindex = false; 1.125 + 1.126 + /** 1.127 + * False if command line option "-noindex" is used. Default value is true. 1.128 + */ 1.129 + public boolean createindex = true; 1.130 + 1.131 + /** 1.132 + * True if command line option "-use" is used. Default value is false. 1.133 + */ 1.134 + public boolean classuse = false; 1.135 + 1.136 + /** 1.137 + * False if command line option "-notree" is used. Default value is true. 1.138 + */ 1.139 + public boolean createtree = true; 1.140 + 1.141 + /** 1.142 + * True if command line option "-nodeprecated" is used. Default value is 1.143 + * false. 1.144 + */ 1.145 + public boolean nodeprecatedlist = false; 1.146 + 1.147 + /** 1.148 + * True if command line option "-nonavbar" is used. Default value is false. 1.149 + */ 1.150 + public boolean nonavbar = false; 1.151 + 1.152 + /** 1.153 + * True if command line option "-nooverview" is used. Default value is 1.154 + * false 1.155 + */ 1.156 + private boolean nooverview = false; 1.157 + 1.158 + /** 1.159 + * True if command line option "-overview" is used. Default value is false. 1.160 + */ 1.161 + public boolean overview = false; 1.162 + 1.163 + /** 1.164 + * This is true if option "-overview" is used or option "-overview" is not 1.165 + * used and number of packages is more than one. 1.166 + */ 1.167 + public boolean createoverview = false; 1.168 + 1.169 + /** 1.170 + * Unique Resource Handler for this package. 1.171 + */ 1.172 + public final MessageRetriever standardmessage; 1.173 + 1.174 + /** 1.175 + * First file to appear in the right-hand frame in the generated 1.176 + * documentation. 1.177 + */ 1.178 + public String topFile = ""; 1.179 + 1.180 + /** 1.181 + * The classdoc for the class file getting generated. 1.182 + */ 1.183 + public ClassDoc currentcd = null; // Set this classdoc in the 1.184 + // ClassWriter. 1.185 + 1.186 + /** 1.187 + * Constructor. Initialises resource for the 1.188 + * {@link com.sun.tools.doclets.MessageRetriever}. 1.189 + */ 1.190 + private ConfigurationImpl() { 1.191 + standardmessage = new MessageRetriever(this, 1.192 + "com.sun.tools.doclets.formats.html.resources.standard"); 1.193 + } 1.194 + 1.195 + public static ConfigurationImpl getInstance() { 1.196 + return instance; 1.197 + } 1.198 + 1.199 + /** 1.200 + * Return the build date for the doclet. 1.201 + */ 1.202 + public String getDocletSpecificBuildDate() { 1.203 + return BUILD_DATE; 1.204 + } 1.205 + 1.206 + /** 1.207 + * Depending upon the command line options provided by the user, set 1.208 + * configure the output generation environment. 1.209 + * 1.210 + * @param options The array of option names and values. 1.211 + */ 1.212 + public void setSpecificDocletOptions(String[][] options) { 1.213 + for (int oi = 0; oi < options.length; ++oi) { 1.214 + String[] os = options[oi]; 1.215 + String opt = os[0].toLowerCase(); 1.216 + if (opt.equals("-footer")) { 1.217 + footer = os[1]; 1.218 + } else if (opt.equals("-header")) { 1.219 + header = os[1]; 1.220 + } else if (opt.equals("-packagesheader")) { 1.221 + packagesheader = os[1]; 1.222 + } else if (opt.equals("-doctitle")) { 1.223 + doctitle = os[1]; 1.224 + } else if (opt.equals("-windowtitle")) { 1.225 + windowtitle = os[1]; 1.226 + } else if (opt.equals("-top")) { 1.227 + top = os[1]; 1.228 + } else if (opt.equals("-bottom")) { 1.229 + bottom = os[1]; 1.230 + } else if (opt.equals("-helpfile")) { 1.231 + helpfile = os[1]; 1.232 + } else if (opt.equals("-stylesheetfile")) { 1.233 + stylesheetfile = os[1]; 1.234 + } else if (opt.equals("-charset")) { 1.235 + charset = os[1]; 1.236 + } else if (opt.equals("-nohelp")) { 1.237 + nohelp = true; 1.238 + } else if (opt.equals("-splitindex")) { 1.239 + splitindex = true; 1.240 + } else if (opt.equals("-noindex")) { 1.241 + createindex = false; 1.242 + } else if (opt.equals("-use")) { 1.243 + classuse = true; 1.244 + } else if (opt.equals("-notree")) { 1.245 + createtree = false; 1.246 + } else if (opt.equals("-nodeprecatedlist")) { 1.247 + nodeprecatedlist = true; 1.248 + } else if (opt.equals("-nosince")) { 1.249 + nosince = true; 1.250 + } else if (opt.equals("-nonavbar")) { 1.251 + nonavbar = true; 1.252 + } else if (opt.equals("-nooverview")) { 1.253 + nooverview = true; 1.254 + } else if (opt.equals("-overview")) { 1.255 + overview = true; 1.256 + } 1.257 + } 1.258 + if (root.specifiedClasses().length > 0) { 1.259 + Map map = new HashMap(); 1.260 + PackageDoc pd; 1.261 + ClassDoc[] classes = root.classes(); 1.262 + for (int i = 0; i < classes.length; i++) { 1.263 + pd = classes[i].containingPackage(); 1.264 + if(! map.containsKey(pd.name())) { 1.265 + map.put(pd.name(), pd); 1.266 + } 1.267 + } 1.268 + } 1.269 + setCreateOverview(); 1.270 + setTopFile(root); 1.271 + } 1.272 + 1.273 + /** 1.274 + * Returns the "length" of a given option. If an option takes no 1.275 + * arguments, its length is one. If it takes one argument, it's 1.276 + * length is two, and so on. This method is called by JavaDoc to 1.277 + * parse the options it does not recognize. It then calls 1.278 + * {@link #validOptions(String[][], DocErrorReporter)} to 1.279 + * validate them. 1.280 + * <b>Note:</b><br> 1.281 + * The options arrive as case-sensitive strings. For options that 1.282 + * are not case-sensitive, use toLowerCase() on the option string 1.283 + * before comparing it. 1.284 + * </blockquote> 1.285 + * 1.286 + * @return number of arguments + 1 for a option. Zero return means 1.287 + * option not known. Negative value means error occurred. 1.288 + */ 1.289 + public int optionLength(String option) { 1.290 + int result = -1; 1.291 + if ((result = super.optionLength(option)) > 0) { 1.292 + return result; 1.293 + } 1.294 + // otherwise look for the options we have added 1.295 + option = option.toLowerCase(); 1.296 + if (option.equals("-nodeprecatedlist") || 1.297 + option.equals("-noindex") || 1.298 + option.equals("-notree") || 1.299 + option.equals("-nohelp") || 1.300 + option.equals("-splitindex") || 1.301 + option.equals("-serialwarn") || 1.302 + option.equals("-use") || 1.303 + option.equals("-nonavbar") || 1.304 + option.equals("-nooverview")) { 1.305 + return 1; 1.306 + } else if (option.equals("-help")) { 1.307 + System.out.println(getText("doclet.usage")); 1.308 + return 1; 1.309 + } else if (option.equals("-footer") || 1.310 + option.equals("-header") || 1.311 + option.equals("-packagesheader") || 1.312 + option.equals("-doctitle") || 1.313 + option.equals("-windowtitle") || 1.314 + option.equals("-top") || 1.315 + option.equals("-bottom") || 1.316 + option.equals("-helpfile") || 1.317 + option.equals("-stylesheetfile") || 1.318 + option.equals("-charset") || 1.319 + option.equals("-overview")) { 1.320 + return 2; 1.321 + } else { 1.322 + return 0; 1.323 + } 1.324 + } 1.325 + 1.326 + /** 1.327 + * {@inheritDoc} 1.328 + */ 1.329 + public boolean validOptions(String options[][], 1.330 + DocErrorReporter reporter) { 1.331 + boolean helpfile = false; 1.332 + boolean nohelp = false; 1.333 + boolean overview = false; 1.334 + boolean nooverview = false; 1.335 + boolean splitindex = false; 1.336 + boolean noindex = false; 1.337 + // check shared options 1.338 + if (!generalValidOptions(options, reporter)) { 1.339 + return false; 1.340 + } 1.341 + // otherwise look at our options 1.342 + for (int oi = 0; oi < options.length; ++oi) { 1.343 + String[] os = options[oi]; 1.344 + String opt = os[0].toLowerCase(); 1.345 + if (opt.equals("-helpfile")) { 1.346 + if (nohelp == true) { 1.347 + reporter.printError(getText("doclet.Option_conflict", 1.348 + "-helpfile", "-nohelp")); 1.349 + return false; 1.350 + } 1.351 + if (helpfile == true) { 1.352 + reporter.printError(getText("doclet.Option_reuse", 1.353 + "-helpfile")); 1.354 + return false; 1.355 + } 1.356 + File help = new File(os[1]); 1.357 + if (!help.exists()) { 1.358 + reporter.printError(getText("doclet.File_not_found", os[1])); 1.359 + return false; 1.360 + } 1.361 + helpfile = true; 1.362 + } else if (opt.equals("-nohelp")) { 1.363 + if (helpfile == true) { 1.364 + reporter.printError(getText("doclet.Option_conflict", 1.365 + "-nohelp", "-helpfile")); 1.366 + return false; 1.367 + } 1.368 + nohelp = true; 1.369 + } else if (opt.equals("-overview")) { 1.370 + if (nooverview == true) { 1.371 + reporter.printError(getText("doclet.Option_conflict", 1.372 + "-overview", "-nooverview")); 1.373 + return false; 1.374 + } 1.375 + if (overview == true) { 1.376 + reporter.printError(getText("doclet.Option_reuse", 1.377 + "-overview")); 1.378 + return false; 1.379 + } 1.380 + overview = true; 1.381 + } else if (opt.equals("-nooverview")) { 1.382 + if (overview == true) { 1.383 + reporter.printError(getText("doclet.Option_conflict", 1.384 + "-nooverview", "-overview")); 1.385 + return false; 1.386 + } 1.387 + nooverview = true; 1.388 + } else if (opt.equals("-splitindex")) { 1.389 + if (noindex == true) { 1.390 + reporter.printError(getText("doclet.Option_conflict", 1.391 + "-splitindex", "-noindex")); 1.392 + return false; 1.393 + } 1.394 + splitindex = true; 1.395 + } else if (opt.equals("-noindex")) { 1.396 + if (splitindex == true) { 1.397 + reporter.printError(getText("doclet.Option_conflict", 1.398 + "-noindex", "-splitindex")); 1.399 + return false; 1.400 + } 1.401 + noindex = true; 1.402 + } 1.403 + } 1.404 + return true; 1.405 + } 1.406 + 1.407 + /** 1.408 + * {@inheritDoc} 1.409 + */ 1.410 + public MessageRetriever getDocletSpecificMsg() { 1.411 + return standardmessage; 1.412 + } 1.413 + 1.414 + /** 1.415 + * Decide the page which will appear first in the right-hand frame. It will 1.416 + * be "overview-summary.html" if "-overview" option is used or no 1.417 + * "-overview" but the number of packages is more than one. It will be 1.418 + * "package-summary.html" of the respective package if there is only one 1.419 + * package to document. It will be a class page(first in the sorted order), 1.420 + * if only classes are provided on the command line. 1.421 + * 1.422 + * @param root Root of the program structure. 1.423 + */ 1.424 + protected void setTopFile(RootDoc root) { 1.425 + if (!checkForDeprecation(root)) { 1.426 + return; 1.427 + } 1.428 + if (createoverview) { 1.429 + topFile = "overview-summary.html"; 1.430 + } else { 1.431 + if (packages.length == 1 && packages[0].name().equals("")) { 1.432 + if (root.classes().length > 0) { 1.433 + ClassDoc[] classarr = root.classes(); 1.434 + Arrays.sort(classarr); 1.435 + ClassDoc cd = getValidClass(classarr); 1.436 + topFile = DirectoryManager.getPathToClass(cd); 1.437 + } 1.438 + } else { 1.439 + topFile = DirectoryManager.getPathToPackage(packages[0], 1.440 + "package-summary.html"); 1.441 + } 1.442 + } 1.443 + } 1.444 + 1.445 + protected ClassDoc getValidClass(ClassDoc[] classarr) { 1.446 + if (!nodeprecated) { 1.447 + return classarr[0]; 1.448 + } 1.449 + for (int i = 0; i < classarr.length; i++) { 1.450 + if (classarr[i].tags("deprecated").length == 0) { 1.451 + return classarr[i]; 1.452 + } 1.453 + } 1.454 + return null; 1.455 + } 1.456 + 1.457 + protected boolean checkForDeprecation(RootDoc root) { 1.458 + ClassDoc[] classarr = root.classes(); 1.459 + for (int i = 0; i < classarr.length; i++) { 1.460 + if (isGeneratedDoc(classarr[i])) { 1.461 + return true; 1.462 + } 1.463 + } 1.464 + return false; 1.465 + } 1.466 + 1.467 + /** 1.468 + * Generate "overview.html" page if option "-overview" is used or number of 1.469 + * packages is more than one. Sets {@link #createoverview} field to true. 1.470 + */ 1.471 + protected void setCreateOverview() { 1.472 + if ((overview || packages.length > 1) && !nooverview) { 1.473 + createoverview = true; 1.474 + } 1.475 + } 1.476 + 1.477 + /** 1.478 + * {@inheritDoc} 1.479 + */ 1.480 + public WriterFactory getWriterFactory() { 1.481 + return WriterFactoryImpl.getInstance(); 1.482 + } 1.483 + 1.484 + /** 1.485 + * {@inheritDoc} 1.486 + */ 1.487 + public Comparator getMemberComparator() { 1.488 + return null; 1.489 + } 1.490 +}