0N/A/*
994N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/Apackage com.sun.tools.doclets.formats.html;
0N/A
0N/Aimport com.sun.tools.doclets.internal.toolkit.*;
0N/Aimport com.sun.tools.doclets.internal.toolkit.builders.*;
0N/Aimport com.sun.tools.doclets.internal.toolkit.util.*;
0N/A
0N/Aimport com.sun.javadoc.*;
0N/Aimport java.util.*;
0N/Aimport java.io.*;
0N/A
0N/A/**
0N/A * The class with "start" method, calls individual Writers.
0N/A *
0N/A * @author Atul M Dambalkar
0N/A * @author Robert Field
0N/A * @author Jamie Ho
0N/A *
0N/A */
0N/Apublic class HtmlDoclet extends AbstractDoclet {
139N/A public HtmlDoclet() {
139N/A configuration = (ConfigurationImpl) configuration();
139N/A }
0N/A
0N/A /**
0N/A * The global configuration information for this run.
0N/A */
139N/A public ConfigurationImpl configuration;
0N/A
0N/A /**
0N/A * The "start" method as required by Javadoc.
0N/A *
0N/A * @param root the root of the documentation tree.
0N/A * @see com.sun.javadoc.RootDoc
0N/A * @return true if the doclet ran without encountering any errors.
0N/A */
0N/A public static boolean start(RootDoc root) {
139N/A try {
139N/A HtmlDoclet doclet = new HtmlDoclet();
139N/A return doclet.start(doclet, root);
139N/A } finally {
139N/A ConfigurationImpl.reset();
139N/A }
0N/A }
0N/A
0N/A /**
0N/A * Create the configuration instance.
0N/A * Override this method to use a different
0N/A * configuration.
0N/A */
0N/A public Configuration configuration() {
0N/A return ConfigurationImpl.getInstance();
0N/A }
0N/A
0N/A /**
0N/A * Start the generation of files. Call generate methods in the individual
0N/A * writers, which will in turn genrate the documentation files. Call the
0N/A * TreeWriter generation first to ensure the Class Hierarchy is built
0N/A * first and then can be used in the later generation.
0N/A *
0N/A * For new format.
0N/A *
0N/A * @see com.sun.javadoc.RootDoc
0N/A */
0N/A protected void generateOtherFiles(RootDoc root, ClassTree classtree)
0N/A throws Exception {
0N/A super.generateOtherFiles(root, classtree);
0N/A if (configuration.linksource) {
0N/A if (configuration.destDirName.length() > 0) {
0N/A SourceToHTMLConverter.convertRoot(configuration,
0N/A root, configuration.destDirName + File.separator
0N/A + DocletConstants.SOURCE_OUTPUT_DIR_NAME);
0N/A } else {
0N/A SourceToHTMLConverter.convertRoot(configuration,
0N/A root, DocletConstants.SOURCE_OUTPUT_DIR_NAME);
0N/A }
0N/A }
0N/A
0N/A if (configuration.topFile.length() == 0) {
0N/A configuration.standardmessage.
0N/A error("doclet.No_Non_Deprecated_Classes_To_Document");
0N/A return;
0N/A }
0N/A boolean nodeprecated = configuration.nodeprecated;
0N/A String configdestdir = configuration.destDirName;
0N/A String confighelpfile = configuration.helpfile;
0N/A String configstylefile = configuration.stylesheetfile;
0N/A performCopy(configdestdir, confighelpfile);
0N/A performCopy(configdestdir, configstylefile);
1030N/A Util.copyResourceFile(configuration, "background.gif", false);
1030N/A Util.copyResourceFile(configuration, "tab.gif", false);
1030N/A Util.copyResourceFile(configuration, "titlebar.gif", false);
1030N/A Util.copyResourceFile(configuration, "titlebar_end.gif", false);
0N/A // do early to reduce memory footprint
0N/A if (configuration.classuse) {
0N/A ClassUseWriter.generate(configuration, classtree);
0N/A }
0N/A IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated);
0N/A
0N/A if (configuration.createtree) {
0N/A TreeWriter.generate(configuration, classtree);
0N/A }
0N/A if (configuration.createindex) {
0N/A if (configuration.splitindex) {
0N/A SplitIndexWriter.generate(configuration, indexbuilder);
0N/A } else {
0N/A SingleIndexWriter.generate(configuration, indexbuilder);
0N/A }
0N/A }
0N/A
0N/A if (!(configuration.nodeprecatedlist || nodeprecated)) {
0N/A DeprecatedListWriter.generate(configuration);
0N/A }
0N/A
0N/A AllClassesFrameWriter.generate(configuration,
0N/A new IndexBuilder(configuration, nodeprecated, true));
0N/A
0N/A FrameOutputWriter.generate(configuration);
0N/A
0N/A if (configuration.createoverview) {
0N/A PackageIndexWriter.generate(configuration);
0N/A }
0N/A if (configuration.helpfile.length() == 0 &&
0N/A !configuration.nohelp) {
0N/A HelpWriter.generate(configuration);
0N/A }
792N/A // If a stylesheet file is not specified, copy the default stylesheet
792N/A // and replace newline with platform-specific newline.
0N/A if (configuration.stylesheetfile.length() == 0) {
765N/A Util.copyFile(configuration, "stylesheet.css", Util.RESOURCESDIR,
765N/A (configdestdir.isEmpty()) ?
792N/A System.getProperty("user.dir") : configdestdir, false, true);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) {
0N/A Arrays.sort(arr);
0N/A for(int i = 0; i < arr.length; i++) {
0N/A if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) {
0N/A continue;
0N/A }
0N/A ClassDoc prev = (i == 0)?
0N/A null:
0N/A arr[i-1];
0N/A ClassDoc curr = arr[i];
0N/A ClassDoc next = (i+1 == arr.length)?
0N/A null:
0N/A arr[i+1];
0N/A try {
0N/A if (curr.isAnnotationType()) {
0N/A AbstractBuilder annotationTypeBuilder =
0N/A configuration.getBuilderFactory()
0N/A .getAnnotationTypeBuilder((AnnotationTypeDoc) curr,
0N/A prev, next);
0N/A annotationTypeBuilder.build();
0N/A } else {
0N/A AbstractBuilder classBuilder =
0N/A configuration.getBuilderFactory()
0N/A .getClassBuilder(curr, prev, next, classtree);
0N/A classBuilder.build();
0N/A }
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A throw new DocletAbortException();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A protected void generatePackageFiles(ClassTree classtree) throws Exception {
0N/A PackageDoc[] packages = configuration.packages;
0N/A if (packages.length > 1) {
0N/A PackageIndexFrameWriter.generate(configuration);
0N/A }
0N/A PackageDoc prev = null, next;
994N/A for (int i = 0; i < packages.length; i++) {
994N/A // if -nodeprecated option is set and the package is marked as
994N/A // deprecated, do not generate the package-summary.html, package-frame.html
994N/A // and package-tree.html pages for that package.
994N/A if (!(configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
994N/A PackageFrameWriter.generate(configuration, packages[i]);
994N/A next = (i + 1 < packages.length &&
994N/A packages[i + 1].name().length() > 0) ? packages[i + 1] : null;
994N/A //If the next package is unnamed package, skip 2 ahead if possible
994N/A next = (i + 2 < packages.length && next == null) ? packages[i + 2] : next;
994N/A AbstractBuilder packageSummaryBuilder =
994N/A configuration.getBuilderFactory().getPackageSummaryBuilder(
994N/A packages[i], prev, next);
994N/A packageSummaryBuilder.build();
994N/A if (configuration.createtree) {
994N/A PackageTreeWriter.generate(configuration,
994N/A packages[i], prev, next,
994N/A configuration.nodeprecated);
994N/A }
994N/A prev = packages[i];
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Check for doclet added options here.
0N/A *
0N/A * @return number of arguments to option. Zero return means
0N/A * option not known. Negative value means error occurred.
0N/A */
0N/A public static int optionLength(String option) {
0N/A // Construct temporary configuration for check
0N/A return (ConfigurationImpl.getInstance()).optionLength(option);
0N/A }
0N/A
0N/A /**
0N/A * Check that options have the correct arguments here.
0N/A * <P>
0N/A * This method is not required and will default gracefully
0N/A * (to true) if absent.
0N/A * <P>
0N/A * Printing option related error messages (using the provided
0N/A * DocErrorReporter) is the responsibility of this method.
0N/A *
0N/A * @return true if the options are valid.
0N/A */
0N/A public static boolean validOptions(String options[][],
0N/A DocErrorReporter reporter) {
0N/A // Construct temporary configuration for check
0N/A return (ConfigurationImpl.getInstance()).validOptions(options, reporter);
0N/A }
0N/A
0N/A private void performCopy(String configdestdir, String filename) {
0N/A try {
0N/A String destdir = (configdestdir.length() > 0) ?
0N/A configdestdir + File.separatorChar: "";
0N/A if (filename.length() > 0) {
0N/A File helpstylefile = new File(filename);
0N/A String parent = helpstylefile.getParent();
0N/A String helpstylefilename = (parent == null)?
0N/A filename:
0N/A filename.substring(parent.length() + 1);
0N/A File desthelpfile = new File(destdir + helpstylefilename);
0N/A if (!desthelpfile.getCanonicalPath().equals(
0N/A helpstylefile.getCanonicalPath())) {
0N/A configuration.message.
0N/A notice((SourcePosition) null,
0N/A "doclet.Copying_File_0_To_File_1",
0N/A helpstylefile.toString(), desthelpfile.toString());
0N/A Util.copyFile(desthelpfile, helpstylefile);
0N/A }
0N/A }
0N/A } catch (IOException exc) {
0N/A configuration.message.
0N/A error((SourcePosition) null,
0N/A "doclet.perform_copy_exception_encountered",
0N/A exc.toString());
0N/A throw new DocletAbortException();
0N/A }
0N/A }
0N/A}