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 | |
bpatel@1568 | 30 | import com.sun.javadoc.*; |
bpatel@1568 | 31 | import com.sun.tools.javac.sym.Profiles; |
bpatel@1568 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@1568 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
bpatel@1568 | 34 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@1568 | 35 | |
bpatel@1568 | 36 | /** |
bpatel@1568 | 37 | * Generate the profile package index for the left-hand frame in the generated output. |
bpatel@1568 | 38 | * A click on the package name in this frame will update the page in the bottom |
bpatel@1568 | 39 | * left hand frame with the listing of contents of the clicked profile package. |
bpatel@1568 | 40 | * |
bpatel@1568 | 41 | * <p><b>This is NOT part of any supported API. |
bpatel@1568 | 42 | * If you write code that depends on this, you do so at your own risk. |
bpatel@1568 | 43 | * This code and its internal interfaces are subject to change or |
bpatel@1568 | 44 | * deletion without notice.</b> |
bpatel@1568 | 45 | * |
bpatel@1568 | 46 | * @author Bhavesh Patel |
bpatel@1568 | 47 | */ |
bpatel@1568 | 48 | public class ProfilePackageIndexFrameWriter extends AbstractProfileIndexWriter { |
bpatel@1568 | 49 | |
bpatel@1568 | 50 | /** |
bpatel@1568 | 51 | * Construct the ProfilePackageIndexFrameWriter object. |
bpatel@1568 | 52 | * |
bpatel@1568 | 53 | * @param configuration the configuration object |
bpatel@1568 | 54 | * @param filename Name of the package index file to be generated. |
bpatel@1568 | 55 | */ |
bpatel@1568 | 56 | public ProfilePackageIndexFrameWriter(ConfigurationImpl configuration, |
bpatel@1568 | 57 | DocPath filename) throws IOException { |
bpatel@1568 | 58 | super(configuration, filename); |
bpatel@1568 | 59 | } |
bpatel@1568 | 60 | |
bpatel@1568 | 61 | /** |
bpatel@1568 | 62 | * Generate the profile package index file. |
bpatel@1568 | 63 | * @throws DocletAbortException |
bpatel@1568 | 64 | * @param configuration the configuration object |
bpatel@1568 | 65 | * @param profileName the name of the profile being documented |
bpatel@1568 | 66 | */ |
bpatel@1568 | 67 | public static void generate(ConfigurationImpl configuration, String profileName) { |
bpatel@1568 | 68 | ProfilePackageIndexFrameWriter profpackgen; |
bpatel@1568 | 69 | DocPath filename = DocPaths.profileFrame(profileName); |
bpatel@1568 | 70 | try { |
bpatel@1568 | 71 | profpackgen = new ProfilePackageIndexFrameWriter(configuration, filename); |
bpatel@1568 | 72 | profpackgen.buildProfilePackagesIndexFile("doclet.Window_Overview", false, profileName); |
bpatel@1568 | 73 | profpackgen.close(); |
bpatel@1568 | 74 | } catch (IOException exc) { |
bpatel@1568 | 75 | configuration.standardmessage.error( |
bpatel@1568 | 76 | "doclet.exception_encountered", |
bpatel@1568 | 77 | exc.toString(), filename); |
bpatel@1568 | 78 | throw new DocletAbortException(); |
bpatel@1568 | 79 | } |
bpatel@1568 | 80 | } |
bpatel@1568 | 81 | |
bpatel@1568 | 82 | /** |
bpatel@1568 | 83 | * {@inheritDoc} |
bpatel@1568 | 84 | */ |
bpatel@1568 | 85 | protected void addProfilePackagesList(Profiles profiles, String text, |
bpatel@1568 | 86 | String tableSummary, Content body, String profileName) { |
bpatel@1568 | 87 | Content profNameContent = new StringContent(profileName); |
bpatel@1568 | 88 | Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, |
bpatel@1568 | 89 | getTargetProfileLink("classFrame", profNameContent, profileName)); |
bpatel@1568 | 90 | heading.addContent(getSpace()); |
bpatel@1568 | 91 | heading.addContent(packagesLabel); |
bpatel@1568 | 92 | Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading); |
bpatel@1568 | 93 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@1568 | 94 | ul.addAttr(HtmlAttr.TITLE, packagesLabel.toString()); |
bpatel@1568 | 95 | PackageDoc[] packages = configuration.profilePackages.get(profileName); |
bpatel@1568 | 96 | for (int i = 0; i < packages.length; i++) { |
bpatel@1568 | 97 | if ((!(configuration.nodeprecated && Util.isDeprecated(packages[i])))) { |
bpatel@1568 | 98 | ul.addContent(getPackage(packages[i], profileName)); |
bpatel@1568 | 99 | } |
bpatel@1568 | 100 | } |
bpatel@1568 | 101 | div.addContent(ul); |
bpatel@1568 | 102 | body.addContent(div); |
bpatel@1568 | 103 | } |
bpatel@1568 | 104 | |
bpatel@1568 | 105 | /** |
bpatel@1568 | 106 | * Gets each package name as a separate link. |
bpatel@1568 | 107 | * |
bpatel@1568 | 108 | * @param pd PackageDoc |
bpatel@1568 | 109 | * @param profileName the name of the profile being documented |
bpatel@1568 | 110 | * @return content for the package link |
bpatel@1568 | 111 | */ |
bpatel@1568 | 112 | protected Content getPackage(PackageDoc pd, String profileName) { |
bpatel@1568 | 113 | Content packageLinkContent; |
bpatel@1568 | 114 | Content pkgLabel; |
bpatel@1568 | 115 | if (pd.name().length() > 0) { |
bpatel@1568 | 116 | pkgLabel = getPackageLabel(pd.name()); |
bpatel@1568 | 117 | packageLinkContent = getHyperLink(pathString(pd, |
bpatel@1568 | 118 | DocPaths.profilePackageFrame(profileName)), pkgLabel, "", |
bpatel@1568 | 119 | "packageFrame"); |
bpatel@1568 | 120 | } else { |
jjg@1737 | 121 | pkgLabel = new StringContent("<unnamed package>"); |
bpatel@1568 | 122 | packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME, |
bpatel@1568 | 123 | pkgLabel, "", "packageFrame"); |
bpatel@1568 | 124 | } |
bpatel@1568 | 125 | Content li = HtmlTree.LI(packageLinkContent); |
bpatel@1568 | 126 | return li; |
bpatel@1568 | 127 | } |
bpatel@1568 | 128 | |
bpatel@1568 | 129 | /** |
bpatel@1568 | 130 | * {@inheritDoc} |
bpatel@1568 | 131 | */ |
bpatel@1568 | 132 | protected void addNavigationBarHeader(Content body) { |
bpatel@1568 | 133 | Content headerContent; |
bpatel@1568 | 134 | if (configuration.packagesheader.length() > 0) { |
bpatel@1568 | 135 | headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader)); |
bpatel@1568 | 136 | } else { |
bpatel@1568 | 137 | headerContent = new RawHtml(replaceDocRootDir(configuration.header)); |
bpatel@1568 | 138 | } |
bpatel@1568 | 139 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@1568 | 140 | HtmlStyle.bar, headerContent); |
bpatel@1568 | 141 | body.addContent(heading); |
bpatel@1568 | 142 | } |
bpatel@1568 | 143 | |
bpatel@1568 | 144 | /** |
bpatel@1568 | 145 | * Do nothing as there is no overview information in this page. |
bpatel@1568 | 146 | */ |
bpatel@1568 | 147 | protected void addOverviewHeader(Content body) { |
bpatel@1568 | 148 | } |
bpatel@1568 | 149 | |
bpatel@1568 | 150 | protected void addProfilesList(Profiles profiles, String text, |
bpatel@1568 | 151 | String tableSummary, Content body) { |
bpatel@1568 | 152 | } |
bpatel@1568 | 153 | |
bpatel@1568 | 154 | /** |
bpatel@1568 | 155 | * Adds "All Classes" link for the top of the left-hand frame page to the |
bpatel@1568 | 156 | * documentation tree. |
bpatel@1568 | 157 | * |
bpatel@1568 | 158 | * @param div the Content object to which the all classes link should be added |
bpatel@1568 | 159 | */ |
bpatel@1568 | 160 | protected void addAllClassesLink(Content div) { |
bpatel@1568 | 161 | Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME, |
bpatel@1568 | 162 | allclassesLabel, "", "packageFrame"); |
bpatel@1568 | 163 | Content span = HtmlTree.SPAN(linkContent); |
bpatel@1568 | 164 | div.addContent(span); |
bpatel@1568 | 165 | } |
bpatel@1568 | 166 | |
bpatel@1568 | 167 | /** |
bpatel@1568 | 168 | * Adds "All Packages" link for the top of the left-hand frame page to the |
bpatel@1568 | 169 | * documentation tree. |
bpatel@1568 | 170 | * |
bpatel@1568 | 171 | * @param div the Content object to which the all packages link should be added |
bpatel@1568 | 172 | */ |
bpatel@1568 | 173 | protected void addAllPackagesLink(Content div) { |
bpatel@1568 | 174 | Content linkContent = getHyperLink(DocPaths.OVERVIEW_FRAME, |
bpatel@1635 | 175 | allpackagesLabel, "", "packageListFrame"); |
bpatel@1568 | 176 | Content span = HtmlTree.SPAN(linkContent); |
bpatel@1568 | 177 | div.addContent(span); |
bpatel@1568 | 178 | } |
bpatel@1568 | 179 | |
bpatel@1568 | 180 | /** |
bpatel@1568 | 181 | * Adds "All Profiles" link for the top of the left-hand frame page to the |
bpatel@1568 | 182 | * documentation tree. |
bpatel@1568 | 183 | * |
bpatel@1568 | 184 | * @param div the Content object to which the all profiles link should be added |
bpatel@1568 | 185 | */ |
bpatel@1568 | 186 | protected void addAllProfilesLink(Content div) { |
bpatel@1568 | 187 | Content linkContent = getHyperLink(DocPaths.PROFILE_OVERVIEW_FRAME, |
bpatel@1635 | 188 | allprofilesLabel, "", "packageListFrame"); |
bpatel@1568 | 189 | Content span = HtmlTree.SPAN(linkContent); |
bpatel@1568 | 190 | div.addContent(span); |
bpatel@1568 | 191 | } |
bpatel@1568 | 192 | |
bpatel@1568 | 193 | /** |
bpatel@1568 | 194 | * {@inheritDoc} |
bpatel@1568 | 195 | */ |
bpatel@1568 | 196 | protected void addNavigationBarFooter(Content body) { |
bpatel@1568 | 197 | Content p = HtmlTree.P(getSpace()); |
bpatel@1568 | 198 | body.addContent(p); |
bpatel@1568 | 199 | } |
bpatel@1568 | 200 | } |