aoqi@0: /*
aoqi@0: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0: *
aoqi@0: * This code is free software; you can redistribute it and/or modify it
aoqi@0: * under the terms of the GNU General Public License version 2 only, as
aoqi@0: * published by the Free Software Foundation. Oracle designates this
aoqi@0: * particular file as subject to the "Classpath" exception as provided
aoqi@0: * by Oracle in the LICENSE file that accompanied this code.
aoqi@0: *
aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0: * accompanied this code).
aoqi@0: *
aoqi@0: * You should have received a copy of the GNU General Public License version
aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0: *
aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0: * or visit www.oracle.com if you need additional information or have any
aoqi@0: * questions.
aoqi@0: */
aoqi@0:
aoqi@0: package com.sun.tools.doclets.formats.html;
aoqi@0:
aoqi@0: import java.io.*;
aoqi@0: import java.util.*;
aoqi@0:
aoqi@0: import com.sun.javadoc.*;
aoqi@0: import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0: import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0:
aoqi@0: /**
aoqi@0: * Class to generate file for each package contents in the left-hand bottom
aoqi@0: * frame. This will list all the Class Kinds in the package. A click on any
aoqi@0: * class-kind will update the right-hand frame with the clicked class-kind page.
aoqi@0: *
aoqi@0: *
This is NOT part of any supported API.
aoqi@0: * If you write code that depends on this, you do so at your own risk.
aoqi@0: * This code and its internal interfaces are subject to change or
aoqi@0: * deletion without notice.
aoqi@0: *
aoqi@0: * @author Atul M Dambalkar
aoqi@0: * @author Bhavesh Patel (Modified)
aoqi@0: */
aoqi@0: public class PackageFrameWriter extends HtmlDocletWriter {
aoqi@0:
aoqi@0: /**
aoqi@0: * The package being documented.
aoqi@0: */
aoqi@0: private PackageDoc packageDoc;
aoqi@0:
aoqi@0: /**
aoqi@0: * The classes to be documented. Use this to filter out classes
aoqi@0: * that will not be documented.
aoqi@0: */
aoqi@0: private Set documentedClasses;
aoqi@0:
aoqi@0: /**
aoqi@0: * Constructor to construct PackageFrameWriter object and to generate
aoqi@0: * "package-frame.html" file in the respective package directory.
aoqi@0: * For example for package "java.lang" this will generate file
aoqi@0: * "package-frame.html" file in the "java/lang" directory. It will also
aoqi@0: * create "java/lang" directory in the current or the destination directory
aoqi@0: * if it doesn't exist.
aoqi@0: *
aoqi@0: * @param configuration the configuration of the doclet.
aoqi@0: * @param packageDoc PackageDoc under consideration.
aoqi@0: */
aoqi@0: public PackageFrameWriter(ConfigurationImpl configuration,
aoqi@0: PackageDoc packageDoc)
aoqi@0: throws IOException {
aoqi@0: super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_FRAME));
aoqi@0: this.packageDoc = packageDoc;
aoqi@0: if (configuration.root.specifiedPackages().length == 0) {
aoqi@0: documentedClasses = new HashSet(Arrays.asList(configuration.root.classes()));
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Generate a package summary page for the left-hand bottom frame. Construct
aoqi@0: * the PackageFrameWriter object and then uses it generate the file.
aoqi@0: *
aoqi@0: * @param configuration the current configuration of the doclet.
aoqi@0: * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
aoqi@0: */
aoqi@0: public static void generate(ConfigurationImpl configuration,
aoqi@0: PackageDoc packageDoc) {
aoqi@0: PackageFrameWriter packgen;
aoqi@0: try {
aoqi@0: packgen = new PackageFrameWriter(configuration, packageDoc);
aoqi@0: String pkgName = Util.getPackageName(packageDoc);
aoqi@0: Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
aoqi@0: Content pkgNameContent = new StringContent(pkgName);
aoqi@0: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
aoqi@0: packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
aoqi@0: body.addContent(heading);
aoqi@0: HtmlTree div = new HtmlTree(HtmlTag.DIV);
aoqi@0: div.addStyle(HtmlStyle.indexContainer);
aoqi@0: packgen.addClassListing(div);
aoqi@0: body.addContent(div);
aoqi@0: packgen.printHtmlDocument(
aoqi@0: configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
aoqi@0: packgen.close();
aoqi@0: } catch (IOException exc) {
aoqi@0: configuration.standardmessage.error(
aoqi@0: "doclet.exception_encountered",
aoqi@0: exc.toString(), DocPaths.PACKAGE_FRAME.getPath());
aoqi@0: throw new DocletAbortException(exc);
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Add class listing for all the classes in this package. Divide class
aoqi@0: * listing as per the class kind and generate separate listing for
aoqi@0: * Classes, Interfaces, Exceptions and Errors.
aoqi@0: *
aoqi@0: * @param contentTree the content tree to which the listing will be added
aoqi@0: */
aoqi@0: protected void addClassListing(Content contentTree) {
aoqi@0: Configuration config = configuration;
aoqi@0: if (packageDoc.isIncluded()) {
aoqi@0: addClassKindListing(packageDoc.interfaces(),
aoqi@0: getResource("doclet.Interfaces"), contentTree);
aoqi@0: addClassKindListing(packageDoc.ordinaryClasses(),
aoqi@0: getResource("doclet.Classes"), contentTree);
aoqi@0: addClassKindListing(packageDoc.enums(),
aoqi@0: getResource("doclet.Enums"), contentTree);
aoqi@0: addClassKindListing(packageDoc.exceptions(),
aoqi@0: getResource("doclet.Exceptions"), contentTree);
aoqi@0: addClassKindListing(packageDoc.errors(),
aoqi@0: getResource("doclet.Errors"), contentTree);
aoqi@0: addClassKindListing(packageDoc.annotationTypes(),
aoqi@0: getResource("doclet.AnnotationTypes"), contentTree);
aoqi@0: } else {
aoqi@0: String name = Util.getPackageName(packageDoc);
aoqi@0: addClassKindListing(config.classDocCatalog.interfaces(name),
aoqi@0: getResource("doclet.Interfaces"), contentTree);
aoqi@0: addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
aoqi@0: getResource("doclet.Classes"), contentTree);
aoqi@0: addClassKindListing(config.classDocCatalog.enums(name),
aoqi@0: getResource("doclet.Enums"), contentTree);
aoqi@0: addClassKindListing(config.classDocCatalog.exceptions(name),
aoqi@0: getResource("doclet.Exceptions"), contentTree);
aoqi@0: addClassKindListing(config.classDocCatalog.errors(name),
aoqi@0: getResource("doclet.Errors"), contentTree);
aoqi@0: addClassKindListing(config.classDocCatalog.annotationTypes(name),
aoqi@0: getResource("doclet.AnnotationTypes"), contentTree);
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Add specific class kind listing. Also add label to the listing.
aoqi@0: *
aoqi@0: * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
aoqi@0: * @param labelContent content tree of the label to be added
aoqi@0: * @param contentTree the content tree to which the class kind listing will be added
aoqi@0: */
aoqi@0: protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
aoqi@0: Content contentTree) {
aoqi@0: arr = Util.filterOutPrivateClasses(arr, configuration.javafx);
aoqi@0: if(arr.length > 0) {
aoqi@0: Arrays.sort(arr);
aoqi@0: boolean printedHeader = false;
aoqi@0: HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0: ul.setTitle(labelContent);
aoqi@0: for (int i = 0; i < arr.length; i++) {
aoqi@0: if (documentedClasses != null &&
aoqi@0: !documentedClasses.contains(arr[i])) {
aoqi@0: continue;
aoqi@0: }
aoqi@0: if (!Util.isCoreClass(arr[i]) || !
aoqi@0: configuration.isGeneratedDoc(arr[i])) {
aoqi@0: continue;
aoqi@0: }
aoqi@0: if (!printedHeader) {
aoqi@0: Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
aoqi@0: true, labelContent);
aoqi@0: contentTree.addContent(heading);
aoqi@0: printedHeader = true;
aoqi@0: }
aoqi@0: Content arr_i_name = new StringContent(arr[i].name());
aoqi@0: if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name);
aoqi@0: Content link = getLink(new LinkInfoImpl(configuration,
aoqi@0: LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame"));
aoqi@0: Content li = HtmlTree.LI(link);
aoqi@0: ul.addContent(li);
aoqi@0: }
aoqi@0: contentTree.addContent(ul);
aoqi@0: }
aoqi@0: }
aoqi@0: }