/* * @(#)Configuration.java 1.7 98/04/30 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.tools.doclets; import com.sun.javadoc.*; import java.util.*; import java.io.*; /** * Configure the output based on the options. Specific Doclets should sub-class * this one, to configure and add their own options. * * @author Robert Field. * @author Atul Dambalkar. */ public abstract class Configuration { public static RootDoc root; public String destdirname = ""; public String docencoding = null; public String encoding = null; public String sourcepath = ""; public boolean showauthor = false; public boolean showversion = false; public boolean linkall = false; public boolean nodate = false; public PackageDoc[] packages; public static MessageRetriever message = null; public abstract void setSpecificDocletOptions(RootDoc root); public abstract int specificDocletOptionLength(String option); public Configuration() { if (message == null) { message = new MessageRetriever("com.sun.tools.javadoc.resources.doclets"); } } public void setOptions(RootDoc root) throws DocletAbortException { String[][] options = root.options(); Configuration.root = root; packages = root.specifiedPackages(); for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; String opt = os[0].toLowerCase(); if (opt.equals("-d")) { destdirname = addTrailingFileSep(os[1]); } else if (opt.equals("-docencoding")) { docencoding = os[1]; } else if (opt.equals("-encoding")) { encoding = os[1]; } else if (opt.equals("-author")) { showauthor = true; } else if (opt.equals("-version")) { showversion = true; } else if (opt.equals("-linkall")) { linkall = true; } else if (opt.equals("-xnodate")) { nodate = true; } else if (opt.equals("-sourcepath") || (opt.equals("-classpath"))) { sourcepath = os[1]; } } if (docencoding == null) { docencoding = encoding; } setSpecificDocletOptions(root); HtmlDocWriter.configuration = this; } String addTrailingFileSep(String path) { String fs = System.getProperty("file.separator"); if (!path.endsWith(fs)) path += fs; return path; } /** * Check for doclet added options here. * * @return number of arguments to option. Zero return means * option not known. Negative value means error occurred. */ public int optionLength(String option) { option = option.toLowerCase(); if (option.equals("-version") || option.equals("-author") || option.equals("-linkall") || option.equals("-xnodate")) { return 1; } else if (option.equals("-docencoding") || option.equals("-encoding") || option.equals("-sourcepath") || option.equals("-d") ) { return 2; } else { return specificDocletOptionLength(option); } } /** * Check that options have the correct arguments here. *

* This method is not required and will default gracefully * (to true) if absent. *

* Printing option related error messages (using the provided * DocErrorReporter) is the responsibility of this method. * * @return true if the options are valid. */ public static boolean validOptions(String options[][], DocErrorReporter reporter) { for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; String opt = os[0].toLowerCase(); if (opt.equals("-d")) { String dd = os[1]; File destDir = new File(dd); if (!destDir.exists()) { reporter.printError(message.getText( "doclet.destination_directory_not_found_0", destDir.getPath())); return false; } else if (!destDir.isDirectory()) { reporter.printError(message.getText( "doclet.destination_directory_not_directory_0", destDir.getPath())); return false; } else if (!destDir.canWrite()) { reporter.printError(message.getText( "doclet.destination_directory_not_writable_0", destDir.getPath())); return false; } } } return true; } }