duke@1: /* ohair@554: * Copyright (c) 1998, 2008, 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: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: duke@1: import com.sun.javadoc.*; duke@1: import java.io.*; duke@1: import java.util.*; 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: * duke@1: * @author Atul M Dambalkar 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: * The name of the output file. duke@1: */ duke@1: public static final String OUTPUT_FILE_NAME = "package-frame.html"; 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 duke@1: * if it doesen'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 { duke@1: super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc)); 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, duke@1: PackageDoc packageDoc) { duke@1: PackageFrameWriter packgen; duke@1: try { duke@1: packgen = new PackageFrameWriter(configuration, packageDoc); duke@1: String pkgName = Util.getPackageName(packageDoc); duke@1: packgen.printHtmlHeader(pkgName, configuration.metakeywords.getMetaKeywords(packageDoc), false); duke@1: packgen.printPackageHeader(pkgName); duke@1: packgen.generateClassListing(); duke@1: packgen.printBodyHtmlEnd(); duke@1: packgen.close(); duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( duke@1: "doclet.exception_encountered", duke@1: exc.toString(), OUTPUT_FILE_NAME); duke@1: throw new DocletAbortException(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate 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. duke@1: */ duke@1: protected void generateClassListing() { duke@1: Configuration config = configuration(); duke@1: if (packageDoc.isIncluded()) { duke@1: generateClassKindListing(packageDoc.interfaces(), duke@1: configuration.getText("doclet.Interfaces")); duke@1: generateClassKindListing(packageDoc.ordinaryClasses(), duke@1: configuration.getText("doclet.Classes")); duke@1: generateClassKindListing(packageDoc.enums(), duke@1: configuration.getText("doclet.Enums")); duke@1: generateClassKindListing(packageDoc.exceptions(), duke@1: configuration.getText("doclet.Exceptions")); duke@1: generateClassKindListing(packageDoc.errors(), duke@1: configuration.getText("doclet.Errors")); duke@1: generateClassKindListing(packageDoc.annotationTypes(), duke@1: configuration.getText("doclet.AnnotationTypes")); duke@1: } else { duke@1: String name = Util.getPackageName(packageDoc); duke@1: generateClassKindListing(config.classDocCatalog.interfaces(name), duke@1: configuration.getText("doclet.Interfaces")); duke@1: generateClassKindListing(config.classDocCatalog.ordinaryClasses(name), duke@1: configuration.getText("doclet.Classes")); duke@1: generateClassKindListing(config.classDocCatalog.enums(name), duke@1: configuration.getText("doclet.Enums")); duke@1: generateClassKindListing(config.classDocCatalog.exceptions(name), duke@1: configuration.getText("doclet.Exceptions")); duke@1: generateClassKindListing(config.classDocCatalog.errors(name), duke@1: configuration.getText("doclet.Errors")); duke@1: generateClassKindListing(config.classDocCatalog.annotationTypes(name), duke@1: configuration.getText("doclet.AnnotationTypes")); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate specific class kind listing. Also add label to the listing. duke@1: * duke@1: * @param arr Array of specific class kinds, namely Class or Interface or duke@1: * Exception or Error. duke@1: * @param label Label for the listing duke@1: */ duke@1: protected void generateClassKindListing(ClassDoc[] arr, String label) { duke@1: if(arr.length > 0) { duke@1: Arrays.sort(arr); duke@1: printPackageTableHeader(); duke@1: fontSizeStyle("+1", "FrameHeadingFont"); duke@1: boolean printedHeader = false; duke@1: for (int i = 0; i < arr.length; i++) { duke@1: if (documentedClasses != null && duke@1: !documentedClasses.contains(arr[i])) { duke@1: continue; duke@1: } duke@1: if (!Util.isCoreClass(arr[i]) || ! duke@1: configuration.isGeneratedDoc(arr[i])) { duke@1: continue; duke@1: } duke@1: if (!printedHeader) { duke@1: print(label); duke@1: fontEnd(); duke@1: println(" "); duke@1: fontStyle("FrameItemFont"); duke@1: printedHeader = true; duke@1: } duke@1: br(); duke@1: printLink(new LinkInfoImpl( duke@1: LinkInfoImpl.PACKAGE_FRAME, duke@1: arr[i], duke@1: (arr[i].isInterface() ? duke@1: italicsText(arr[i].name()) : duke@1: arr[i].name()),"classFrame") duke@1: ); duke@1: } duke@1: fontEnd(); duke@1: printPackageTableFooter(); duke@1: println(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the package link at the top of the class kind listing. Clicking duke@1: * this link, package-summary page will appear in the right hand frame. duke@1: * duke@1: * @param heading Top Heading to be used for the class kind listing. duke@1: */ duke@1: protected void printPackageHeader(String heading) { duke@1: fontSizeStyle("+1", "FrameTitleFont"); duke@1: printTargetPackageLink(packageDoc, "classFrame", heading); duke@1: fontEnd(); duke@1: } duke@1: duke@1: /** duke@1: * The table for the class kind listing. duke@1: */ duke@1: protected void printPackageTableHeader() { duke@1: table(); duke@1: tr(); duke@1: tdNowrap(); duke@1: } duke@1: duke@1: /** duke@1: * Closing Html tags for table of class kind listing. duke@1: */ duke@1: protected void printPackageTableFooter() { duke@1: tdEnd(); duke@1: trEnd(); duke@1: tableEnd(); duke@1: } duke@1: }