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

This is NOT part of any supported API. bpatel@1568: * If you write code that depends on this, you do so at your own risk. bpatel@1568: * This code and its internal interfaces are subject to change or bpatel@1568: * deletion without notice. bpatel@1568: * bpatel@1568: * @author Bhavesh Patel bpatel@1568: */ bpatel@1568: public class ProfilePackageFrameWriter extends HtmlDocletWriter { bpatel@1568: bpatel@1568: /** bpatel@1568: * The package being documented. bpatel@1568: */ bpatel@1568: private PackageDoc packageDoc; bpatel@1568: bpatel@1568: /** bpatel@1568: * Constructor to construct ProfilePackageFrameWriter object and to generate bpatel@1568: * "profilename-package-frame.html" file in the respective package directory. bpatel@1568: * For example for profile compact1 and package "java.lang" this will generate file bpatel@1568: * "compact1-package-frame.html" file in the "java/lang" directory. It will also bpatel@1568: * create "java/lang" directory in the current or the destination directory bpatel@1568: * if it doesn't exist. bpatel@1568: * bpatel@1568: * @param configuration the configuration of the doclet. bpatel@1568: * @param packageDoc PackageDoc under consideration. bpatel@1568: * @param profileName the name of the profile being documented bpatel@1568: */ bpatel@1568: public ProfilePackageFrameWriter(ConfigurationImpl configuration, bpatel@1568: PackageDoc packageDoc, String profileName) bpatel@1568: throws IOException { bpatel@1568: super(configuration, DocPath.forPackage(packageDoc).resolve( bpatel@1568: DocPaths.profilePackageFrame(profileName))); bpatel@1568: this.packageDoc = packageDoc; bpatel@1568: } bpatel@1568: bpatel@1568: /** bpatel@1568: * Generate a profile package summary page for the left-hand bottom frame. Construct bpatel@1568: * the ProfilePackageFrameWriter object and then uses it generate the file. bpatel@1568: * bpatel@1568: * @param configuration the current configuration of the doclet. bpatel@1568: * @param packageDoc The package for which "profilename-package-frame.html" is to be generated. bpatel@1568: * @param profileValue the value of the profile being documented bpatel@1568: */ bpatel@1568: public static void generate(ConfigurationImpl configuration, bpatel@1568: PackageDoc packageDoc, int profileValue) { bpatel@1568: ProfilePackageFrameWriter profpackgen; bpatel@1568: try { bpatel@1568: String profileName = Profile.lookup(profileValue).name; bpatel@1568: profpackgen = new ProfilePackageFrameWriter(configuration, packageDoc, bpatel@1568: profileName); bpatel@1568: StringBuilder winTitle = new StringBuilder(profileName); bpatel@1568: String sep = " - "; bpatel@1568: winTitle.append(sep); bpatel@1568: String pkgName = Util.getPackageName(packageDoc); bpatel@1568: winTitle.append(pkgName); bpatel@1568: Content body = profpackgen.getBody(false, bpatel@1568: profpackgen.getWindowTitle(winTitle.toString())); bpatel@1568: Content profName = new StringContent(profileName); bpatel@1568: Content sepContent = new StringContent(sep); bpatel@1568: Content pkgNameContent = new RawHtml(pkgName); bpatel@1568: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, bpatel@1568: profpackgen.getTargetProfileLink("classFrame", profName, profileName)); bpatel@1568: heading.addContent(sepContent); bpatel@1568: heading.addContent(profpackgen.getTargetProfilePackageLink(packageDoc, bpatel@1568: "classFrame", pkgNameContent, profileName)); bpatel@1568: body.addContent(heading); bpatel@1568: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@1568: div.addStyle(HtmlStyle.indexContainer); bpatel@1568: profpackgen.addClassListing(div, profileValue); bpatel@1568: body.addContent(div); bpatel@1568: profpackgen.printHtmlDocument( bpatel@1568: configuration.metakeywords.getMetaKeywords(packageDoc), false, body); bpatel@1568: profpackgen.close(); bpatel@1568: } catch (IOException exc) { bpatel@1568: configuration.standardmessage.error( bpatel@1568: "doclet.exception_encountered", bpatel@1568: exc.toString(), DocPaths.PACKAGE_FRAME.getPath()); bpatel@1568: throw new DocletAbortException(); bpatel@1568: } bpatel@1568: } bpatel@1568: bpatel@1568: /** bpatel@1568: * Add class listing for all the classes in this package. Divide class bpatel@1568: * listing as per the class kind and generate separate listing for bpatel@1568: * Classes, Interfaces, Exceptions and Errors. bpatel@1568: * bpatel@1568: * @param contentTree the content tree to which the listing will be added bpatel@1568: * @param profileValue the value of the profile being documented bpatel@1568: */ bpatel@1568: protected void addClassListing(Content contentTree, int profileValue) { bpatel@1568: if (packageDoc.isIncluded()) { bpatel@1568: addClassKindListing(packageDoc.interfaces(), bpatel@1568: getResource("doclet.Interfaces"), contentTree, profileValue); bpatel@1568: addClassKindListing(packageDoc.ordinaryClasses(), bpatel@1568: getResource("doclet.Classes"), contentTree, profileValue); bpatel@1568: addClassKindListing(packageDoc.enums(), bpatel@1568: getResource("doclet.Enums"), contentTree, profileValue); bpatel@1568: addClassKindListing(packageDoc.exceptions(), bpatel@1568: getResource("doclet.Exceptions"), contentTree, profileValue); bpatel@1568: addClassKindListing(packageDoc.errors(), bpatel@1568: getResource("doclet.Errors"), contentTree, profileValue); bpatel@1568: addClassKindListing(packageDoc.annotationTypes(), bpatel@1568: getResource("doclet.AnnotationTypes"), contentTree, profileValue); bpatel@1568: } bpatel@1568: } bpatel@1568: bpatel@1568: /** bpatel@1568: * Add specific class kind listing. Also add label to the listing. bpatel@1568: * bpatel@1568: * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error bpatel@1568: * @param labelContent content tree of the label to be added bpatel@1568: * @param contentTree the content tree to which the class kind listing will be added bpatel@1568: * @param profileValue the value of the profile being documented bpatel@1568: */ bpatel@1568: protected void addClassKindListing(ClassDoc[] arr, Content labelContent, bpatel@1568: Content contentTree, int profileValue) { bpatel@1568: if(arr.length > 0) { bpatel@1568: Arrays.sort(arr); bpatel@1568: boolean printedHeader = false; bpatel@1568: HtmlTree ul = new HtmlTree(HtmlTag.UL); bpatel@1568: ul.addAttr(HtmlAttr.TITLE, labelContent.toString()); bpatel@1568: for (int i = 0; i < arr.length; i++) { bpatel@1568: if (!isTypeInProfile(arr[i], profileValue)) { bpatel@1568: continue; bpatel@1568: } bpatel@1568: if (!Util.isCoreClass(arr[i]) || ! bpatel@1568: configuration.isGeneratedDoc(arr[i])) { bpatel@1568: continue; bpatel@1568: } bpatel@1568: if (!printedHeader) { bpatel@1568: Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, bpatel@1568: true, labelContent); bpatel@1568: contentTree.addContent(heading); bpatel@1568: printedHeader = true; bpatel@1568: } jjg@1737: Content arr_i_name = new StringContent(arr[i].name()); jjg@1737: if (arr[i].isInterface()) arr_i_name = HtmlTree.I(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@1568: Content li = HtmlTree.LI(link); bpatel@1568: ul.addContent(li); bpatel@1568: } bpatel@1568: contentTree.addContent(ul); bpatel@1568: } bpatel@1568: } bpatel@1568: }