Mon, 15 Oct 2012 17:07:55 -0700
8000666: javadoc should write directly to Writer instead of composing strings
Reviewed-by: bpatel
1 /*
2 * Copyright (c) 1998, 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.*;
29 import com.sun.javadoc.*;
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.DocletAbortException;
34 /**
35 * Generate the Serialized Form Information Page.
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 Atul M Dambalkar
43 */
44 public class SerializedFormWriterImpl extends SubWriterHolderWriter
45 implements SerializedFormWriter {
47 private static final String FILE_NAME = "serialized-form.html";
49 /**
50 * @throws IOException
51 * @throws DocletAbortException
52 */
53 public SerializedFormWriterImpl() throws IOException {
54 super(ConfigurationImpl.getInstance(), FILE_NAME);
55 }
57 /**
58 * Get the given header.
59 *
60 * @param header the header to write
61 * @return the body content tree
62 */
63 public Content getHeader(String header) {
64 Content bodyTree = getBody(true, getWindowTitle(header));
65 addTop(bodyTree);
66 addNavLinks(true, bodyTree);
67 Content h1Content = new StringContent(header);
68 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
69 HtmlStyle.title, h1Content);
70 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
71 bodyTree.addContent(div);
72 return bodyTree;
73 }
75 /**
76 * Get the serialized form summaries header.
77 *
78 * @return the serialized form summary header tree
79 */
80 public Content getSerializedSummariesHeader() {
81 HtmlTree ul = new HtmlTree(HtmlTag.UL);
82 ul.addStyle(HtmlStyle.blockList);
83 return ul;
84 }
86 /**
87 * Get the package serialized form header.
88 *
89 * @return the package serialized form header tree
90 */
91 public Content getPackageSerializedHeader() {
92 HtmlTree li = new HtmlTree(HtmlTag.LI);
93 li.addStyle(HtmlStyle.blockList);
94 return li;
95 }
97 /**
98 * Get the given package header.
99 *
100 * @param packageName the package header to write
101 * @return a content tree for the package header
102 */
103 public Content getPackageHeader(String packageName) {
104 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
105 packageLabel);
106 heading.addContent(getSpace());
107 heading.addContent(packageName);
108 return heading;
109 }
111 /**
112 * Get the serialized class header.
113 *
114 * @return a content tree for the serialized class header
115 */
116 public Content getClassSerializedHeader() {
117 HtmlTree ul = new HtmlTree(HtmlTag.UL);
118 ul.addStyle(HtmlStyle.blockList);
119 return ul;
120 }
122 /**
123 * Get the serializable class heading.
124 *
125 * @param classDoc the class being processed
126 * @return a content tree for the class header
127 */
128 public Content getClassHeader(ClassDoc classDoc) {
129 String classLink = (classDoc.isPublic() || classDoc.isProtected())?
130 getLink(new LinkInfoImpl(classDoc,
131 configuration.getClassName(classDoc))):
132 classDoc.qualifiedName();
133 Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
134 classDoc.qualifiedName()));
135 String superClassLink =
136 classDoc.superclassType() != null ?
137 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_SERIALIZED_FORM,
138 classDoc.superclassType())) :
139 null;
141 //Print the heading.
142 String className = superClassLink == null ?
143 configuration.getText(
144 "doclet.Class_0_implements_serializable", classLink) :
145 configuration.getText(
146 "doclet.Class_0_extends_implements_serializable", classLink,
147 superClassLink);
148 Content classNameContent = new RawHtml(className);
149 li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
150 classNameContent));
151 return li;
152 }
154 /**
155 * Get the serial UID info header.
156 *
157 * @return a content tree for the serial uid info header
158 */
159 public Content getSerialUIDInfoHeader() {
160 HtmlTree dl = new HtmlTree(HtmlTag.DL);
161 dl.addStyle(HtmlStyle.nameValue);
162 return dl;
163 }
165 /**
166 * Adds the serial UID info.
167 *
168 * @param header the header that will show up before the UID.
169 * @param serialUID the serial UID to print.
170 * @param serialUidTree the serial UID content tree to which the serial UID
171 * content will be added
172 */
173 public void addSerialUIDInfo(String header, String serialUID,
174 Content serialUidTree) {
175 Content headerContent = new StringContent(header);
176 serialUidTree.addContent(HtmlTree.DT(headerContent));
177 Content serialContent = new StringContent(serialUID);
178 serialUidTree.addContent(HtmlTree.DD(serialContent));
179 }
181 /**
182 * Get the class serialize content header.
183 *
184 * @return a content tree for the class serialize content header
185 */
186 public Content getClassContentHeader() {
187 HtmlTree ul = new HtmlTree(HtmlTag.UL);
188 ul.addStyle(HtmlStyle.blockList);
189 return ul;
190 }
192 /**
193 * Get the serialized content tree section.
194 *
195 * @param serializedTreeContent the serialized content tree to be added
196 * @return a div content tree
197 */
198 public Content getSerializedContent(Content serializedTreeContent) {
199 Content divContent = HtmlTree.DIV(HtmlStyle.serializedFormContainer,
200 serializedTreeContent);
201 return divContent;
202 }
204 /**
205 * Add the footer.
206 *
207 * @param serializedTree the serialized tree to be added
208 */
209 public void addFooter(Content serializedTree) {
210 addNavLinks(false, serializedTree);
211 addBottom(serializedTree);
212 }
214 /**
215 * {@inheritDoc}
216 */
217 public void printDocument(Content serializedTree) throws IOException {
218 printHtmlDocument(null, true, serializedTree);
219 }
221 private void tableHeader() {
222 tableIndexSummary();
223 trBgcolorStyle("#CCCCFF", "TableSubHeadingColor");
224 }
226 private void tableFooter() {
227 fontEnd();
228 thEnd(); trEnd(); tableEnd();
229 }
231 /**
232 * Return an instance of a SerialFieldWriter.
233 *
234 * @return an instance of a SerialFieldWriter.
235 */
236 public SerialFieldWriter getSerialFieldWriter(ClassDoc classDoc) {
237 return new HtmlSerialFieldWriter(this, classDoc);
238 }
240 /**
241 * Return an instance of a SerialMethodWriter.
242 *
243 * @return an instance of a SerialMethodWriter.
244 */
245 public SerialMethodWriter getSerialMethodWriter(ClassDoc classDoc) {
246 return new HtmlSerialMethodWriter(this, classDoc);
247 }
248 }