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