Tue, 14 May 2013 10:14:54 -0700
8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1357 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
jjg@1357 | 29 | |
jjg@1357 | 30 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 31 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 32 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Generate File to list all the deprecated classes and class members with the |
duke@1 | 36 | * appropriate links. |
duke@1 | 37 | * |
jjg@1359 | 38 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 39 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 40 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 41 | * deletion without notice.</b> |
jjg@1359 | 42 | * |
duke@1 | 43 | * @see java.util.List |
duke@1 | 44 | * @author Atul M Dambalkar |
bpatel@243 | 45 | * @author Bhavesh Patel (Modified) |
duke@1 | 46 | */ |
duke@1 | 47 | public class DeprecatedListWriter extends SubWriterHolderWriter { |
duke@1 | 48 | |
duke@1 | 49 | private static final String[] ANCHORS = new String[] { |
bpatel@995 | 50 | "package", "interface", "class", "enum", "exception", "error", |
bpatel@995 | 51 | "annotation_type", "field", "method", "constructor", "enum_constant", |
duke@1 | 52 | "annotation_type_member" |
duke@1 | 53 | }; |
duke@1 | 54 | |
duke@1 | 55 | private static final String[] HEADING_KEYS = new String[] { |
bpatel@995 | 56 | "doclet.Deprecated_Packages", "doclet.Deprecated_Interfaces", |
bpatel@995 | 57 | "doclet.Deprecated_Classes", "doclet.Deprecated_Enums", |
bpatel@995 | 58 | "doclet.Deprecated_Exceptions", "doclet.Deprecated_Errors", |
duke@1 | 59 | "doclet.Deprecated_Annotation_Types", |
duke@1 | 60 | "doclet.Deprecated_Fields", |
duke@1 | 61 | "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors", |
duke@1 | 62 | "doclet.Deprecated_Enum_Constants", |
duke@1 | 63 | "doclet.Deprecated_Annotation_Type_Members" |
duke@1 | 64 | }; |
duke@1 | 65 | |
bpatel@243 | 66 | private static final String[] SUMMARY_KEYS = new String[] { |
bpatel@995 | 67 | "doclet.deprecated_packages", "doclet.deprecated_interfaces", |
bpatel@995 | 68 | "doclet.deprecated_classes", "doclet.deprecated_enums", |
bpatel@995 | 69 | "doclet.deprecated_exceptions", "doclet.deprecated_errors", |
bpatel@243 | 70 | "doclet.deprecated_annotation_types", |
bpatel@243 | 71 | "doclet.deprecated_fields", |
bpatel@243 | 72 | "doclet.deprecated_methods", "doclet.deprecated_constructors", |
bpatel@243 | 73 | "doclet.deprecated_enum_constants", |
bpatel@243 | 74 | "doclet.deprecated_annotation_type_members" |
bpatel@243 | 75 | }; |
bpatel@243 | 76 | |
bpatel@243 | 77 | private static final String[] HEADER_KEYS = new String[] { |
bpatel@995 | 78 | "doclet.Package", "doclet.Interface", "doclet.Class", |
bpatel@243 | 79 | "doclet.Enum", "doclet.Exceptions", |
bpatel@243 | 80 | "doclet.Errors", |
bpatel@243 | 81 | "doclet.AnnotationType", |
bpatel@243 | 82 | "doclet.Field", |
bpatel@243 | 83 | "doclet.Method", "doclet.Constructor", |
bpatel@243 | 84 | "doclet.Enum_Constant", |
bpatel@243 | 85 | "doclet.Annotation_Type_Member" |
bpatel@243 | 86 | }; |
bpatel@243 | 87 | |
duke@1 | 88 | private AbstractMemberWriter[] writers; |
duke@1 | 89 | |
duke@1 | 90 | private ConfigurationImpl configuration; |
duke@1 | 91 | |
duke@1 | 92 | /** |
duke@1 | 93 | * Constructor. |
duke@1 | 94 | * |
duke@1 | 95 | * @param filename the file to be generated. |
duke@1 | 96 | */ |
duke@1 | 97 | public DeprecatedListWriter(ConfigurationImpl configuration, |
jjg@1372 | 98 | DocPath filename) throws IOException { |
duke@1 | 99 | super(configuration, filename); |
duke@1 | 100 | this.configuration = configuration; |
duke@1 | 101 | NestedClassWriterImpl classW = new NestedClassWriterImpl(this); |
duke@1 | 102 | writers = new AbstractMemberWriter[] |
duke@1 | 103 | {classW, classW, classW, classW, classW, classW, |
duke@1 | 104 | new FieldWriterImpl(this), |
duke@1 | 105 | new MethodWriterImpl(this), |
duke@1 | 106 | new ConstructorWriterImpl(this), |
duke@1 | 107 | new EnumConstantWriterImpl(this), |
duke@1 | 108 | new AnnotationTypeOptionalMemberWriterImpl(this, null)}; |
duke@1 | 109 | } |
duke@1 | 110 | |
duke@1 | 111 | /** |
duke@1 | 112 | * Get list of all the deprecated classes and members in all the Packages |
duke@1 | 113 | * specified on the Command Line. |
duke@1 | 114 | * Then instantiate DeprecatedListWriter and generate File. |
duke@1 | 115 | * |
duke@1 | 116 | * @param configuration the current configuration of the doclet. |
duke@1 | 117 | */ |
duke@1 | 118 | public static void generate(ConfigurationImpl configuration) { |
jjg@1372 | 119 | DocPath filename = DocPaths.DEPRECATED_LIST; |
duke@1 | 120 | try { |
duke@1 | 121 | DeprecatedListWriter depr = |
duke@1 | 122 | new DeprecatedListWriter(configuration, filename); |
duke@1 | 123 | depr.generateDeprecatedListFile( |
bpatel@995 | 124 | new DeprecatedAPIListBuilder(configuration)); |
duke@1 | 125 | depr.close(); |
duke@1 | 126 | } catch (IOException exc) { |
duke@1 | 127 | configuration.standardmessage.error( |
duke@1 | 128 | "doclet.exception_encountered", |
duke@1 | 129 | exc.toString(), filename); |
duke@1 | 130 | throw new DocletAbortException(); |
duke@1 | 131 | } |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /** |
bpatel@766 | 135 | * Generate the deprecated API list. |
duke@1 | 136 | * |
duke@1 | 137 | * @param deprapi list of deprecated API built already. |
duke@1 | 138 | */ |
duke@1 | 139 | protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) |
bpatel@766 | 140 | throws IOException { |
bpatel@766 | 141 | Content body = getHeader(); |
bpatel@766 | 142 | body.addContent(getContentsList(deprapi)); |
bpatel@243 | 143 | String memberTableSummary; |
bpatel@243 | 144 | String[] memberTableHeader = new String[1]; |
bpatel@766 | 145 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 146 | div.addStyle(HtmlStyle.contentContainer); |
duke@1 | 147 | for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { |
duke@1 | 148 | if (deprapi.hasDocumentation(i)) { |
bpatel@766 | 149 | addAnchor(deprapi, i, div); |
bpatel@243 | 150 | memberTableSummary = |
bpatel@243 | 151 | configuration.getText("doclet.Member_Table_Summary", |
bpatel@243 | 152 | configuration.getText(HEADING_KEYS[i]), |
bpatel@243 | 153 | configuration.getText(SUMMARY_KEYS[i])); |
bpatel@243 | 154 | memberTableHeader[0] = configuration.getText("doclet.0_and_1", |
bpatel@243 | 155 | configuration.getText(HEADER_KEYS[i]), |
bpatel@243 | 156 | configuration.getText("doclet.Description")); |
bpatel@995 | 157 | // DeprecatedAPIListBuilder.PACKAGE == 0, so if i == 0, it is |
bpatel@995 | 158 | // a PackageDoc. |
bpatel@995 | 159 | if (i == DeprecatedAPIListBuilder.PACKAGE) |
bpatel@995 | 160 | addPackageDeprecatedAPI(deprapi.getList(i), |
bpatel@995 | 161 | HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); |
bpatel@995 | 162 | else |
bpatel@995 | 163 | writers[i - 1].addDeprecatedAPI(deprapi.getList(i), |
bpatel@995 | 164 | HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); |
duke@1 | 165 | } |
duke@1 | 166 | } |
bpatel@766 | 167 | body.addContent(div); |
bpatel@766 | 168 | addNavLinks(false, body); |
bpatel@766 | 169 | addBottom(body); |
bpatel@766 | 170 | printHtmlDocument(null, true, body); |
duke@1 | 171 | } |
duke@1 | 172 | |
bpatel@766 | 173 | /** |
bpatel@766 | 174 | * Add the index link. |
bpatel@766 | 175 | * |
bpatel@766 | 176 | * @param builder the deprecated list builder |
bpatel@766 | 177 | * @param type the type of list being documented |
bpatel@766 | 178 | * @param contentTree the content tree to which the index link will be added |
bpatel@766 | 179 | */ |
bpatel@766 | 180 | private void addIndexLink(DeprecatedAPIListBuilder builder, |
bpatel@766 | 181 | int type, Content contentTree) { |
duke@1 | 182 | if (builder.hasDocumentation(type)) { |
jjg@1372 | 183 | Content li = HtmlTree.LI(getHyperLink(ANCHORS[type], |
bpatel@766 | 184 | getResource(HEADING_KEYS[type]))); |
bpatel@766 | 185 | contentTree.addContent(li); |
duke@1 | 186 | } |
duke@1 | 187 | } |
duke@1 | 188 | |
duke@1 | 189 | /** |
bpatel@766 | 190 | * Get the contents list. |
bpatel@766 | 191 | * |
bpatel@766 | 192 | * @param deprapi the deprecated list builder |
bpatel@766 | 193 | * @return a content tree for the contents list |
duke@1 | 194 | */ |
bpatel@766 | 195 | public Content getContentsList(DeprecatedAPIListBuilder deprapi) { |
bpatel@766 | 196 | Content headContent = getResource("doclet.Deprecated_API"); |
bpatel@766 | 197 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 198 | HtmlStyle.title, headContent); |
bpatel@766 | 199 | Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
bpatel@766 | 200 | Content headingContent = getResource("doclet.Contents"); |
bpatel@766 | 201 | div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
bpatel@766 | 202 | headingContent)); |
bpatel@766 | 203 | Content ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 204 | for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { |
bpatel@766 | 205 | addIndexLink(deprapi, i, ul); |
bpatel@766 | 206 | } |
bpatel@766 | 207 | div.addContent(ul); |
bpatel@766 | 208 | return div; |
duke@1 | 209 | } |
duke@1 | 210 | |
duke@1 | 211 | /** |
bpatel@766 | 212 | * Add the anchor. |
bpatel@766 | 213 | * |
bpatel@766 | 214 | * @param builder the deprecated list builder |
bpatel@766 | 215 | * @param type the type of list being documented |
jjg@1358 | 216 | * @param htmlTree the content tree to which the anchor will be added |
duke@1 | 217 | */ |
bpatel@766 | 218 | private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) { |
bpatel@766 | 219 | if (builder.hasDocumentation(type)) { |
bpatel@766 | 220 | htmlTree.addContent(getMarkerAnchor(ANCHORS[type])); |
bpatel@766 | 221 | } |
duke@1 | 222 | } |
duke@1 | 223 | |
duke@1 | 224 | /** |
bpatel@766 | 225 | * Get the header for the deprecated API Listing. |
bpatel@766 | 226 | * |
bpatel@766 | 227 | * @return a content tree for the header |
duke@1 | 228 | */ |
bpatel@766 | 229 | public Content getHeader() { |
bpatel@766 | 230 | String title = configuration.getText("doclet.Window_Deprecated_List"); |
bpatel@766 | 231 | Content bodyTree = getBody(true, getWindowTitle(title)); |
bpatel@766 | 232 | addTop(bodyTree); |
bpatel@766 | 233 | addNavLinks(true, bodyTree); |
bpatel@766 | 234 | return bodyTree; |
bpatel@766 | 235 | } |
bpatel@766 | 236 | |
bpatel@766 | 237 | /** |
bpatel@766 | 238 | * Get the deprecated label. |
bpatel@766 | 239 | * |
bpatel@766 | 240 | * @return a content tree for the deprecated label |
bpatel@766 | 241 | */ |
bpatel@766 | 242 | protected Content getNavLinkDeprecated() { |
bpatel@766 | 243 | Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, deprecatedLabel); |
bpatel@766 | 244 | return li; |
duke@1 | 245 | } |
duke@1 | 246 | } |