duke@1: /* jjg@1606: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@766: import java.io.*; bpatel@766: import java.util.*; jjg@1357: bpatel@766: import com.sun.javadoc.*; jjg@1357: import com.sun.tools.doclets.formats.html.markup.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Class to generate file for each package contents in the left-hand bottom duke@1: * frame. This will list all the Class Kinds in the package. A click on any duke@1: * class-kind will update the right-hand frame with the clicked class-kind page. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @author Atul M Dambalkar bpatel@766: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class PackageFrameWriter extends HtmlDocletWriter { duke@1: duke@1: /** duke@1: * The package being documented. duke@1: */ duke@1: private PackageDoc packageDoc; duke@1: duke@1: /** duke@1: * The classes to be documented. Use this to filter out classes duke@1: * that will not be documented. duke@1: */ mcimadamore@184: private Set documentedClasses; duke@1: duke@1: /** duke@1: * Constructor to construct PackageFrameWriter object and to generate duke@1: * "package-frame.html" file in the respective package directory. duke@1: * For example for package "java.lang" this will generate file duke@1: * "package-frame.html" file in the "java/lang" directory. It will also duke@1: * create "java/lang" directory in the current or the destination directory jjg@1372: * if it doesn't exist. duke@1: * duke@1: * @param configuration the configuration of the doclet. duke@1: * @param packageDoc PackageDoc under consideration. duke@1: */ duke@1: public PackageFrameWriter(ConfigurationImpl configuration, duke@1: PackageDoc packageDoc) duke@1: throws IOException { jjg@1372: super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_FRAME)); duke@1: this.packageDoc = packageDoc; duke@1: if (configuration.root.specifiedPackages().length == 0) { jjg@74: documentedClasses = new HashSet(Arrays.asList(configuration.root.classes())); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate a package summary page for the left-hand bottom frame. Construct duke@1: * the PackageFrameWriter object and then uses it generate the file. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: * @param packageDoc The package for which "pacakge-frame.html" is to be generated. duke@1: */ duke@1: public static void generate(ConfigurationImpl configuration, bpatel@766: PackageDoc packageDoc) { duke@1: PackageFrameWriter packgen; duke@1: try { duke@1: packgen = new PackageFrameWriter(configuration, packageDoc); duke@1: String pkgName = Util.getPackageName(packageDoc); bpatel@766: Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName)); jjg@1737: Content pkgNameContent = new StringContent(pkgName); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, bpatel@766: packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent)); bpatel@766: body.addContent(heading); bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.indexContainer); bpatel@766: packgen.addClassListing(div); bpatel@766: body.addContent(div); bpatel@766: packgen.printHtmlDocument( bpatel@766: configuration.metakeywords.getMetaKeywords(packageDoc), false, body); duke@1: packgen.close(); duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( bpatel@766: "doclet.exception_encountered", jjg@1372: exc.toString(), DocPaths.PACKAGE_FRAME.getPath()); jjg@1985: throw new DocletAbortException(exc); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add class listing for all the classes in this package. Divide class duke@1: * listing as per the class kind and generate separate listing for duke@1: * Classes, Interfaces, Exceptions and Errors. bpatel@766: * bpatel@766: * @param contentTree the content tree to which the listing will be added duke@1: */ bpatel@766: protected void addClassListing(Content contentTree) { jjg@1410: Configuration config = configuration; duke@1: if (packageDoc.isIncluded()) { bpatel@766: addClassKindListing(packageDoc.interfaces(), bpatel@766: getResource("doclet.Interfaces"), contentTree); bpatel@766: addClassKindListing(packageDoc.ordinaryClasses(), bpatel@766: getResource("doclet.Classes"), contentTree); bpatel@766: addClassKindListing(packageDoc.enums(), bpatel@766: getResource("doclet.Enums"), contentTree); bpatel@766: addClassKindListing(packageDoc.exceptions(), bpatel@766: getResource("doclet.Exceptions"), contentTree); bpatel@766: addClassKindListing(packageDoc.errors(), bpatel@766: getResource("doclet.Errors"), contentTree); bpatel@766: addClassKindListing(packageDoc.annotationTypes(), bpatel@766: getResource("doclet.AnnotationTypes"), contentTree); duke@1: } else { duke@1: String name = Util.getPackageName(packageDoc); bpatel@766: addClassKindListing(config.classDocCatalog.interfaces(name), bpatel@766: getResource("doclet.Interfaces"), contentTree); bpatel@766: addClassKindListing(config.classDocCatalog.ordinaryClasses(name), bpatel@766: getResource("doclet.Classes"), contentTree); bpatel@766: addClassKindListing(config.classDocCatalog.enums(name), bpatel@766: getResource("doclet.Enums"), contentTree); bpatel@766: addClassKindListing(config.classDocCatalog.exceptions(name), bpatel@766: getResource("doclet.Exceptions"), contentTree); bpatel@766: addClassKindListing(config.classDocCatalog.errors(name), bpatel@766: getResource("doclet.Errors"), contentTree); bpatel@766: addClassKindListing(config.classDocCatalog.annotationTypes(name), bpatel@766: getResource("doclet.AnnotationTypes"), contentTree); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add specific class kind listing. Also add label to the listing. duke@1: * bpatel@766: * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error bpatel@766: * @param labelContent content tree of the label to be added bpatel@766: * @param contentTree the content tree to which the class kind listing will be added duke@1: */ bpatel@766: protected void addClassKindListing(ClassDoc[] arr, Content labelContent, bpatel@766: Content contentTree) { jjg@1606: arr = Util.filterOutPrivateClasses(arr, configuration.javafx); duke@1: if(arr.length > 0) { duke@1: Arrays.sort(arr); duke@1: boolean printedHeader = false; bpatel@766: HtmlTree ul = new HtmlTree(HtmlTag.UL); jjg@1747: ul.setTitle(labelContent); duke@1: for (int i = 0; i < arr.length; i++) { duke@1: if (documentedClasses != null && bpatel@766: !documentedClasses.contains(arr[i])) { duke@1: continue; duke@1: } duke@1: if (!Util.isCoreClass(arr[i]) || ! bpatel@766: configuration.isGeneratedDoc(arr[i])) { duke@1: continue; duke@1: } duke@1: if (!printedHeader) { bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, bpatel@766: true, labelContent); bpatel@766: contentTree.addContent(heading); duke@1: printedHeader = true; duke@1: } jjg@1737: Content arr_i_name = new StringContent(arr[i].name()); bpatel@2147: if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); jjg@1736: Content link = getLink(new LinkInfoImpl(configuration, jjg@1738: LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame")); bpatel@766: Content li = HtmlTree.LI(link); bpatel@766: ul.addContent(li); duke@1: } bpatel@766: contentTree.addContent(ul); duke@1: } duke@1: } duke@1: }