Tue, 23 Oct 2012 13:20:37 -0700
8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy
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.DocPaths;
33 import com.sun.tools.doclets.internal.toolkit.util.DocletAbortException;
35 /**
36 * Generate the Serialized Form Information Page.
37 *
38 * <p><b>This is NOT part of any supported API.
39 * If you write code that depends on this, you do so at your own risk.
40 * This code and its internal interfaces are subject to change or
41 * deletion without notice.</b>
42 *
43 * @author Atul M Dambalkar
44 */
45 public class SerializedFormWriterImpl extends SubWriterHolderWriter
46 implements SerializedFormWriter {
48 /**
49 * @throws IOException
50 * @throws DocletAbortException
51 */
52 public SerializedFormWriterImpl() throws IOException {
53 super(ConfigurationImpl.getInstance(), DocPaths.SERIALIZED_FORM);
54 }
56 /**
57 * Get the given header.
58 *
59 * @param header the header to write
60 * @return the body content tree
61 */
62 public Content getHeader(String header) {
63 Content bodyTree = getBody(true, getWindowTitle(header));
64 addTop(bodyTree);
65 addNavLinks(true, bodyTree);
66 Content h1Content = new StringContent(header);
67 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
68 HtmlStyle.title, h1Content);
69 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
70 bodyTree.addContent(div);
71 return bodyTree;
72 }
74 /**
75 * Get the serialized form summaries header.
76 *
77 * @return the serialized form summary header tree
78 */
79 public Content getSerializedSummariesHeader() {
80 HtmlTree ul = new HtmlTree(HtmlTag.UL);
81 ul.addStyle(HtmlStyle.blockList);
82 return ul;
83 }
85 /**
86 * Get the package serialized form header.
87 *
88 * @return the package serialized form header tree
89 */
90 public Content getPackageSerializedHeader() {
91 HtmlTree li = new HtmlTree(HtmlTag.LI);
92 li.addStyle(HtmlStyle.blockList);
93 return li;
94 }
96 /**
97 * Get the given package header.
98 *
99 * @param packageName the package header to write
100 * @return a content tree for the package header
101 */
102 public Content getPackageHeader(String packageName) {
103 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
104 packageLabel);
105 heading.addContent(getSpace());
106 heading.addContent(packageName);
107 return heading;
108 }
110 /**
111 * Get the serialized class header.
112 *
113 * @return a content tree for the serialized class header
114 */
115 public Content getClassSerializedHeader() {
116 HtmlTree ul = new HtmlTree(HtmlTag.UL);
117 ul.addStyle(HtmlStyle.blockList);
118 return ul;
119 }
121 /**
122 * Get the serializable class heading.
123 *
124 * @param classDoc the class being processed
125 * @return a content tree for the class header
126 */
127 public Content getClassHeader(ClassDoc classDoc) {
128 String classLink = (classDoc.isPublic() || classDoc.isProtected())?
129 getLink(new LinkInfoImpl(classDoc,
130 configuration.getClassName(classDoc))):
131 classDoc.qualifiedName();
132 Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
133 classDoc.qualifiedName()));
134 String superClassLink =
135 classDoc.superclassType() != null ?
136 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_SERIALIZED_FORM,
137 classDoc.superclassType())) :
138 null;
140 //Print the heading.
141 String className = superClassLink == null ?
142 configuration.getText(
143 "doclet.Class_0_implements_serializable", classLink) :
144 configuration.getText(
145 "doclet.Class_0_extends_implements_serializable", classLink,
146 superClassLink);
147 Content classNameContent = new RawHtml(className);
148 li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
149 classNameContent));
150 return li;
151 }
153 /**
154 * Get the serial UID info header.
155 *
156 * @return a content tree for the serial uid info header
157 */
158 public Content getSerialUIDInfoHeader() {
159 HtmlTree dl = new HtmlTree(HtmlTag.DL);
160 dl.addStyle(HtmlStyle.nameValue);
161 return dl;
162 }
164 /**
165 * Adds the serial UID info.
166 *
167 * @param header the header that will show up before the UID.
168 * @param serialUID the serial UID to print.
169 * @param serialUidTree the serial UID content tree to which the serial UID
170 * content will be added
171 */
172 public void addSerialUIDInfo(String header, String serialUID,
173 Content serialUidTree) {
174 Content headerContent = new StringContent(header);
175 serialUidTree.addContent(HtmlTree.DT(headerContent));
176 Content serialContent = new StringContent(serialUID);
177 serialUidTree.addContent(HtmlTree.DD(serialContent));
178 }
180 /**
181 * Get the class serialize content header.
182 *
183 * @return a content tree for the class serialize content header
184 */
185 public Content getClassContentHeader() {
186 HtmlTree ul = new HtmlTree(HtmlTag.UL);
187 ul.addStyle(HtmlStyle.blockList);
188 return ul;
189 }
191 /**
192 * Get the serialized content tree section.
193 *
194 * @param serializedTreeContent the serialized content tree to be added
195 * @return a div content tree
196 */
197 public Content getSerializedContent(Content serializedTreeContent) {
198 Content divContent = HtmlTree.DIV(HtmlStyle.serializedFormContainer,
199 serializedTreeContent);
200 return divContent;
201 }
203 /**
204 * Add the footer.
205 *
206 * @param serializedTree the serialized tree to be added
207 */
208 public void addFooter(Content serializedTree) {
209 addNavLinks(false, serializedTree);
210 addBottom(serializedTree);
211 }
213 /**
214 * {@inheritDoc}
215 */
216 public void printDocument(Content serializedTree) throws IOException {
217 printHtmlDocument(null, true, serializedTree);
218 }
220 /**
221 * Return an instance of a SerialFieldWriter.
222 *
223 * @return an instance of a SerialFieldWriter.
224 */
225 public SerialFieldWriter getSerialFieldWriter(ClassDoc classDoc) {
226 return new HtmlSerialFieldWriter(this, classDoc);
227 }
229 /**
230 * Return an instance of a SerialMethodWriter.
231 *
232 * @return an instance of a SerialMethodWriter.
233 */
234 public SerialMethodWriter getSerialMethodWriter(ClassDoc classDoc) {
235 return new HtmlSerialMethodWriter(this, classDoc);
236 }
237 }