View Javadoc
1   /*
2    * Copyright (c) 1998, 2013, 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  
26  package com.sun.tools.doclets.formats.html;
27  
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;
34  
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 {
47  
48      /**
49       * @param configuration the configuration data for the doclet
50       * @throws IOException
51       * @throws DocletAbortException
52       */
53      public SerializedFormWriterImpl(ConfigurationImpl configuration)
54              throws IOException {
55          super(configuration, DocPaths.SERIALIZED_FORM);
56      }
57  
58      /**
59       * Get the given header.
60       *
61       * @param header the header to write
62       * @return the body content tree
63       */
64      public Content getHeader(String header) {
65          Content bodyTree = getBody(true, getWindowTitle(header));
66          addTop(bodyTree);
67          addNavLinks(true, bodyTree);
68          Content h1Content = new StringContent(header);
69          Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
70                  HtmlStyle.title, h1Content);
71          Content div = HtmlTree.DIV(HtmlStyle.header, heading);
72          bodyTree.addContent(div);
73          return bodyTree;
74      }
75  
76      /**
77       * Get the serialized form summaries header.
78       *
79       * @return the serialized form summary header tree
80       */
81      public Content getSerializedSummariesHeader() {
82          HtmlTree ul = new HtmlTree(HtmlTag.UL);
83          ul.addStyle(HtmlStyle.blockList);
84          return ul;
85      }
86  
87      /**
88       * Get the package serialized form header.
89       *
90       * @return the package serialized form header tree
91       */
92      public Content getPackageSerializedHeader() {
93          HtmlTree li = new HtmlTree(HtmlTag.LI);
94          li.addStyle(HtmlStyle.blockList);
95          return li;
96      }
97  
98      /**
99       * Get the given package header.
100      *
101      * @param packageName the package header to write
102      * @return a content tree for the package header
103      */
104     public Content getPackageHeader(String packageName) {
105         Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
106                 packageLabel);
107         heading.addContent(getSpace());
108         heading.addContent(packageName);
109         return heading;
110     }
111 
112     /**
113      * Get the serialized class header.
114      *
115      * @return a content tree for the serialized class header
116      */
117     public Content getClassSerializedHeader() {
118         HtmlTree ul = new HtmlTree(HtmlTag.UL);
119         ul.addStyle(HtmlStyle.blockList);
120         return ul;
121     }
122 
123     /**
124      * Get the serializable class heading.
125      *
126      * @param classDoc the class being processed
127      * @return a content tree for the class header
128      */
129     public Content getClassHeader(ClassDoc classDoc) {
130         Content classLink = (classDoc.isPublic() || classDoc.isProtected()) ?
131             getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, classDoc)
132             .label(configuration.getClassName(classDoc))) :
133             new StringContent(classDoc.qualifiedName());
134         Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
135                 classDoc.qualifiedName()));
136         Content superClassLink =
137             classDoc.superclassType() != null ?
138                 getLink(new LinkInfoImpl(configuration,
139                         LinkInfoImpl.Kind.SERIALIZED_FORM,
140                         classDoc.superclassType())) :
141                 null;
142 
143         //Print the heading.
144         Content className = superClassLink == null ?
145             configuration.getResource(
146             "doclet.Class_0_implements_serializable", classLink) :
147             configuration.getResource(
148             "doclet.Class_0_extends_implements_serializable", classLink,
149             superClassLink);
150         li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
151                 className));
152         return li;
153     }
154 
155     /**
156      * Get the serial UID info header.
157      *
158      * @return a content tree for the serial uid info header
159      */
160     public Content getSerialUIDInfoHeader() {
161         HtmlTree dl = new HtmlTree(HtmlTag.DL);
162         dl.addStyle(HtmlStyle.nameValue);
163         return dl;
164     }
165 
166     /**
167      * Adds the serial UID info.
168      *
169      * @param header the header that will show up before the UID.
170      * @param serialUID the serial UID to print.
171      * @param serialUidTree the serial UID content tree to which the serial UID
172      *                      content will be added
173      */
174     public void addSerialUIDInfo(String header, String serialUID,
175             Content serialUidTree) {
176         Content headerContent = new StringContent(header);
177         serialUidTree.addContent(HtmlTree.DT(headerContent));
178         Content serialContent = new StringContent(serialUID);
179         serialUidTree.addContent(HtmlTree.DD(serialContent));
180     }
181 
182     /**
183      * Get the class serialize content header.
184      *
185      * @return a content tree for the class serialize content header
186      */
187     public Content getClassContentHeader() {
188         HtmlTree ul = new HtmlTree(HtmlTag.UL);
189         ul.addStyle(HtmlStyle.blockList);
190         return ul;
191     }
192 
193     /**
194      * Get the serialized content tree section.
195      *
196      * @param serializedTreeContent the serialized content tree to be added
197      * @return a div content tree
198      */
199     public Content getSerializedContent(Content serializedTreeContent) {
200         Content divContent = HtmlTree.DIV(HtmlStyle.serializedFormContainer,
201                 serializedTreeContent);
202         return divContent;
203     }
204 
205     /**
206      * Add the footer.
207      *
208      * @param serializedTree the serialized tree to be added
209      */
210     public void addFooter(Content serializedTree) {
211         addNavLinks(false, serializedTree);
212         addBottom(serializedTree);
213     }
214 
215     /**
216      * {@inheritDoc}
217      */
218     public void printDocument(Content serializedTree) throws IOException {
219         printHtmlDocument(null, true, serializedTree);
220     }
221 
222     /**
223      * Return an instance of a SerialFieldWriter.
224      *
225      * @return an instance of a SerialFieldWriter.
226      */
227     public SerialFieldWriter getSerialFieldWriter(ClassDoc classDoc) {
228         return new HtmlSerialFieldWriter(this, classDoc);
229     }
230 
231     /**
232      * Return an instance of a SerialMethodWriter.
233      *
234      * @return an instance of a SerialMethodWriter.
235      */
236     public SerialMethodWriter getSerialMethodWriter(ClassDoc classDoc) {
237         return new HtmlSerialMethodWriter(this, classDoc);
238     }
239 }