Tue, 14 May 2013 10:14:55 -0700
8012178: Cleanup use of Util.escapeHtmlChars
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 2013, 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.internal.toolkit.builders;
28 import java.io.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
34 /**
35 * Builds the summary for a given package.
36 *
37 * <p><b>This is NOT part of any supported API.
38 * If you write code that depends on this, you do so at your own risk.
39 * This code and its internal interfaces are subject to change or
40 * deletion without notice.</b>
41 *
42 * @author Jamie Ho
43 * @author Bhavesh Patel (Modified)
44 * @since 1.5
45 */
46 public class PackageSummaryBuilder extends AbstractBuilder {
47 /**
48 * The root element of the package summary XML is {@value}.
49 */
50 public static final String ROOT = "PackageDoc";
52 /**
53 * The package being documented.
54 */
55 private final PackageDoc packageDoc;
57 /**
58 * The doclet specific writer that will output the result.
59 */
60 private final PackageSummaryWriter packageWriter;
62 /**
63 * The content that will be added to the package summary documentation tree.
64 */
65 private Content contentTree;
67 /**
68 * Construct a new PackageSummaryBuilder.
69 *
70 * @param context the build context.
71 * @param pkg the package being documented.
72 * @param packageWriter the doclet specific writer that will output the
73 * result.
74 */
75 private PackageSummaryBuilder(Context context,
76 PackageDoc pkg,
77 PackageSummaryWriter packageWriter) {
78 super(context);
79 this.packageDoc = pkg;
80 this.packageWriter = packageWriter;
81 }
83 /**
84 * Construct a new PackageSummaryBuilder.
85 *
86 * @param context the build context.
87 * @param pkg the package being documented.
88 * @param packageWriter the doclet specific writer that will output the
89 * result.
90 *
91 * @return an instance of a PackageSummaryBuilder.
92 */
93 public static PackageSummaryBuilder getInstance(Context context,
94 PackageDoc pkg, PackageSummaryWriter packageWriter) {
95 return new PackageSummaryBuilder(context, pkg, packageWriter);
96 }
98 /**
99 * Build the package summary.
100 */
101 public void build() throws IOException {
102 if (packageWriter == null) {
103 //Doclet does not support this output.
104 return;
105 }
106 build(layoutParser.parseXML(ROOT), contentTree);
107 }
109 /**
110 * {@inheritDoc}
111 */
112 public String getName() {
113 return ROOT;
114 }
116 /**
117 * Build the package documentation.
118 *
119 * @param node the XML element that specifies which components to document
120 * @param contentTree the content tree to which the documentation will be added
121 */
122 public void buildPackageDoc(XMLNode node, Content contentTree) throws Exception {
123 contentTree = packageWriter.getPackageHeader(Util.getPackageName(packageDoc));
124 buildChildren(node, contentTree);
125 packageWriter.addPackageFooter(contentTree);
126 packageWriter.printDocument(contentTree);
127 packageWriter.close();
128 Util.copyDocFiles(configuration, packageDoc);
129 }
131 /**
132 * Build the content for the package doc.
133 *
134 * @param node the XML element that specifies which components to document
135 * @param contentTree the content tree to which the package contents
136 * will be added
137 */
138 public void buildContent(XMLNode node, Content contentTree) {
139 Content packageContentTree = packageWriter.getContentHeader();
140 buildChildren(node, packageContentTree);
141 contentTree.addContent(packageContentTree);
142 }
144 /**
145 * Build the package summary.
146 *
147 * @param node the XML element that specifies which components to document
148 * @param packageContentTree the package content tree to which the summaries will
149 * be added
150 */
151 public void buildSummary(XMLNode node, Content packageContentTree) {
152 Content summaryContentTree = packageWriter.getSummaryHeader();
153 buildChildren(node, summaryContentTree);
154 packageContentTree.addContent(summaryContentTree);
155 }
157 /**
158 * Build the summary for the interfaces in this package.
159 *
160 * @param node the XML element that specifies which components to document
161 * @param summaryContentTree the summary tree to which the interface summary
162 * will be added
163 */
164 public void buildInterfaceSummary(XMLNode node, Content summaryContentTree) {
165 String interfaceTableSummary =
166 configuration.getText("doclet.Member_Table_Summary",
167 configuration.getText("doclet.Interface_Summary"),
168 configuration.getText("doclet.interfaces"));
169 String[] interfaceTableHeader = new String[] {
170 configuration.getText("doclet.Interface"),
171 configuration.getText("doclet.Description")
172 };
173 ClassDoc[] interfaces =
174 packageDoc.isIncluded()
175 ? packageDoc.interfaces()
176 : configuration.classDocCatalog.interfaces(
177 Util.getPackageName(packageDoc));
178 interfaces = Util.filterOutPrivateClasses(interfaces, configuration.javafx);
179 if (interfaces.length > 0) {
180 packageWriter.addClassesSummary(
181 interfaces,
182 configuration.getText("doclet.Interface_Summary"),
183 interfaceTableSummary, interfaceTableHeader, summaryContentTree);
184 }
185 }
187 /**
188 * Build the summary for the classes in this package.
189 *
190 * @param node the XML element that specifies which components to document
191 * @param summaryContentTree the summary tree to which the class summary will
192 * be added
193 */
194 public void buildClassSummary(XMLNode node, Content summaryContentTree) {
195 String classTableSummary =
196 configuration.getText("doclet.Member_Table_Summary",
197 configuration.getText("doclet.Class_Summary"),
198 configuration.getText("doclet.classes"));
199 String[] classTableHeader = new String[] {
200 configuration.getText("doclet.Class"),
201 configuration.getText("doclet.Description")
202 };
203 ClassDoc[] classes =
204 packageDoc.isIncluded()
205 ? packageDoc.ordinaryClasses()
206 : configuration.classDocCatalog.ordinaryClasses(
207 Util.getPackageName(packageDoc));
208 classes = Util.filterOutPrivateClasses(classes, configuration.javafx);
209 if (classes.length > 0) {
210 packageWriter.addClassesSummary(
211 classes,
212 configuration.getText("doclet.Class_Summary"),
213 classTableSummary, classTableHeader, summaryContentTree);
214 }
215 }
217 /**
218 * Build the summary for the enums in this package.
219 *
220 * @param node the XML element that specifies which components to document
221 * @param summaryContentTree the summary tree to which the enum summary will
222 * be added
223 */
224 public void buildEnumSummary(XMLNode node, Content summaryContentTree) {
225 String enumTableSummary =
226 configuration.getText("doclet.Member_Table_Summary",
227 configuration.getText("doclet.Enum_Summary"),
228 configuration.getText("doclet.enums"));
229 String[] enumTableHeader = new String[] {
230 configuration.getText("doclet.Enum"),
231 configuration.getText("doclet.Description")
232 };
233 ClassDoc[] enums =
234 packageDoc.isIncluded()
235 ? packageDoc.enums()
236 : configuration.classDocCatalog.enums(
237 Util.getPackageName(packageDoc));
238 enums = Util.filterOutPrivateClasses(enums, configuration.javafx);
239 if (enums.length > 0) {
240 packageWriter.addClassesSummary(
241 enums,
242 configuration.getText("doclet.Enum_Summary"),
243 enumTableSummary, enumTableHeader, summaryContentTree);
244 }
245 }
247 /**
248 * Build the summary for the exceptions in this package.
249 *
250 * @param node the XML element that specifies which components to document
251 * @param summaryContentTree the summary tree to which the exception summary will
252 * be added
253 */
254 public void buildExceptionSummary(XMLNode node, Content summaryContentTree) {
255 String exceptionTableSummary =
256 configuration.getText("doclet.Member_Table_Summary",
257 configuration.getText("doclet.Exception_Summary"),
258 configuration.getText("doclet.exceptions"));
259 String[] exceptionTableHeader = new String[] {
260 configuration.getText("doclet.Exception"),
261 configuration.getText("doclet.Description")
262 };
263 ClassDoc[] exceptions =
264 packageDoc.isIncluded()
265 ? packageDoc.exceptions()
266 : configuration.classDocCatalog.exceptions(
267 Util.getPackageName(packageDoc));
268 exceptions = Util.filterOutPrivateClasses(exceptions, configuration.javafx);
269 if (exceptions.length > 0) {
270 packageWriter.addClassesSummary(
271 exceptions,
272 configuration.getText("doclet.Exception_Summary"),
273 exceptionTableSummary, exceptionTableHeader, summaryContentTree);
274 }
275 }
277 /**
278 * Build the summary for the errors in this package.
279 *
280 * @param node the XML element that specifies which components to document
281 * @param summaryContentTree the summary tree to which the error summary will
282 * be added
283 */
284 public void buildErrorSummary(XMLNode node, Content summaryContentTree) {
285 String errorTableSummary =
286 configuration.getText("doclet.Member_Table_Summary",
287 configuration.getText("doclet.Error_Summary"),
288 configuration.getText("doclet.errors"));
289 String[] errorTableHeader = new String[] {
290 configuration.getText("doclet.Error"),
291 configuration.getText("doclet.Description")
292 };
293 ClassDoc[] errors =
294 packageDoc.isIncluded()
295 ? packageDoc.errors()
296 : configuration.classDocCatalog.errors(
297 Util.getPackageName(packageDoc));
298 errors = Util.filterOutPrivateClasses(errors, configuration.javafx);
299 if (errors.length > 0) {
300 packageWriter.addClassesSummary(
301 errors,
302 configuration.getText("doclet.Error_Summary"),
303 errorTableSummary, errorTableHeader, summaryContentTree);
304 }
305 }
307 /**
308 * Build the summary for the annotation type in this package.
309 *
310 * @param node the XML element that specifies which components to document
311 * @param summaryContentTree the summary tree to which the annotation type
312 * summary will be added
313 */
314 public void buildAnnotationTypeSummary(XMLNode node, Content summaryContentTree) {
315 String annotationtypeTableSummary =
316 configuration.getText("doclet.Member_Table_Summary",
317 configuration.getText("doclet.Annotation_Types_Summary"),
318 configuration.getText("doclet.annotationtypes"));
319 String[] annotationtypeTableHeader = new String[] {
320 configuration.getText("doclet.AnnotationType"),
321 configuration.getText("doclet.Description")
322 };
323 ClassDoc[] annotationTypes =
324 packageDoc.isIncluded()
325 ? packageDoc.annotationTypes()
326 : configuration.classDocCatalog.annotationTypes(
327 Util.getPackageName(packageDoc));
328 annotationTypes = Util.filterOutPrivateClasses(annotationTypes, configuration.javafx);
329 if (annotationTypes.length > 0) {
330 packageWriter.addClassesSummary(
331 annotationTypes,
332 configuration.getText("doclet.Annotation_Types_Summary"),
333 annotationtypeTableSummary, annotationtypeTableHeader,
334 summaryContentTree);
335 }
336 }
338 /**
339 * Build the description of the summary.
340 *
341 * @param node the XML element that specifies which components to document
342 * @param packageContentTree the tree to which the package description will
343 * be added
344 */
345 public void buildPackageDescription(XMLNode node, Content packageContentTree) {
346 if (configuration.nocomment) {
347 return;
348 }
349 packageWriter.addPackageDescription(packageContentTree);
350 }
352 /**
353 * Build the tags of the summary.
354 *
355 * @param node the XML element that specifies which components to document
356 * @param packageContentTree the tree to which the package tags will be added
357 */
358 public void buildPackageTags(XMLNode node, Content packageContentTree) {
359 if (configuration.nocomment) {
360 return;
361 }
362 packageWriter.addPackageTags(packageContentTree);
363 }
364 }