Sat, 13 Apr 2013 18:48:29 -0700
8009686: Generated javadoc documentation should be able to display type annotation on an array
Reviewed-by: jjg
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.markup;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
33 import com.sun.tools.doclets.internal.toolkit.*;
34 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
35 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
36 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
37 import com.sun.tools.doclets.internal.toolkit.util.DocPaths;
40 /**
41 * Class for the Html Format Code Generation specific to JavaDoc.
42 * This Class contains methods related to the Html Code Generation which
43 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
44 * and com.sun.tools.doclets.oneone.
45 *
46 * <p><b>This is NOT part of any supported API.
47 * If you write code that depends on this, you do so at your own risk.
48 * This code and its internal interfaces are subject to change or
49 * deletion without notice.</b>
50 *
51 * @since 1.2
52 * @author Atul M Dambalkar
53 * @author Robert Field
54 */
55 public abstract class HtmlDocWriter extends HtmlWriter {
57 /**
58 * Constructor. Initializes the destination file name through the super
59 * class HtmlWriter.
60 *
61 * @param filename String file name.
62 */
63 public HtmlDocWriter(Configuration configuration, DocPath filename)
64 throws IOException {
65 super(configuration, filename);
66 configuration.message.notice("doclet.Generating_0",
67 DocFile.createFileForOutput(configuration, filename).getPath());
68 }
70 /**
71 * Accessor for configuration.
72 */
73 public abstract Configuration configuration();
75 /**
76 * Return Html Hyper Link string.
77 *
78 * @param link String name of the file.
79 * @param label Tag for the link.
80 * @param strong Boolean that sets label to strong.
81 * @return String Hyper Link.
82 */
83 public String getHyperLinkString(DocPath link,
84 String label, boolean strong) {
85 return getHyperLinkString(link, label, strong, "", "", "");
86 }
88 public String getHyperLinkString(DocLink link,
89 String label, boolean strong) {
90 return getHyperLinkString(link, label, strong, "", "", "");
91 }
93 /**
94 * Get Html Hyper Link string.
95 *
96 * @param link String name of the file.
97 * @param label Tag for the link.
98 * @param strong Boolean that sets label to strong.
99 * @param stylename String style of text defined in style sheet.
100 * @return String Hyper Link.
101 */
102 public String getHyperLinkString(DocPath link,
103 String label, boolean strong,
104 String stylename) {
105 return getHyperLinkString(link, label, strong, stylename, "", "");
106 }
108 public String getHyperLinkString(DocLink link,
109 String label, boolean strong,
110 String stylename) {
111 return getHyperLinkString(link, label, strong, stylename, "", "");
112 }
114 /**
115 * Get Html Hyper Link string.
116 *
117 * @param where Position of the link in the file. Character '#' is not
118 * needed.
119 * @param label Tag for the link.
120 * @return a content tree for the hyper link
121 */
122 public Content getHyperLink(String where,
123 Content label) {
124 return getHyperLink(DocLink.fragment(where), label, "", "");
125 }
127 /**
128 * Get Html Hyper Link string.
129 *
130 * @param link String name of the file.
131 * @param label Tag for the link.
132 * @return a content tree for the hyper link
133 */
134 public Content getHyperLink(DocPath link,
135 Content label) {
136 return getHyperLink(link, label, "", "");
137 }
139 public Content getHyperLink(DocLink link,
140 Content label) {
141 return getHyperLink(link, label, "", "");
142 }
144 /**
145 * Get Html Hyper Link string.
146 *
147 * @param link String name of the file.
148 * @param label Tag for the link.
149 * @param strong Boolean that sets label to strong.
150 * @param stylename String style of text defined in style sheet.
151 * @param title String that describes the links content for accessibility.
152 * @param target Target frame.
153 * @return String Hyper Link.
154 */
155 public String getHyperLinkString(DocPath link,
156 String label, boolean strong,
157 String stylename, String title, String target) {
158 return getHyperLinkString(new DocLink(link), label, strong,
159 stylename, title, target);
160 }
162 public String getHyperLinkString(DocLink link,
163 String label, boolean strong,
164 String stylename, String title, String target) {
165 StringBuilder retlink = new StringBuilder();
166 retlink.append("<a href=\"").append(link).append('"');
167 if (title != null && title.length() != 0) {
168 retlink.append(" title=\"").append(title).append('"');
169 }
170 if (target != null && target.length() != 0) {
171 retlink.append(" target=\"").append(target).append('"');
172 }
173 retlink.append(">");
174 if (stylename != null && stylename.length() != 0) {
175 retlink.append("<FONT CLASS=\"");
176 retlink.append(stylename);
177 retlink.append("\">");
178 }
179 if (strong) {
180 retlink.append("<span class=\"strong\">");
181 }
182 retlink.append(label);
183 if (strong) {
184 retlink.append("</span>");
185 }
186 if (stylename != null && stylename.length() != 0) {
187 retlink.append("</FONT>");
188 }
189 retlink.append("</a>");
190 return retlink.toString();
191 }
193 /**
194 * Get Html Hyper Link.
195 *
196 * @param link String name of the file.
197 * @param label Tag for the link.
198 * @param title String that describes the link's content for accessibility.
199 * @param target Target frame.
200 * @return a content tree for the hyper link.
201 */
202 public Content getHyperLink(DocPath link,
203 Content label, String title, String target) {
204 return getHyperLink(new DocLink(link), label, title, target);
205 }
207 public Content getHyperLink(DocLink link,
208 Content label, String title, String target) {
209 HtmlTree anchor = HtmlTree.A(link.toString(), label);
210 if (title != null && title.length() != 0) {
211 anchor.addAttr(HtmlAttr.TITLE, title);
212 }
213 if (target != null && target.length() != 0) {
214 anchor.addAttr(HtmlAttr.TARGET, target);
215 }
216 return anchor;
217 }
219 /**
220 * Get link string without positioning in the file.
221 *
222 * @param link String name of the file.
223 * @param label Tag for the link.
224 * @return Strign Hyper link.
225 */
226 public String getHyperLinkString(DocPath link, String label) {
227 return getHyperLinkString(link, label, false);
228 }
230 /**
231 * Get the name of the package, this class is in.
232 *
233 * @param cd ClassDoc.
234 */
235 public String getPkgName(ClassDoc cd) {
236 String pkgName = cd.containingPackage().name();
237 if (pkgName.length() > 0) {
238 pkgName += ".";
239 return pkgName;
240 }
241 return "";
242 }
244 public boolean getMemberDetailsListPrinted() {
245 return memberDetailsListPrinted;
246 }
248 /**
249 * Print the frameset version of the Html file header.
250 * Called only when generating an HTML frameset file.
251 *
252 * @param title Title of this HTML document
253 * @param noTimeStamp If true, don't print time stamp in header
254 * @param frameset the frameset to be added to the HTML document
255 */
256 public void printFramesetDocument(String title, boolean noTimeStamp,
257 Content frameset) throws IOException {
258 Content htmlDocType = DocType.FRAMESET;
259 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
260 Content head = new HtmlTree(HtmlTag.HEAD);
261 if (! noTimeStamp) {
262 Content headComment = new Comment(getGeneratedByString());
263 head.addContent(headComment);
264 }
265 if (configuration.charset.length() > 0) {
266 Content meta = HtmlTree.META("Content-Type", "text/html",
267 configuration.charset);
268 head.addContent(meta);
269 }
270 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
271 head.addContent(windowTitle);
272 head.addContent(getFramesetJavaScript());
273 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
274 head, frameset);
275 Content htmlDocument = new HtmlDocument(htmlDocType,
276 htmlComment, htmlTree);
277 write(htmlDocument);
278 }
280 /**
281 * Print the appropriate spaces to format the class tree in the class page.
282 *
283 * @param len Number of spaces.
284 */
285 public String spaces(int len) {
286 String space = "";
288 for (int i = 0; i < len; i++) {
289 space += " ";
290 }
291 return space;
292 }
294 protected String getGeneratedByString() {
295 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
296 Date today = calendar.getTime();
297 return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
298 }
299 }