Fri, 18 Jun 2010 21:13:56 -0700
6961178: Allow doclet.xml to contain XML attributes
Reviewed-by: bpatel
1 /*
2 * Copyright (c) 2003, 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 com.sun.tools.doclets.internal.toolkit.util.*;
29 import com.sun.tools.doclets.internal.toolkit.*;
30 import com.sun.javadoc.*;
31 import java.io.*;
33 /**
34 * Builds the summary for a given package.
35 *
36 * This code is not part of an API.
37 * It is implementation that is subject to change.
38 * Do not use it as an API
39 *
40 * @author Jamie Ho
41 * @author Bhavesh Patel (Modified)
42 * @since 1.5
43 */
44 public class PackageSummaryBuilder extends AbstractBuilder {
46 /**
47 * The root element of the package summary XML is {@value}.
48 */
49 public static final String ROOT = "PackageDoc";
51 /**
52 * The package being documented.
53 */
54 private PackageDoc packageDoc;
56 /**
57 * The doclet specific writer that will output the result.
58 */
59 private PackageSummaryWriter packageWriter;
61 private PackageSummaryBuilder(Configuration configuration) {
62 super(configuration);
63 }
65 /**
66 * Construct a new PackageSummaryBuilder.
67 * @param configuration the current configuration of the doclet.
68 * @param pkg the package being documented.
69 * @param packageWriter the doclet specific writer that will output the
70 * result.
71 *
72 * @return an instance of a PackageSummaryBuilder.
73 */
74 public static PackageSummaryBuilder getInstance(
75 Configuration configuration,
76 PackageDoc pkg,
77 PackageSummaryWriter packageWriter) {
78 PackageSummaryBuilder builder =
79 new PackageSummaryBuilder(configuration);
80 builder.packageDoc = pkg;
81 builder.packageWriter = packageWriter;
82 return builder;
83 }
85 /**
86 * Build the package summary.
87 */
88 public void build() throws IOException {
89 if (packageWriter == null) {
90 //Doclet does not support this output.
91 return;
92 }
93 build(LayoutParser.getInstance(configuration).parseXML(ROOT));
94 }
96 /**
97 * {@inheritDoc}
98 */
99 public String getName() {
100 return ROOT;
101 }
103 /**
104 * Build the package documentation.
105 */
106 public void buildPackageDoc(XMLNode node) throws Exception {
107 buildChildren(node);
108 packageWriter.close();
109 Util.copyDocFiles(
110 configuration,
111 Util.getPackageSourcePath(configuration, packageDoc),
112 DirectoryManager.getDirectoryPath(packageDoc)
113 + File.separator
114 + DocletConstants.DOC_FILES_DIR_NAME,
115 true);
116 }
118 /**
119 * Build the header of the summary.
120 */
121 public void buildPackageHeader(XMLNode node) {
122 packageWriter.writePackageHeader(Util.getPackageName(packageDoc));
123 }
125 /**
126 * Build the description of the summary.
127 */
128 public void buildPackageDescription(XMLNode node) {
129 if (configuration.nocomment) {
130 return;
131 }
132 packageWriter.writePackageDescription();
133 }
135 /**
136 * Build the tags of the summary.
137 */
138 public void buildPackageTags(XMLNode node) {
139 if (configuration.nocomment) {
140 return;
141 }
142 packageWriter.writePackageTags();
143 }
145 /**
146 * Build the package summary.
147 */
148 public void buildSummary(XMLNode node) {
149 buildChildren(node);
150 }
152 /**
153 * Build the overall header.
154 */
155 public void buildSummaryHeader(XMLNode node) {
156 packageWriter.writeSummaryHeader();
157 }
159 /**
160 * Build the overall footer.
161 */
162 public void buildSummaryFooter(XMLNode node) {
163 packageWriter.writeSummaryFooter();
164 }
166 /**
167 * Build the summary for the classes in this package.
168 */
169 public void buildClassSummary(XMLNode node) {
170 String classTableSummary =
171 configuration.getText("doclet.Member_Table_Summary",
172 configuration.getText("doclet.Class_Summary"),
173 configuration.getText("doclet.classes"));
174 String[] classTableHeader = new String[] {
175 configuration.getText("doclet.Class"),
176 configuration.getText("doclet.Description")
177 };
178 ClassDoc[] classes =
179 packageDoc.isIncluded()
180 ? packageDoc.ordinaryClasses()
181 : configuration.classDocCatalog.ordinaryClasses(
182 Util.getPackageName(packageDoc));
183 if (classes.length > 0) {
184 packageWriter.writeClassesSummary(
185 classes,
186 configuration.getText("doclet.Class_Summary"),
187 classTableSummary, classTableHeader);
188 }
189 }
191 /**
192 * Build the summary for the interfaces in this package.
193 */
194 public void buildInterfaceSummary(XMLNode node) {
195 String interfaceTableSummary =
196 configuration.getText("doclet.Member_Table_Summary",
197 configuration.getText("doclet.Interface_Summary"),
198 configuration.getText("doclet.interfaces"));
199 String[] interfaceTableHeader = new String[] {
200 configuration.getText("doclet.Interface"),
201 configuration.getText("doclet.Description")
202 };
203 ClassDoc[] interfaces =
204 packageDoc.isIncluded()
205 ? packageDoc.interfaces()
206 : configuration.classDocCatalog.interfaces(
207 Util.getPackageName(packageDoc));
208 if (interfaces.length > 0) {
209 packageWriter.writeClassesSummary(
210 interfaces,
211 configuration.getText("doclet.Interface_Summary"),
212 interfaceTableSummary, interfaceTableHeader);
213 }
214 }
216 /**
217 * Build the summary for the enums in this package.
218 */
219 public void buildAnnotationTypeSummary(XMLNode node) {
220 String annotationtypeTableSummary =
221 configuration.getText("doclet.Member_Table_Summary",
222 configuration.getText("doclet.Annotation_Types_Summary"),
223 configuration.getText("doclet.annotationtypes"));
224 String[] annotationtypeTableHeader = new String[] {
225 configuration.getText("doclet.AnnotationType"),
226 configuration.getText("doclet.Description")
227 };
228 ClassDoc[] annotationTypes =
229 packageDoc.isIncluded()
230 ? packageDoc.annotationTypes()
231 : configuration.classDocCatalog.annotationTypes(
232 Util.getPackageName(packageDoc));
233 if (annotationTypes.length > 0) {
234 packageWriter.writeClassesSummary(
235 annotationTypes,
236 configuration.getText("doclet.Annotation_Types_Summary"),
237 annotationtypeTableSummary, annotationtypeTableHeader);
238 }
239 }
241 /**
242 * Build the summary for the enums in this package.
243 */
244 public void buildEnumSummary(XMLNode node) {
245 String enumTableSummary =
246 configuration.getText("doclet.Member_Table_Summary",
247 configuration.getText("doclet.Enum_Summary"),
248 configuration.getText("doclet.enums"));
249 String[] enumTableHeader = new String[] {
250 configuration.getText("doclet.Enum"),
251 configuration.getText("doclet.Description")
252 };
253 ClassDoc[] enums =
254 packageDoc.isIncluded()
255 ? packageDoc.enums()
256 : configuration.classDocCatalog.enums(
257 Util.getPackageName(packageDoc));
258 if (enums.length > 0) {
259 packageWriter.writeClassesSummary(
260 enums,
261 configuration.getText("doclet.Enum_Summary"),
262 enumTableSummary, enumTableHeader);
263 }
264 }
266 /**
267 * Build the summary for the exceptions in this package.
268 */
269 public void buildExceptionSummary(XMLNode node) {
270 String exceptionTableSummary =
271 configuration.getText("doclet.Member_Table_Summary",
272 configuration.getText("doclet.Exception_Summary"),
273 configuration.getText("doclet.exceptions"));
274 String[] exceptionTableHeader = new String[] {
275 configuration.getText("doclet.Exception"),
276 configuration.getText("doclet.Description")
277 };
278 ClassDoc[] exceptions =
279 packageDoc.isIncluded()
280 ? packageDoc.exceptions()
281 : configuration.classDocCatalog.exceptions(
282 Util.getPackageName(packageDoc));
283 if (exceptions.length > 0) {
284 packageWriter.writeClassesSummary(
285 exceptions,
286 configuration.getText("doclet.Exception_Summary"),
287 exceptionTableSummary, exceptionTableHeader);
288 }
289 }
291 /**
292 * Build the summary for the errors in this package.
293 */
294 public void buildErrorSummary(XMLNode node) {
295 String errorTableSummary =
296 configuration.getText("doclet.Member_Table_Summary",
297 configuration.getText("doclet.Error_Summary"),
298 configuration.getText("doclet.errors"));
299 String[] errorTableHeader = new String[] {
300 configuration.getText("doclet.Error"),
301 configuration.getText("doclet.Description")
302 };
303 ClassDoc[] errors =
304 packageDoc.isIncluded()
305 ? packageDoc.errors()
306 : configuration.classDocCatalog.errors(
307 Util.getPackageName(packageDoc));
308 if (errors.length > 0) {
309 packageWriter.writeClassesSummary(
310 errors,
311 configuration.getText("doclet.Error_Summary"),
312 errorTableSummary, errorTableHeader);
313 }
314 }
316 /**
317 * Build the footer of the summary.
318 */
319 public void buildPackageFooter(XMLNode node) {
320 packageWriter.writePackageFooter();
321 }
322 }