src/share/classes/com/sun/tools/doclets/formats/html/PackageFrameWriter.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 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.doclets.formats.html.markup.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Class to generate file for each package contents in the left-hand bottom
aoqi@0 38 * frame. This will list all the Class Kinds in the package. A click on any
aoqi@0 39 * class-kind will update the right-hand frame with the clicked class-kind page.
aoqi@0 40 *
aoqi@0 41 * <p><b>This is NOT part of any supported API.
aoqi@0 42 * If you write code that depends on this, you do so at your own risk.
aoqi@0 43 * This code and its internal interfaces are subject to change or
aoqi@0 44 * deletion without notice.</b>
aoqi@0 45 *
aoqi@0 46 * @author Atul M Dambalkar
aoqi@0 47 * @author Bhavesh Patel (Modified)
aoqi@0 48 */
aoqi@0 49 public class PackageFrameWriter 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 * The classes to be documented. Use this to filter out classes
aoqi@0 58 * that will not be documented.
aoqi@0 59 */
aoqi@0 60 private Set<ClassDoc> documentedClasses;
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * Constructor to construct PackageFrameWriter object and to generate
aoqi@0 64 * "package-frame.html" file in the respective package directory.
aoqi@0 65 * For example for package "java.lang" this will generate file
aoqi@0 66 * "package-frame.html" file in the "java/lang" directory. It will also
aoqi@0 67 * create "java/lang" directory in the current or the destination directory
aoqi@0 68 * if it doesn't exist.
aoqi@0 69 *
aoqi@0 70 * @param configuration the configuration of the doclet.
aoqi@0 71 * @param packageDoc PackageDoc under consideration.
aoqi@0 72 */
aoqi@0 73 public PackageFrameWriter(ConfigurationImpl configuration,
aoqi@0 74 PackageDoc packageDoc)
aoqi@0 75 throws IOException {
aoqi@0 76 super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_FRAME));
aoqi@0 77 this.packageDoc = packageDoc;
aoqi@0 78 if (configuration.root.specifiedPackages().length == 0) {
aoqi@0 79 documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
aoqi@0 80 }
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 /**
aoqi@0 84 * Generate a package summary page for the left-hand bottom frame. Construct
aoqi@0 85 * the PackageFrameWriter object and then uses it generate the file.
aoqi@0 86 *
aoqi@0 87 * @param configuration the current configuration of the doclet.
aoqi@0 88 * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
aoqi@0 89 */
aoqi@0 90 public static void generate(ConfigurationImpl configuration,
aoqi@0 91 PackageDoc packageDoc) {
aoqi@0 92 PackageFrameWriter packgen;
aoqi@0 93 try {
aoqi@0 94 packgen = new PackageFrameWriter(configuration, packageDoc);
aoqi@0 95 String pkgName = Util.getPackageName(packageDoc);
aoqi@0 96 Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
aoqi@0 97 Content pkgNameContent = new StringContent(pkgName);
aoqi@0 98 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
aoqi@0 99 packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
aoqi@0 100 body.addContent(heading);
aoqi@0 101 HtmlTree div = new HtmlTree(HtmlTag.DIV);
aoqi@0 102 div.addStyle(HtmlStyle.indexContainer);
aoqi@0 103 packgen.addClassListing(div);
aoqi@0 104 body.addContent(div);
aoqi@0 105 packgen.printHtmlDocument(
aoqi@0 106 configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
aoqi@0 107 packgen.close();
aoqi@0 108 } catch (IOException exc) {
aoqi@0 109 configuration.standardmessage.error(
aoqi@0 110 "doclet.exception_encountered",
aoqi@0 111 exc.toString(), DocPaths.PACKAGE_FRAME.getPath());
aoqi@0 112 throw new DocletAbortException(exc);
aoqi@0 113 }
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 /**
aoqi@0 117 * Add class listing for all the classes in this package. Divide class
aoqi@0 118 * listing as per the class kind and generate separate listing for
aoqi@0 119 * Classes, Interfaces, Exceptions and Errors.
aoqi@0 120 *
aoqi@0 121 * @param contentTree the content tree to which the listing will be added
aoqi@0 122 */
aoqi@0 123 protected void addClassListing(Content contentTree) {
aoqi@0 124 Configuration config = configuration;
aoqi@0 125 if (packageDoc.isIncluded()) {
aoqi@0 126 addClassKindListing(packageDoc.interfaces(),
aoqi@0 127 getResource("doclet.Interfaces"), contentTree);
aoqi@0 128 addClassKindListing(packageDoc.ordinaryClasses(),
aoqi@0 129 getResource("doclet.Classes"), contentTree);
aoqi@0 130 addClassKindListing(packageDoc.enums(),
aoqi@0 131 getResource("doclet.Enums"), contentTree);
aoqi@0 132 addClassKindListing(packageDoc.exceptions(),
aoqi@0 133 getResource("doclet.Exceptions"), contentTree);
aoqi@0 134 addClassKindListing(packageDoc.errors(),
aoqi@0 135 getResource("doclet.Errors"), contentTree);
aoqi@0 136 addClassKindListing(packageDoc.annotationTypes(),
aoqi@0 137 getResource("doclet.AnnotationTypes"), contentTree);
aoqi@0 138 } else {
aoqi@0 139 String name = Util.getPackageName(packageDoc);
aoqi@0 140 addClassKindListing(config.classDocCatalog.interfaces(name),
aoqi@0 141 getResource("doclet.Interfaces"), contentTree);
aoqi@0 142 addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
aoqi@0 143 getResource("doclet.Classes"), contentTree);
aoqi@0 144 addClassKindListing(config.classDocCatalog.enums(name),
aoqi@0 145 getResource("doclet.Enums"), contentTree);
aoqi@0 146 addClassKindListing(config.classDocCatalog.exceptions(name),
aoqi@0 147 getResource("doclet.Exceptions"), contentTree);
aoqi@0 148 addClassKindListing(config.classDocCatalog.errors(name),
aoqi@0 149 getResource("doclet.Errors"), contentTree);
aoqi@0 150 addClassKindListing(config.classDocCatalog.annotationTypes(name),
aoqi@0 151 getResource("doclet.AnnotationTypes"), contentTree);
aoqi@0 152 }
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 /**
aoqi@0 156 * Add specific class kind listing. Also add label to the listing.
aoqi@0 157 *
aoqi@0 158 * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
aoqi@0 159 * @param labelContent content tree of the label to be added
aoqi@0 160 * @param contentTree the content tree to which the class kind listing will be added
aoqi@0 161 */
aoqi@0 162 protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
aoqi@0 163 Content contentTree) {
aoqi@0 164 arr = Util.filterOutPrivateClasses(arr, configuration.javafx);
aoqi@0 165 if(arr.length > 0) {
aoqi@0 166 Arrays.sort(arr);
aoqi@0 167 boolean printedHeader = false;
aoqi@0 168 HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0 169 ul.setTitle(labelContent);
aoqi@0 170 for (int i = 0; i < arr.length; i++) {
aoqi@0 171 if (documentedClasses != null &&
aoqi@0 172 !documentedClasses.contains(arr[i])) {
aoqi@0 173 continue;
aoqi@0 174 }
aoqi@0 175 if (!Util.isCoreClass(arr[i]) || !
aoqi@0 176 configuration.isGeneratedDoc(arr[i])) {
aoqi@0 177 continue;
aoqi@0 178 }
aoqi@0 179 if (!printedHeader) {
aoqi@0 180 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
aoqi@0 181 true, labelContent);
aoqi@0 182 contentTree.addContent(heading);
aoqi@0 183 printedHeader = true;
aoqi@0 184 }
aoqi@0 185 Content arr_i_name = new StringContent(arr[i].name());
aoqi@0 186 if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name);
aoqi@0 187 Content link = getLink(new LinkInfoImpl(configuration,
aoqi@0 188 LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame"));
aoqi@0 189 Content li = HtmlTree.LI(link);
aoqi@0 190 ul.addContent(li);
aoqi@0 191 }
aoqi@0 192 contentTree.addContent(ul);
aoqi@0 193 }
aoqi@0 194 }
aoqi@0 195 }

mercurial