SerializedFormWriterImpl.java revision 3233:b5d08bc0d224
1/*
2 * Copyright (c) 1998, 2015, 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 */
25
26package jdk.javadoc.internal.doclets.formats.html;
27
28import java.io.*;
29import java.util.*;
30
31import javax.lang.model.element.TypeElement;
32
33import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
34import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
35import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
36import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
37import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
38import jdk.javadoc.internal.doclets.toolkit.Content;
39import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter;
40import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter.SerialFieldWriter;
41import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter.SerialMethodWriter;
42import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
43import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
44
45/**
46 * Generate the Serialized Form Information Page.
47 *
48 *  <p><b>This is NOT part of any supported API.
49 *  If you write code that depends on this, you do so at your own risk.
50 *  This code and its internal interfaces are subject to change or
51 *  deletion without notice.</b>
52 *
53 * @author Atul M Dambalkar
54 */
55public class SerializedFormWriterImpl extends SubWriterHolderWriter
56    implements SerializedFormWriter {
57
58    Set<TypeElement> visibleClasses;
59
60    /**
61     * HTML tree for main tag.
62     */
63    private HtmlTree mainTree = HtmlTree.MAIN();
64
65    /**
66     * @param configuration the configuration data for the doclet
67     * @throws IOException
68     * @throws DocletAbortException
69     */
70    public SerializedFormWriterImpl(ConfigurationImpl configuration)
71            throws IOException {
72        super(configuration, DocPaths.SERIALIZED_FORM);
73        visibleClasses = configuration.root.getIncludedClasses();
74    }
75
76    /**
77     * Get the given header.
78     *
79     * @param header the header to write
80     * @return the body content tree
81     */
82    public Content getHeader(String header) {
83        HtmlTree bodyTree = getBody(true, getWindowTitle(header));
84        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
85                ? HtmlTree.HEADER()
86                : bodyTree;
87        addTop(htmlTree);
88        addNavLinks(true, htmlTree);
89        if (configuration.allowTag(HtmlTag.HEADER)) {
90            bodyTree.addContent(htmlTree);
91        }
92        Content h1Content = new StringContent(header);
93        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
94                HtmlStyle.title, h1Content);
95        Content div = HtmlTree.DIV(HtmlStyle.header, heading);
96        if (configuration.allowTag(HtmlTag.MAIN)) {
97            mainTree.addContent(div);
98        } else {
99            bodyTree.addContent(div);
100        }
101        return bodyTree;
102    }
103
104    /**
105     * Get the serialized form summaries header.
106     *
107     * @return the serialized form summary header tree
108     */
109    public Content getSerializedSummariesHeader() {
110        HtmlTree ul = new HtmlTree(HtmlTag.UL);
111        ul.addStyle(HtmlStyle.blockList);
112        return ul;
113    }
114
115    /**
116     * Get the package serialized form header.
117     *
118     * @return the package serialized form header tree
119     */
120    public Content getPackageSerializedHeader() {
121        HtmlTree htmlTree;
122        if (configuration.allowTag(HtmlTag.SECTION)) {
123            htmlTree = HtmlTree.SECTION();
124        } else {
125            htmlTree = new HtmlTree(HtmlTag.LI);
126            htmlTree.addStyle(HtmlStyle.blockList);
127        }
128        return htmlTree;
129    }
130
131    /**
132     * Get the given package header.
133     *
134     * @param packageName the package header to write
135     * @return a content tree for the package header
136     */
137    public Content getPackageHeader(String packageName) {
138        Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
139                packageLabel);
140        heading.addContent(getSpace());
141        heading.addContent(packageName);
142        return heading;
143    }
144
145    /**
146     * Get the serialized class header.
147     *
148     * @return a content tree for the serialized class header
149     */
150    public Content getClassSerializedHeader() {
151        HtmlTree ul = new HtmlTree(HtmlTag.UL);
152        ul.addStyle(HtmlStyle.blockList);
153        return ul;
154    }
155
156    /**
157     * Checks if a class is generated and is visible.
158     *
159     * @param typeElement the class being processed.
160     * @return true if the class, that is being processed, is generated and is visible.
161     */
162    public boolean isVisibleClass(TypeElement typeElement) {
163        return visibleClasses.contains(typeElement) && configuration.isGeneratedDoc(typeElement);
164    }
165
166    /**
167     * Get the serializable class heading.
168     *
169     * @param typeElement the class being processed
170     * @return a content tree for the class header
171     */
172    public Content getClassHeader(TypeElement typeElement) {
173        Content classLink = (isVisibleClass(typeElement))
174                ? getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, typeElement)
175                        .label(configuration.getClassName(typeElement)))
176                : new StringContent(utils.getFullyQualifiedName(typeElement));
177        Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
178                utils.getFullyQualifiedName(typeElement)));
179        Content superClassLink = typeElement.getSuperclass() != null
180                ? getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.SERIALIZED_FORM,
181                        typeElement.getSuperclass()))
182                : null;
183
184        //Print the heading.
185        Content className = superClassLink == null ?
186            configuration.getResource(
187            "doclet.Class_0_implements_serializable", classLink) :
188            configuration.getResource(
189            "doclet.Class_0_extends_implements_serializable", classLink,
190            superClassLink);
191        li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
192                className));
193        return li;
194    }
195
196    /**
197     * Get the serial UID info header.
198     *
199     * @return a content tree for the serial uid info header
200     */
201    public Content getSerialUIDInfoHeader() {
202        HtmlTree dl = new HtmlTree(HtmlTag.DL);
203        dl.addStyle(HtmlStyle.nameValue);
204        return dl;
205    }
206
207    /**
208     * Adds the serial UID info.
209     *
210     * @param header the header that will show up before the UID.
211     * @param serialUID the serial UID to print.
212     * @param serialUidTree the serial UID content tree to which the serial UID
213     *                      content will be added
214     */
215    public void addSerialUIDInfo(String header, String serialUID,
216            Content serialUidTree) {
217        Content headerContent = new StringContent(header);
218        serialUidTree.addContent(HtmlTree.DT(headerContent));
219        Content serialContent = new StringContent(serialUID);
220        serialUidTree.addContent(HtmlTree.DD(serialContent));
221    }
222
223    /**
224     * Get the class serialize content header.
225     *
226     * @return a content tree for the class serialize content header
227     */
228    public Content getClassContentHeader() {
229        HtmlTree ul = new HtmlTree(HtmlTag.UL);
230        ul.addStyle(HtmlStyle.blockList);
231        return ul;
232    }
233
234    /**
235     * Get the serialized content tree section.
236     *
237     * @param serializedTreeContent the serialized content tree to be added
238     * @return a div content tree
239     */
240    public Content getSerializedContent(Content serializedTreeContent) {
241        HtmlTree divContent = HtmlTree.DIV(HtmlStyle.serializedFormContainer,
242                serializedTreeContent);
243        if (configuration.allowTag(HtmlTag.MAIN)) {
244            mainTree.addContent(divContent);
245            return mainTree;
246        } else {
247            return divContent;
248        }
249    }
250
251    /**
252     * {@inheritDoc}
253     */
254    public void addPackageSerializedTree(Content serializedSummariesTree,
255            Content packageSerializedTree) {
256        serializedSummariesTree.addContent((configuration.allowTag(HtmlTag.SECTION))
257                ? HtmlTree.LI(HtmlStyle.blockList, packageSerializedTree)
258                : packageSerializedTree);
259    }
260
261    /**
262     * Add the footer.
263     *
264     * @param serializedTree the serialized tree to be added
265     */
266    public void addFooter(Content serializedTree) {
267        Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
268                ? HtmlTree.FOOTER()
269                : serializedTree;
270        addNavLinks(false, htmlTree);
271        addBottom(htmlTree);
272        if (configuration.allowTag(HtmlTag.FOOTER)) {
273            serializedTree.addContent(htmlTree);
274        }
275    }
276
277    /**
278     * {@inheritDoc}
279     */
280    public void printDocument(Content serializedTree) throws IOException {
281        printHtmlDocument(null, true, serializedTree);
282    }
283
284    /**
285     * Return an instance of a SerialFieldWriter.
286     *
287     * @return an instance of a SerialFieldWriter.
288     */
289    public SerialFieldWriter getSerialFieldWriter(TypeElement typeElement) {
290        return new HtmlSerialFieldWriter(this, typeElement);
291    }
292
293    /**
294     * Return an instance of a SerialMethodWriter.
295     *
296     * @return an instance of a SerialMethodWriter.
297     */
298    public SerialMethodWriter getSerialMethodWriter(TypeElement typeElement) {
299        return new HtmlSerialMethodWriter(this, typeElement);
300    }
301}
302