1 /* 2 * Copyright (c) 1998, 2018, 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.*; 29 30 import javax.lang.model.element.TypeElement; 31 32 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 36 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation; 37 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode; 38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 39 import jdk.javadoc.internal.doclets.toolkit.Content; 40 import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; 41 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 43 44 /** 45 * Generate the Serialized Form Information Page. 46 * 47 * <p><b>This is NOT part of any supported API. 48 * If you write code that depends on this, you do so at your own risk. 49 * This code and its internal interfaces are subject to change or 50 * deletion without notice.</b> 51 * 52 * @author Atul M Dambalkar 53 */ 54 public class SerializedFormWriterImpl extends SubWriterHolderWriter 55 implements SerializedFormWriter { 56 57 Set<TypeElement> visibleClasses; 58 59 /** 60 * HTML tree for main tag. 61 */ 62 private HtmlTree mainTree = HtmlTree.MAIN(); 63 64 private final Navigation navBar; 65 66 /** 67 * @param configuration the configuration data for the doclet 68 */ SerializedFormWriterImpl(HtmlConfiguration configuration)69 public SerializedFormWriterImpl(HtmlConfiguration configuration) { 70 super(configuration, DocPaths.SERIALIZED_FORM); 71 visibleClasses = configuration.getIncludedTypeElements(); 72 this.navBar = new Navigation(null, configuration, fixedNavDiv, PageMode.SERIALIZEDFORM, path); 73 } 74 75 /** 76 * Get the given header. 77 * 78 * @param header the header to write 79 * @return the body content tree 80 */ getHeader(String header)81 public Content getHeader(String header) { 82 HtmlTree bodyTree = getBody(true, getWindowTitle(header)); 83 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 84 ? HtmlTree.HEADER() 85 : bodyTree; 86 addTop(htmlTree); 87 navBar.setUserHeader(getUserHeaderFooter(true)); 88 htmlTree.addContent(navBar.getContent(true)); 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 */ getSerializedSummariesHeader()109 public Content getSerializedSummariesHeader() { 110 HtmlTree ul = new HtmlTree(HtmlTag.UL); 111 ul.setStyle(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 */ getPackageSerializedHeader()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.setStyle(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 */ getPackageHeader(String packageName)137 public Content getPackageHeader(String packageName) { 138 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 139 contents.packageLabel); 140 heading.addContent(Contents.SPACE); 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 */ getClassSerializedHeader()150 public Content getClassSerializedHeader() { 151 HtmlTree ul = new HtmlTree(HtmlTag.UL); 152 ul.setStyle(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 */ isVisibleClass(TypeElement typeElement)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 */ getClassHeader(TypeElement typeElement)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, links.createAnchor( 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 contents.getContent( 187 "doclet.Class_0_implements_serializable", classLink) : 188 contents.getContent( 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 */ getSerialUIDInfoHeader()201 public Content getSerialUIDInfoHeader() { 202 HtmlTree dl = new HtmlTree(HtmlTag.DL); 203 dl.setStyle(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 */ addSerialUIDInfo(String header, String serialUID, Content serialUidTree)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 */ getClassContentHeader()228 public Content getClassContentHeader() { 229 HtmlTree ul = new HtmlTree(HtmlTag.UL); 230 ul.setStyle(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 */ getSerializedContent(Content serializedTreeContent)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 */ addPackageSerializedTree(Content serializedSummariesTree, Content packageSerializedTree)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 */ addFooter(Content serializedTree)266 public void addFooter(Content serializedTree) { 267 Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER)) 268 ? HtmlTree.FOOTER() 269 : serializedTree; 270 navBar.setUserFooter(getUserHeaderFooter(false)); 271 htmlTree.addContent(navBar.getContent(false)); 272 addBottom(htmlTree); 273 if (configuration.allowTag(HtmlTag.FOOTER)) { 274 serializedTree.addContent(htmlTree); 275 } 276 } 277 278 /** 279 * {@inheritDoc} 280 */ 281 @Override printDocument(Content serializedTree)282 public void printDocument(Content serializedTree) throws DocFileIOException { 283 printHtmlDocument(null, true, serializedTree); 284 } 285 286 /** 287 * Return an instance of a SerialFieldWriter. 288 * 289 * @return an instance of a SerialFieldWriter. 290 */ getSerialFieldWriter(TypeElement typeElement)291 public SerialFieldWriter getSerialFieldWriter(TypeElement typeElement) { 292 return new HtmlSerialFieldWriter(this, typeElement); 293 } 294 295 /** 296 * Return an instance of a SerialMethodWriter. 297 * 298 * @return an instance of a SerialMethodWriter. 299 */ getSerialMethodWriter(TypeElement typeElement)300 public SerialMethodWriter getSerialMethodWriter(TypeElement typeElement) { 301 return new HtmlSerialMethodWriter(this, typeElement); 302 } 303 } 304