/* * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.doclets.internal.toolkit; import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.tools.JavaFileManager; import javax.tools.JavaFileManager.Location; import com.sun.javadoc.*; import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory; import com.sun.tools.doclets.internal.toolkit.taglets.*; import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.javac.util.StringUtils; /** * Configure the output based on the options. Doclets should sub-class * Configuration, to configure and add their own options. This class contains * all user options which are supported by the 1.1 doclet and the standard * doclet. * *
This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*
* @author Robert Field.
* @author Atul Dambalkar.
* @author Jamie Ho
*/
public abstract class Configuration {
/**
* Exception used to report a problem during setOptions.
*/
public static class Fault extends Exception {
private static final long serialVersionUID = 0;
Fault(String msg) {
super(msg);
}
Fault(String msg, Exception cause) {
super(msg, cause);
}
}
/**
* The factory for builders.
*/
protected BuilderFactory builderFactory;
/**
* The taglet manager.
*/
public TagletManager tagletManager;
/**
* The path to the builder XML input file.
*/
public String builderXMLPath;
/**
* The default path to the builder XML.
*/
private static final String DEFAULT_BUILDER_XML = "resources/doclet.xml";
/**
* The path to Taglets
*/
public String tagletpath = "";
/**
* This is true if option "-serialwarn" is used. Defualt value is false to
* suppress excessive warnings about serial tag.
*/
public boolean serialwarn = false;
/**
* The specified amount of space between tab stops.
*/
public int sourcetab;
public String tabSpaces;
/**
* True if we should generate browsable sources.
*/
public boolean linksource = false;
/**
* True if command line option "-nosince" is used. Default value is
* false.
*/
public boolean nosince = false;
/**
* True if we should recursively copy the doc-file subdirectories
*/
public boolean copydocfilesubdirs = false;
/**
* The META charset tag used for cross-platform viewing.
*/
public String charset = "";
/**
* True if user wants to add member names as meta keywords.
* Set to false because meta keywords are ignored in general
* by most Internet search engines.
*/
public boolean keywords = false;
/**
* The meta tag keywords instance.
*/
public final MetaKeywords metakeywords;
/**
* The list of doc-file subdirectories to exclude
*/
protected Setshowauthor
is set to true if -author option is used.
* Default is don't show author information.
*/
public boolean showauthor = false;
/**
* Generate documentation for JavaFX getters and setters automatically
* by copying it from the appropriate property definition.
*/
public boolean javafx = false;
/**
* Generate version specific information for the all the classes
* if @version tag is used in the doc comment and if -version option is
* used. showversion
is set to true if -version option is
* used.Default is don't show version information.
*/
public boolean showversion = false;
/**
* Don't generate deprecated API information at all, if -nodeprecated
* option is used. nodepracted
is set to true if
* -nodeprecated option is used. Default is generate deprected API
* information.
*/
public boolean nodeprecated = false;
/**
* The catalog of classes specified on the command-line
*/
public ClassDocCatalog classDocCatalog;
/**
* Message Retriever for the doclet, to retrieve message from the resource
* file for this Configuration, which is common for 1.1 and standard
* doclets.
*
* TODO: Make this private!!!
*/
public MessageRetriever message = null;
/**
* True if user wants to suppress time stamp in output.
* Default is false.
*/
public boolean notimestamp= false;
/**
* The package grouping instance.
*/
public final Group group = new Group(this);
/**
* The tracker of external package links.
*/
public final Extern extern = new Extern(this);
/**
* Return the build date for the doclet.
*/
public abstract String getDocletSpecificBuildDate();
/**
* This method should be defined in all those doclets(configurations),
* which want to derive themselves from this Configuration. This method
* can be used to set its own command line options.
*
* @param options The array of option names and values.
* @throws DocletAbortException
*/
public abstract void setSpecificDocletOptions(String[][] options) throws Fault;
/**
* Return the doclet specific {@link MessageRetriever}
* @return the doclet specific MessageRetriever.
*/
public abstract MessageRetriever getDocletSpecificMsg();
/**
* A sorted set of packages specified on the command-line merged with a
* collection of packages that contain the classes specified on the
* command-line.
*/
public SortedSetClassDoc
if it's qualifier is not excluded. Otherwise,
* return the unqualified ClassDoc
name.
* @param cd the ClassDoc
to check.
*/
public String getClassName(ClassDoc cd) {
PackageDoc pd = cd.containingPackage();
if (pd != null && shouldExcludeQualifier(cd.containingPackage().name())) {
return cd.name();
} else {
return cd.qualifiedName();
}
}
public String getText(String key) {
//Check the doclet specific properties file.
if (getDocletSpecificMsg().containsKey(key)) {
return getDocletSpecificMsg().getText(key);
}
//Check the shared properties file.
return message.getText(key);
}
public String getText(String key, String a1) {
//Check the doclet specific properties file.
if (getDocletSpecificMsg().containsKey(key)) {
return getDocletSpecificMsg().getText(key, a1);
}
//Check the shared properties file.
return message.getText(key, a1);
}
public String getText(String key, String a1, String a2) {
//Check the doclet specific properties file.
if (getDocletSpecificMsg().containsKey(key)) {
return getDocletSpecificMsg().getText(key, a1, a2);
}
//Check the shared properties file.
return message.getText(key, a1, a2);
}
public String getText(String key, String a1, String a2, String a3) {
//Check the doclet specific properties file.
if (getDocletSpecificMsg().containsKey(key)) {
return getDocletSpecificMsg().getText(key, a1, a2, a3);
}
//Check the shared properties file.
return message.getText(key, a1, a2, a3);
}
public abstract Content newContent();
/**
* Get the configuration string as a content.
*
* @param key the key to look for in the configuration file
* @return a content tree for the text
*/
public Content getResource(String key) {
Content c = newContent();
c.addContent(getText(key));
return c;
}
/**
* Get the configuration string as a content.
*
* @param key the key to look for in the configuration file
* @param o string or content argument added to configuration text
* @return a content tree for the text
*/
public Content getResource(String key, Object o) {
return getResource(key, o, null, null);
}
/**
* Get the configuration string as a content.
*
* @param key the key to look for in the configuration file
* @param o string or content argument added to configuration text
* @return a content tree for the text
*/
public Content getResource(String key, Object o1, Object o2) {
return getResource(key, o1, o2, null);
}
/**
* Get the configuration string as a content.
*
* @param key the key to look for in the configuration file
* @param o1 string or content argument added to configuration text
* @param o2 string or content argument added to configuration text
* @return a content tree for the text
*/
public Content getResource(String key, Object o0, Object o1, Object o2) {
Content c = newContent();
Pattern p = Pattern.compile("\\{([012])\\}");
String text = getText(key);
Matcher m = p.matcher(text);
int start = 0;
while (m.find(start)) {
c.addContent(text.substring(start, m.start()));
Object o = null;
switch (m.group(1).charAt(0)) {
case '0': o = o0; break;
case '1': o = o1; break;
case '2': o = o2; break;
}
if (o == null) {
c.addContent("{" + m.group(1) + "}");
} else if (o instanceof String) {
c.addContent((String) o);
} else if (o instanceof Content) {
c.addContent((Content) o);
}
start = m.end();
}
c.addContent(text.substring(start));
return c;
}
/**
* Return true if the ClassDoc element is getting documented, depending upon
* -nodeprecated option and the deprecation information. Return true if
* -nodeprecated is not used. Return false if -nodeprecated is used and if
* either ClassDoc element is deprecated or the containing package is deprecated.
*
* @param cd the ClassDoc for which the page generation is checked
*/
public boolean isGeneratedDoc(ClassDoc cd) {
if (!nodeprecated) {
return true;
}
return !(utils.isDeprecated(cd) || utils.isDeprecated(cd.containingPackage()));
}
/**
* Return the doclet specific instance of a writer factory.
* @return the {@link WriterFactory} for the doclet.
*/
public abstract WriterFactory getWriterFactory();
/**
* Return the input stream to the builder XML.
*
* @return the input steam to the builder XML.
* @throws FileNotFoundException when the given XML file cannot be found.
*/
public InputStream getBuilderXML() throws IOException {
return builderXMLPath == null ?
Configuration.class.getResourceAsStream(DEFAULT_BUILDER_XML) :
DocFile.createFileForInput(this, builderXMLPath).openInputStream();
}
/**
* Return the Locale for this document.
*/
public abstract Locale getLocale();
/**
* Return the current file manager.
*/
public abstract JavaFileManager getFileManager();
/**
* Return the comparator that will be used to sort member documentation.
* To no do any sorting, return null.
*
* @return the {@link java.util.Comparator} used to sort members.
*/
public abstract Comparator