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