Thu, 31 Aug 2017 15:17:03 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.doclets.formats.html; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.*; |
aoqi@0 | 29 | import java.util.*; |
aoqi@0 | 30 | |
aoqi@0 | 31 | import com.sun.javadoc.*; |
aoqi@0 | 32 | import com.sun.tools.javac.jvm.Profile; |
aoqi@0 | 33 | import com.sun.tools.doclets.formats.html.markup.*; |
aoqi@0 | 34 | import com.sun.tools.doclets.internal.toolkit.*; |
aoqi@0 | 35 | import com.sun.tools.doclets.internal.toolkit.util.*; |
aoqi@0 | 36 | |
aoqi@0 | 37 | /** |
aoqi@0 | 38 | * Class to generate file for each package contents of a profile in the left-hand bottom |
aoqi@0 | 39 | * frame. This will list all the Class Kinds in the package for a profile. A click on any |
aoqi@0 | 40 | * class-kind will update the right-hand frame with the clicked class-kind page. |
aoqi@0 | 41 | * |
aoqi@0 | 42 | * <p><b>This is NOT part of any supported API. |
aoqi@0 | 43 | * If you write code that depends on this, you do so at your own risk. |
aoqi@0 | 44 | * This code and its internal interfaces are subject to change or |
aoqi@0 | 45 | * deletion without notice.</b> |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * @author Bhavesh Patel |
aoqi@0 | 48 | */ |
aoqi@0 | 49 | public class ProfilePackageFrameWriter extends HtmlDocletWriter { |
aoqi@0 | 50 | |
aoqi@0 | 51 | /** |
aoqi@0 | 52 | * The package being documented. |
aoqi@0 | 53 | */ |
aoqi@0 | 54 | private PackageDoc packageDoc; |
aoqi@0 | 55 | |
aoqi@0 | 56 | /** |
aoqi@0 | 57 | * Constructor to construct ProfilePackageFrameWriter object and to generate |
aoqi@0 | 58 | * "profilename-package-frame.html" file in the respective package directory. |
aoqi@0 | 59 | * For example for profile compact1 and package "java.lang" this will generate file |
aoqi@0 | 60 | * "compact1-package-frame.html" file in the "java/lang" directory. It will also |
aoqi@0 | 61 | * create "java/lang" directory in the current or the destination directory |
aoqi@0 | 62 | * if it doesn't exist. |
aoqi@0 | 63 | * |
aoqi@0 | 64 | * @param configuration the configuration of the doclet. |
aoqi@0 | 65 | * @param packageDoc PackageDoc under consideration. |
aoqi@0 | 66 | * @param profileName the name of the profile being documented |
aoqi@0 | 67 | */ |
aoqi@0 | 68 | public ProfilePackageFrameWriter(ConfigurationImpl configuration, |
aoqi@0 | 69 | PackageDoc packageDoc, String profileName) |
aoqi@0 | 70 | throws IOException { |
aoqi@0 | 71 | super(configuration, DocPath.forPackage(packageDoc).resolve( |
aoqi@0 | 72 | DocPaths.profilePackageFrame(profileName))); |
aoqi@0 | 73 | this.packageDoc = packageDoc; |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | /** |
aoqi@0 | 77 | * Generate a profile package summary page for the left-hand bottom frame. Construct |
aoqi@0 | 78 | * the ProfilePackageFrameWriter object and then uses it generate the file. |
aoqi@0 | 79 | * |
aoqi@0 | 80 | * @param configuration the current configuration of the doclet. |
aoqi@0 | 81 | * @param packageDoc The package for which "profilename-package-frame.html" is to be generated. |
aoqi@0 | 82 | * @param profileValue the value of the profile being documented |
aoqi@0 | 83 | */ |
aoqi@0 | 84 | public static void generate(ConfigurationImpl configuration, |
aoqi@0 | 85 | PackageDoc packageDoc, int profileValue) { |
aoqi@0 | 86 | ProfilePackageFrameWriter profpackgen; |
aoqi@0 | 87 | try { |
aoqi@0 | 88 | String profileName = Profile.lookup(profileValue).name; |
aoqi@0 | 89 | profpackgen = new ProfilePackageFrameWriter(configuration, packageDoc, |
aoqi@0 | 90 | profileName); |
aoqi@0 | 91 | StringBuilder winTitle = new StringBuilder(profileName); |
aoqi@0 | 92 | String sep = " - "; |
aoqi@0 | 93 | winTitle.append(sep); |
aoqi@0 | 94 | String pkgName = Util.getPackageName(packageDoc); |
aoqi@0 | 95 | winTitle.append(pkgName); |
aoqi@0 | 96 | Content body = profpackgen.getBody(false, |
aoqi@0 | 97 | profpackgen.getWindowTitle(winTitle.toString())); |
aoqi@0 | 98 | Content profName = new StringContent(profileName); |
aoqi@0 | 99 | Content sepContent = new StringContent(sep); |
aoqi@0 | 100 | Content pkgNameContent = new RawHtml(pkgName); |
aoqi@0 | 101 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, |
aoqi@0 | 102 | profpackgen.getTargetProfileLink("classFrame", profName, profileName)); |
aoqi@0 | 103 | heading.addContent(sepContent); |
aoqi@0 | 104 | heading.addContent(profpackgen.getTargetProfilePackageLink(packageDoc, |
aoqi@0 | 105 | "classFrame", pkgNameContent, profileName)); |
aoqi@0 | 106 | body.addContent(heading); |
aoqi@0 | 107 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
aoqi@0 | 108 | div.addStyle(HtmlStyle.indexContainer); |
aoqi@0 | 109 | profpackgen.addClassListing(div, profileValue); |
aoqi@0 | 110 | body.addContent(div); |
aoqi@0 | 111 | profpackgen.printHtmlDocument( |
aoqi@0 | 112 | configuration.metakeywords.getMetaKeywords(packageDoc), false, body); |
aoqi@0 | 113 | profpackgen.close(); |
aoqi@0 | 114 | } catch (IOException exc) { |
aoqi@0 | 115 | configuration.standardmessage.error( |
aoqi@0 | 116 | "doclet.exception_encountered", |
aoqi@0 | 117 | exc.toString(), DocPaths.PACKAGE_FRAME.getPath()); |
aoqi@0 | 118 | throw new DocletAbortException(exc); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | /** |
aoqi@0 | 123 | * Add class listing for all the classes in this package. Divide class |
aoqi@0 | 124 | * listing as per the class kind and generate separate listing for |
aoqi@0 | 125 | * Classes, Interfaces, Exceptions and Errors. |
aoqi@0 | 126 | * |
aoqi@0 | 127 | * @param contentTree the content tree to which the listing will be added |
aoqi@0 | 128 | * @param profileValue the value of the profile being documented |
aoqi@0 | 129 | */ |
aoqi@0 | 130 | protected void addClassListing(Content contentTree, int profileValue) { |
aoqi@0 | 131 | if (packageDoc.isIncluded()) { |
aoqi@0 | 132 | addClassKindListing(packageDoc.interfaces(), |
aoqi@0 | 133 | getResource("doclet.Interfaces"), contentTree, profileValue); |
aoqi@0 | 134 | addClassKindListing(packageDoc.ordinaryClasses(), |
aoqi@0 | 135 | getResource("doclet.Classes"), contentTree, profileValue); |
aoqi@0 | 136 | addClassKindListing(packageDoc.enums(), |
aoqi@0 | 137 | getResource("doclet.Enums"), contentTree, profileValue); |
aoqi@0 | 138 | addClassKindListing(packageDoc.exceptions(), |
aoqi@0 | 139 | getResource("doclet.Exceptions"), contentTree, profileValue); |
aoqi@0 | 140 | addClassKindListing(packageDoc.errors(), |
aoqi@0 | 141 | getResource("doclet.Errors"), contentTree, profileValue); |
aoqi@0 | 142 | addClassKindListing(packageDoc.annotationTypes(), |
aoqi@0 | 143 | getResource("doclet.AnnotationTypes"), contentTree, profileValue); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | /** |
aoqi@0 | 148 | * Add specific class kind listing. Also add label to the listing. |
aoqi@0 | 149 | * |
aoqi@0 | 150 | * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error |
aoqi@0 | 151 | * @param labelContent content tree of the label to be added |
aoqi@0 | 152 | * @param contentTree the content tree to which the class kind listing will be added |
aoqi@0 | 153 | * @param profileValue the value of the profile being documented |
aoqi@0 | 154 | */ |
aoqi@0 | 155 | protected void addClassKindListing(ClassDoc[] arr, Content labelContent, |
aoqi@0 | 156 | Content contentTree, int profileValue) { |
aoqi@0 | 157 | if(arr.length > 0) { |
aoqi@0 | 158 | Arrays.sort(arr); |
aoqi@0 | 159 | boolean printedHeader = false; |
aoqi@0 | 160 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
aoqi@0 | 161 | ul.setTitle(labelContent); |
aoqi@0 | 162 | for (int i = 0; i < arr.length; i++) { |
aoqi@0 | 163 | if (!isTypeInProfile(arr[i], profileValue)) { |
aoqi@0 | 164 | continue; |
aoqi@0 | 165 | } |
aoqi@0 | 166 | if (!Util.isCoreClass(arr[i]) || ! |
aoqi@0 | 167 | configuration.isGeneratedDoc(arr[i])) { |
aoqi@0 | 168 | continue; |
aoqi@0 | 169 | } |
aoqi@0 | 170 | if (!printedHeader) { |
aoqi@0 | 171 | Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, |
aoqi@0 | 172 | true, labelContent); |
aoqi@0 | 173 | contentTree.addContent(heading); |
aoqi@0 | 174 | printedHeader = true; |
aoqi@0 | 175 | } |
aoqi@0 | 176 | Content arr_i_name = new StringContent(arr[i].name()); |
aoqi@0 | 177 | if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); |
aoqi@0 | 178 | Content link = getLink(new LinkInfoImpl(configuration, |
aoqi@0 | 179 | LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame")); |
aoqi@0 | 180 | Content li = HtmlTree.LI(link); |
aoqi@0 | 181 | ul.addContent(li); |
aoqi@0 | 182 | } |
aoqi@0 | 183 | contentTree.addContent(ul); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | } |
aoqi@0 | 186 | } |