Fri, 27 Feb 2009 18:57:17 -0800
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
Reviewed-by: jjg
1 /*
2 * Copyright 2003-2005 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.*;
30 import com.sun.tools.doclets.internal.toolkit.util.*;
31 import com.sun.tools.doclets.internal.toolkit.builders.*;
33 /**
34 * Generate the Class Information Page.
35 * @see com.sun.javadoc.ClassDoc
36 * @see java.util.Collections
37 * @see java.util.List
38 * @see java.util.ArrayList
39 * @see java.util.HashMap
40 *
41 * @author Atul M Dambalkar
42 * @author Robert Field
43 */
44 public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
45 implements AnnotationTypeWriter {
47 protected AnnotationTypeDoc annotationType;
49 protected Type prev;
51 protected Type next;
53 /**
54 * @param annotationType the annotation type being documented.
55 * @param prevType the previous class that was documented.
56 * @param nextType the next class being documented.
57 */
58 public AnnotationTypeWriterImpl (AnnotationTypeDoc annotationType,
59 Type prevType, Type nextType)
60 throws Exception {
61 super(ConfigurationImpl.getInstance(),
62 DirectoryManager.getDirectoryPath(annotationType.containingPackage()),
63 annotationType.name() + ".html",
64 DirectoryManager.getRelativePath(annotationType.containingPackage().name()));
65 this.annotationType = annotationType;
66 configuration.currentcd = annotationType.asClassDoc();
67 this.prev = prevType;
68 this.next = nextType;
69 }
71 /**
72 * Print this package link
73 */
74 protected void navLinkPackage() {
75 navCellStart();
76 printHyperLink("package-summary.html", "",
77 configuration.getText("doclet.Package"), true, "NavBarFont1");
78 navCellEnd();
79 }
81 /**
82 * Print class page indicator
83 */
84 protected void navLinkClass() {
85 navCellRevStart();
86 fontStyle("NavBarFont1Rev");
87 strongText("doclet.Class");
88 fontEnd();
89 navCellEnd();
90 }
92 /**
93 * Print class use link
94 */
95 protected void navLinkClassUse() {
96 navCellStart();
97 printHyperLink("class-use/" + filename, "",
98 configuration.getText("doclet.navClassUse"), true, "NavBarFont1");
99 navCellEnd();
100 }
102 /**
103 * Print previous package link
104 */
105 protected void navLinkPrevious() {
106 if (prev == null) {
107 printText("doclet.Prev_Class");
108 } else {
109 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS,
110 prev.asClassDoc(), "",
111 configuration.getText("doclet.Prev_Class"), true));
112 }
113 }
115 /**
116 * Print next package link
117 */
118 protected void navLinkNext() {
119 if (next == null) {
120 printText("doclet.Next_Class");
121 } else {
122 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS,
123 next.asClassDoc(), "",
124 configuration.getText("doclet.Next_Class"), true));
125 }
126 }
128 /**
129 * {@inheritDoc}
130 */
131 public void writeHeader(String header) {
133 String pkgname = (annotationType.containingPackage() != null)?
134 annotationType.containingPackage().name(): "";
135 String clname = annotationType.name();
137 printHtmlHeader(clname,
138 configuration.metakeywords.getMetaKeywords(annotationType), true);
139 printTop();
140 navLinks(true);
141 hr();
142 println("<!-- ======== START OF CLASS DATA ======== -->");
143 h2();
144 if (pkgname.length() > 0) {
145 font("-1"); print(pkgname); fontEnd(); br();
146 }
147 print(header + getTypeParameterLinks(new LinkInfoImpl(
148 LinkInfoImpl.CONTEXT_CLASS_HEADER,
149 annotationType, false)));
150 h2End();
151 }
153 /**
154 * {@inheritDoc}
155 */
156 public void writeFooter() {
157 println("<!-- ========= END OF CLASS DATA ========= -->");
158 hr();
159 navLinks(false);
160 printBottom();
161 printBodyHtmlEnd();
162 }
164 /**
165 * {@inheritDoc}
166 */
167 public void writeAnnotationTypeSignature(String modifiers) {
168 preNoNewLine();
169 writeAnnotationInfo(annotationType);
170 print(modifiers);
171 String name = annotationType.name() +
172 getTypeParameterLinks(new LinkInfoImpl(
173 LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false));
174 if (configuration().linksource) {
175 printSrcLink(annotationType, name);
176 } else {
177 strong(name);
178 }
179 preEnd();
180 p();
181 }
183 /**
184 * {@inheritDoc}
185 */
186 public void writeAnnotationTypeDescription() {
187 if(!configuration.nocomment) {
188 // generate documentation for the class.
189 if (annotationType.inlineTags().length > 0) {
190 printInlineComment(annotationType);
191 p();
192 }
193 }
194 }
196 /**
197 * {@inheritDoc}
198 */
199 public void writeAnnotationTypeTagInfo() {
200 boolean needHr = annotationType.elements().length > 0;
201 if(!configuration.nocomment) {
202 // Print Information about all the tags here
203 printTags(annotationType);
204 if (needHr) {
205 hr();
206 }
207 p();
208 } else if (needHr) {
209 hr();
210 }
211 }
213 /**
214 * {@inheritDoc}
215 */
216 public void writeAnnotationTypeDeprecationInfo() {
217 hr();
218 Tag[] deprs = annotationType.tags("deprecated");
219 if (Util.isDeprecated(annotationType)) {
220 strongText("doclet.Deprecated");
221 if (deprs.length > 0) {
222 Tag[] commentTags = deprs[0].inlineTags();
223 if (commentTags.length > 0) {
225 space();
226 printInlineDeprecatedComment(annotationType, deprs[0]);
227 }
228 }
229 p();
230 }
231 }
233 protected void navLinkTree() {
234 navCellStart();
235 printHyperLink("package-tree.html", "",
236 configuration.getText("doclet.Tree"), true, "NavBarFont1");
237 navCellEnd();
238 }
240 protected void printSummaryDetailLinks() {
241 try {
242 tr();
243 tdVAlignClass("top", "NavBarCell3");
244 font("-2");
245 print(" ");
246 navSummaryLinks();
247 fontEnd();
248 tdEnd();
250 tdVAlignClass("top", "NavBarCell3");
251 font("-2");
252 navDetailLinks();
253 fontEnd();
254 tdEnd();
255 trEnd();
256 } catch (Exception e) {
257 e.printStackTrace();
258 throw new DocletAbortException();
259 }
260 }
262 protected void navSummaryLinks() throws Exception {
263 printText("doclet.Summary");
264 space();
265 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
266 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
267 writeNavSummaryLink(memberSummaryBuilder,
268 "doclet.navAnnotationTypeRequiredMember",
269 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED);
270 navGap();
271 writeNavSummaryLink(memberSummaryBuilder,
272 "doclet.navAnnotationTypeOptionalMember",
273 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL);
274 }
276 private void writeNavSummaryLink(MemberSummaryBuilder builder,
277 String label, int type) {
278 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
279 getMemberSummaryWriter(type));
280 if (writer == null) {
281 printText(label);
282 } else {
283 writer.printNavSummaryLink(null,
284 ! builder.getVisibleMemberMap(type).noVisibleMembers());
285 }
286 }
288 /**
289 * Method navDetailLinks
290 *
291 * @throws Exception
292 *
293 */
294 protected void navDetailLinks() throws Exception {
295 printText("doclet.Detail");
296 space();
297 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
298 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
299 AbstractMemberWriter writerOptional =
300 ((AbstractMemberWriter) memberSummaryBuilder.
301 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
302 AbstractMemberWriter writerRequired =
303 ((AbstractMemberWriter) memberSummaryBuilder.
304 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
305 if (writerOptional != null){
306 writerOptional.printNavDetailLink(annotationType.elements().length > 0);
307 } else if (writerRequired != null){
308 writerRequired.printNavDetailLink(annotationType.elements().length > 0);
309 } else {
310 printText("doclet.navAnnotationTypeMember");
311 }
312 }
314 protected void navGap() {
315 space();
316 print('|');
317 space();
318 }
320 /**
321 * If this is an inner class or interface, write the enclosing class or
322 * interface.
323 */
324 public void writeNestedClassInfo() {
325 ClassDoc outerClass = annotationType.containingClass();
326 if (outerClass != null) {
327 dl();
328 dt();
329 if (annotationType.isInterface()) {
330 strongText("doclet.Enclosing_Interface");
331 } else {
332 strongText("doclet.Enclosing_Class");
333 }
334 dtEnd();
335 dd();
336 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS, outerClass,
337 false));
338 ddEnd();
339 dlEnd();
340 }
341 }
343 /**
344 * {@inheritDoc}
345 */
346 public AnnotationTypeDoc getAnnotationTypeDoc() {
347 return annotationType;
348 }
350 /**
351 * {@inheritDoc}
352 */
353 public void completeMemberSummaryBuild() {
354 p();
355 }
356 }