1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,186 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import java.io.*; 1.32 +import java.util.*; 1.33 + 1.34 +import com.sun.javadoc.*; 1.35 +import com.sun.tools.javac.jvm.Profile; 1.36 +import com.sun.tools.doclets.formats.html.markup.*; 1.37 +import com.sun.tools.doclets.internal.toolkit.*; 1.38 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.39 + 1.40 +/** 1.41 + * Class to generate file for each package contents of a profile in the left-hand bottom 1.42 + * frame. This will list all the Class Kinds in the package for a profile. A click on any 1.43 + * class-kind will update the right-hand frame with the clicked class-kind page. 1.44 + * 1.45 + * <p><b>This is NOT part of any supported API. 1.46 + * If you write code that depends on this, you do so at your own risk. 1.47 + * This code and its internal interfaces are subject to change or 1.48 + * deletion without notice.</b> 1.49 + * 1.50 + * @author Bhavesh Patel 1.51 + */ 1.52 +public class ProfilePackageFrameWriter extends HtmlDocletWriter { 1.53 + 1.54 + /** 1.55 + * The package being documented. 1.56 + */ 1.57 + private PackageDoc packageDoc; 1.58 + 1.59 + /** 1.60 + * Constructor to construct ProfilePackageFrameWriter object and to generate 1.61 + * "profilename-package-frame.html" file in the respective package directory. 1.62 + * For example for profile compact1 and package "java.lang" this will generate file 1.63 + * "compact1-package-frame.html" file in the "java/lang" directory. It will also 1.64 + * create "java/lang" directory in the current or the destination directory 1.65 + * if it doesn't exist. 1.66 + * 1.67 + * @param configuration the configuration of the doclet. 1.68 + * @param packageDoc PackageDoc under consideration. 1.69 + * @param profileName the name of the profile being documented 1.70 + */ 1.71 + public ProfilePackageFrameWriter(ConfigurationImpl configuration, 1.72 + PackageDoc packageDoc, String profileName) 1.73 + throws IOException { 1.74 + super(configuration, DocPath.forPackage(packageDoc).resolve( 1.75 + DocPaths.profilePackageFrame(profileName))); 1.76 + this.packageDoc = packageDoc; 1.77 + } 1.78 + 1.79 + /** 1.80 + * Generate a profile package summary page for the left-hand bottom frame. Construct 1.81 + * the ProfilePackageFrameWriter object and then uses it generate the file. 1.82 + * 1.83 + * @param configuration the current configuration of the doclet. 1.84 + * @param packageDoc The package for which "profilename-package-frame.html" is to be generated. 1.85 + * @param profileValue the value of the profile being documented 1.86 + */ 1.87 + public static void generate(ConfigurationImpl configuration, 1.88 + PackageDoc packageDoc, int profileValue) { 1.89 + ProfilePackageFrameWriter profpackgen; 1.90 + try { 1.91 + String profileName = Profile.lookup(profileValue).name; 1.92 + profpackgen = new ProfilePackageFrameWriter(configuration, packageDoc, 1.93 + profileName); 1.94 + StringBuilder winTitle = new StringBuilder(profileName); 1.95 + String sep = " - "; 1.96 + winTitle.append(sep); 1.97 + String pkgName = Util.getPackageName(packageDoc); 1.98 + winTitle.append(pkgName); 1.99 + Content body = profpackgen.getBody(false, 1.100 + profpackgen.getWindowTitle(winTitle.toString())); 1.101 + Content profName = new StringContent(profileName); 1.102 + Content sepContent = new StringContent(sep); 1.103 + Content pkgNameContent = new RawHtml(pkgName); 1.104 + Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, 1.105 + profpackgen.getTargetProfileLink("classFrame", profName, profileName)); 1.106 + heading.addContent(sepContent); 1.107 + heading.addContent(profpackgen.getTargetProfilePackageLink(packageDoc, 1.108 + "classFrame", pkgNameContent, profileName)); 1.109 + body.addContent(heading); 1.110 + HtmlTree div = new HtmlTree(HtmlTag.DIV); 1.111 + div.addStyle(HtmlStyle.indexContainer); 1.112 + profpackgen.addClassListing(div, profileValue); 1.113 + body.addContent(div); 1.114 + profpackgen.printHtmlDocument( 1.115 + configuration.metakeywords.getMetaKeywords(packageDoc), false, body); 1.116 + profpackgen.close(); 1.117 + } catch (IOException exc) { 1.118 + configuration.standardmessage.error( 1.119 + "doclet.exception_encountered", 1.120 + exc.toString(), DocPaths.PACKAGE_FRAME.getPath()); 1.121 + throw new DocletAbortException(exc); 1.122 + } 1.123 + } 1.124 + 1.125 + /** 1.126 + * Add class listing for all the classes in this package. Divide class 1.127 + * listing as per the class kind and generate separate listing for 1.128 + * Classes, Interfaces, Exceptions and Errors. 1.129 + * 1.130 + * @param contentTree the content tree to which the listing will be added 1.131 + * @param profileValue the value of the profile being documented 1.132 + */ 1.133 + protected void addClassListing(Content contentTree, int profileValue) { 1.134 + if (packageDoc.isIncluded()) { 1.135 + addClassKindListing(packageDoc.interfaces(), 1.136 + getResource("doclet.Interfaces"), contentTree, profileValue); 1.137 + addClassKindListing(packageDoc.ordinaryClasses(), 1.138 + getResource("doclet.Classes"), contentTree, profileValue); 1.139 + addClassKindListing(packageDoc.enums(), 1.140 + getResource("doclet.Enums"), contentTree, profileValue); 1.141 + addClassKindListing(packageDoc.exceptions(), 1.142 + getResource("doclet.Exceptions"), contentTree, profileValue); 1.143 + addClassKindListing(packageDoc.errors(), 1.144 + getResource("doclet.Errors"), contentTree, profileValue); 1.145 + addClassKindListing(packageDoc.annotationTypes(), 1.146 + getResource("doclet.AnnotationTypes"), contentTree, profileValue); 1.147 + } 1.148 + } 1.149 + 1.150 + /** 1.151 + * Add specific class kind listing. Also add label to the listing. 1.152 + * 1.153 + * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error 1.154 + * @param labelContent content tree of the label to be added 1.155 + * @param contentTree the content tree to which the class kind listing will be added 1.156 + * @param profileValue the value of the profile being documented 1.157 + */ 1.158 + protected void addClassKindListing(ClassDoc[] arr, Content labelContent, 1.159 + Content contentTree, int profileValue) { 1.160 + if(arr.length > 0) { 1.161 + Arrays.sort(arr); 1.162 + boolean printedHeader = false; 1.163 + HtmlTree ul = new HtmlTree(HtmlTag.UL); 1.164 + ul.setTitle(labelContent); 1.165 + for (int i = 0; i < arr.length; i++) { 1.166 + if (!isTypeInProfile(arr[i], profileValue)) { 1.167 + continue; 1.168 + } 1.169 + if (!Util.isCoreClass(arr[i]) || ! 1.170 + configuration.isGeneratedDoc(arr[i])) { 1.171 + continue; 1.172 + } 1.173 + if (!printedHeader) { 1.174 + Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 1.175 + true, labelContent); 1.176 + contentTree.addContent(heading); 1.177 + printedHeader = true; 1.178 + } 1.179 + Content arr_i_name = new StringContent(arr[i].name()); 1.180 + if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); 1.181 + Content link = getLink(new LinkInfoImpl(configuration, 1.182 + LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame")); 1.183 + Content li = HtmlTree.LI(link); 1.184 + ul.addContent(li); 1.185 + } 1.186 + contentTree.addContent(ul); 1.187 + } 1.188 + } 1.189 +}