1 /* 2 * Copyright (c) 1998, 2019, 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 jdk.javadoc.internal.doclets.formats.html; 27 28 import java.util.Set; 29 30 import javax.lang.model.element.TypeElement; 31 32 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; 33 import jdk.javadoc.internal.doclets.formats.html.markup.Entity; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation; 38 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode; 39 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 40 import jdk.javadoc.internal.doclets.toolkit.Content; 41 import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 43 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 44 45 /** 46 * Generates the Serialized Form Information Page, <i>serialized-form.html</i>. 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 public class SerializedFormWriterImpl extends SubWriterHolderWriter 54 implements SerializedFormWriter { 55 56 Set<TypeElement> visibleClasses; 57 58 private final Navigation navBar; 59 60 /** 61 * @param configuration the configuration data for the doclet 62 */ 63 public SerializedFormWriterImpl(HtmlConfiguration configuration) { 64 super(configuration, DocPaths.SERIALIZED_FORM); 65 visibleClasses = configuration.getIncludedTypeElements(); 66 this.navBar = new Navigation(null, configuration, PageMode.SERIALIZEDFORM, path); 67 } 68 69 /** 70 * Get the given header. 71 * 72 * @param header the header to write 73 * @return the body content tree 74 */ 75 public Content getHeader(String header) { 76 HtmlTree bodyTree = getBody(getWindowTitle(header)); 77 Content headerContent = new ContentBuilder(); 78 addTop(headerContent); 79 navBar.setUserHeader(getUserHeaderFooter(true)); 80 headerContent.add(navBar.getContent(true)); 81 Content h1Content = new StringContent(header); 82 Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, true, 83 HtmlStyle.title, h1Content); 84 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 85 bodyContents.setHeader(headerContent) 86 .addMainContent(div); 87 return bodyTree; 88 } 89 90 /** 91 * Get the serialized form summaries header. 92 * 93 * @return the serialized form summary header tree 94 */ 95 public Content getSerializedSummariesHeader() { 96 HtmlTree ul = new HtmlTree(HtmlTag.UL); 97 ul.setStyle(HtmlStyle.blockList); 98 return ul; 99 } 100 101 /** 102 * Get the package serialized form header. 103 * 104 * @return the package serialized form header tree 105 */ 106 public Content getPackageSerializedHeader() { 107 return HtmlTree.SECTION(HtmlStyle.serializedPackageContainer); 108 } 109 110 /** 111 * Get the given package header. 112 * 113 * @param packageName the package header to write 114 * @return a content tree for the package header 115 */ 116 public Content getPackageHeader(String packageName) { 117 Content heading = HtmlTree.HEADING(Headings.SerializedForm.PACKAGE_HEADING, true, 118 contents.packageLabel); 119 heading.add(Entity.NO_BREAK_SPACE); 120 heading.add(packageName); 121 return heading; 122 } 123 124 /** 125 * Get the serialized class header. 126 * 127 * @return a content tree for the serialized class header 128 */ 129 public Content getClassSerializedHeader() { 130 HtmlTree ul = new HtmlTree(HtmlTag.UL); 131 ul.setStyle(HtmlStyle.blockList); 132 return ul; 133 } 134 135 /** 136 * Checks if a class is generated and is visible. 137 * 138 * @param typeElement the class being processed. 139 * @return true if the class, that is being processed, is generated and is visible. 140 */ 141 public boolean isVisibleClass(TypeElement typeElement) { 142 return visibleClasses.contains(typeElement) && configuration.isGeneratedDoc(typeElement); 143 } 144 145 /** 146 * Get the serializable class heading. 147 * 148 * @param typeElement the class being processed 149 * @return a content tree for the class header 150 */ 151 public Content getClassHeader(TypeElement typeElement) { 152 Content classLink = (isVisibleClass(typeElement)) 153 ? getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, typeElement) 154 .label(configuration.getClassName(typeElement))) 155 : new StringContent(utils.getFullyQualifiedName(typeElement)); 156 Content section = HtmlTree.SECTION(HtmlStyle.serializedClassDetails, links.createAnchor( 157 utils.getFullyQualifiedName(typeElement))); 158 Content superClassLink = typeElement.getSuperclass() != null 159 ? getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.SERIALIZED_FORM, 160 typeElement.getSuperclass())) 161 : null; 162 163 //Print the heading. 164 Content className = superClassLink == null ? 165 contents.getContent( 166 "doclet.Class_0_implements_serializable", classLink) : 167 contents.getContent( 168 "doclet.Class_0_extends_implements_serializable", classLink, 169 superClassLink); 170 section.add(HtmlTree.HEADING(Headings.SerializedForm.CLASS_HEADING, className)); 171 return section; 172 } 173 174 /** 175 * Get the serial UID info header. 176 * 177 * @return a content tree for the serial uid info header 178 */ 179 public Content getSerialUIDInfoHeader() { 180 HtmlTree dl = new HtmlTree(HtmlTag.DL); 181 dl.setStyle(HtmlStyle.nameValue); 182 return dl; 183 } 184 185 /** 186 * Adds the serial UID info. 187 * 188 * @param header the header that will show up before the UID. 189 * @param serialUID the serial UID to print. 190 * @param serialUidTree the serial UID content tree to which the serial UID 191 * content will be added 192 */ 193 public void addSerialUIDInfo(String header, String serialUID, 194 Content serialUidTree) { 195 Content headerContent = new StringContent(header); 196 serialUidTree.add(HtmlTree.DT(headerContent)); 197 Content serialContent = new StringContent(serialUID); 198 serialUidTree.add(HtmlTree.DD(serialContent)); 199 } 200 201 /** 202 * Get the class serialize content header. 203 * 204 * @return a content tree for the class serialize content header 205 */ 206 public Content getClassContentHeader() { 207 HtmlTree ul = new HtmlTree(HtmlTag.UL); 208 ul.setStyle(HtmlStyle.blockList); 209 return ul; 210 } 211 212 /** 213 * Add the serialized content tree section. 214 * 215 * @param serializedTreeContent the serialized content tree to be added 216 */ 217 public void addSerializedContent(Content serializedTreeContent) { 218 HtmlTree divContent = HtmlTree.DIV(HtmlStyle.serializedFormContainer, 219 serializedTreeContent); 220 bodyContents.addMainContent(divContent); 221 } 222 223 /** 224 * {@inheritDoc} 225 */ 226 public void addPackageSerializedTree(Content serializedSummariesTree, 227 Content packageSerializedTree) { 228 serializedSummariesTree.add(HtmlTree.LI(HtmlStyle.blockList, packageSerializedTree)); 229 } 230 231 /** 232 * Add the footer. 233 */ 234 public void addFooter() { 235 Content htmlTree = HtmlTree.FOOTER(); 236 navBar.setUserFooter(getUserHeaderFooter(false)); 237 htmlTree.add(navBar.getContent(false)); 238 addBottom(htmlTree); 239 bodyContents.setFooter(htmlTree); 240 } 241 242 /** 243 * {@inheritDoc} 244 */ 245 @Override 246 public void printDocument(Content serializedTree) throws DocFileIOException { 247 serializedTree.add(bodyContents.toContent()); 248 printHtmlDocument(null, "serialized forms", serializedTree); 249 } 250 251 /** 252 * Return an instance of a SerialFieldWriter. 253 * 254 * @return an instance of a SerialFieldWriter. 255 */ 256 public SerialFieldWriter getSerialFieldWriter(TypeElement typeElement) { 257 return new HtmlSerialFieldWriter(this, typeElement); 258 } 259 260 /** 261 * Return an instance of a SerialMethodWriter. 262 * 263 * @return an instance of a SerialMethodWriter. 264 */ 265 public SerialMethodWriter getSerialMethodWriter(TypeElement typeElement) { 266 return new HtmlSerialMethodWriter(this, typeElement); 267 } 268 }