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