1 /* 2 * Copyright (c) 1997, 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 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.*; 33 34 /** 35 * Generate File to list all the deprecated classes and class members with the 36 * appropriate links. 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 * @see java.util.List 44 * @author Atul M Dambalkar 45 * @author Bhavesh Patel (Modified) 46 */ 47 public class DeprecatedListWriter extends SubWriterHolderWriter { 48 49 private static final String[] ANCHORS = new String[] { 50 "package", "interface", "class", "enum", "exception", "error", 51 "annotation.type", "field", "method", "constructor", "enum.constant", 52 "annotation.type.member" 53 }; 54 55 private static final String[] HEADING_KEYS = new String[] { 56 "doclet.Deprecated_Packages", "doclet.Deprecated_Interfaces", 57 "doclet.Deprecated_Classes", "doclet.Deprecated_Enums", 58 "doclet.Deprecated_Exceptions", "doclet.Deprecated_Errors", 59 "doclet.Deprecated_Annotation_Types", 60 "doclet.Deprecated_Fields", 61 "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors", 62 "doclet.Deprecated_Enum_Constants", 63 "doclet.Deprecated_Annotation_Type_Members" 64 }; 65 66 private static final String[] SUMMARY_KEYS = new String[] { 67 "doclet.deprecated_packages", "doclet.deprecated_interfaces", 68 "doclet.deprecated_classes", "doclet.deprecated_enums", 69 "doclet.deprecated_exceptions", "doclet.deprecated_errors", 70 "doclet.deprecated_annotation_types", 71 "doclet.deprecated_fields", 72 "doclet.deprecated_methods", "doclet.deprecated_constructors", 73 "doclet.deprecated_enum_constants", 74 "doclet.deprecated_annotation_type_members" 75 }; 76 77 private static final String[] HEADER_KEYS = new String[] { 78 "doclet.Package", "doclet.Interface", "doclet.Class", 79 "doclet.Enum", "doclet.Exceptions", 80 "doclet.Errors", 81 "doclet.AnnotationType", 82 "doclet.Field", 83 "doclet.Method", "doclet.Constructor", 84 "doclet.Enum_Constant", 85 "doclet.Annotation_Type_Member" 86 }; 87 88 private AbstractMemberWriter[] writers; 89 90 private ConfigurationImpl configuration; 91 92 /** 93 * Constructor. 94 * 95 * @param filename the file to be generated. 96 */ 97 public DeprecatedListWriter(ConfigurationImpl configuration, 98 DocPath filename) throws IOException { 99 super(configuration, filename); 100 this.configuration = configuration; 101 NestedClassWriterImpl classW = new NestedClassWriterImpl(this); 102 writers = new AbstractMemberWriter[] 103 {classW, classW, classW, classW, classW, classW, 104 new FieldWriterImpl(this), 105 new MethodWriterImpl(this), 106 new ConstructorWriterImpl(this), 107 new EnumConstantWriterImpl(this), 108 new AnnotationTypeOptionalMemberWriterImpl(this, null)}; 109 } 110 111 /** 112 * Get list of all the deprecated classes and members in all the Packages 113 * specified on the Command Line. 114 * Then instantiate DeprecatedListWriter and generate File. 115 * 116 * @param configuration the current configuration of the doclet. 117 */ 118 public static void generate(ConfigurationImpl configuration) { 119 DocPath filename = DocPaths.DEPRECATED_LIST; 120 try { 121 DeprecatedListWriter depr = 122 new DeprecatedListWriter(configuration, filename); 123 depr.generateDeprecatedListFile( 124 new DeprecatedAPIListBuilder(configuration)); 125 depr.close(); 126 } catch (IOException exc) { 127 configuration.standardmessage.error( 128 "doclet.exception_encountered", 129 exc.toString(), filename); 130 throw new DocletAbortException(exc); 131 } 132 } 133 134 /** 135 * Generate the deprecated API list. 136 * 137 * @param deprapi list of deprecated API built already. 138 */ 139 protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) 140 throws IOException { 141 HtmlTree body = getHeader(); 142 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 143 ? HtmlTree.MAIN() 144 : body; 145 htmlTree.addContent(getContentsList(deprapi)); 146 String memberTableSummary; 147 String[] memberTableHeader = new String[1]; 148 HtmlTree div = new HtmlTree(HtmlTag.DIV); 149 div.addStyle(HtmlStyle.contentContainer); 150 for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { 151 if (deprapi.hasDocumentation(i)) { 152 addAnchor(deprapi, i, div); 153 memberTableSummary = 154 configuration.getText("doclet.Member_Table_Summary", 155 configuration.getText(HEADING_KEYS[i]), 156 configuration.getText(SUMMARY_KEYS[i])); 157 memberTableHeader[0] = configuration.getText("doclet.0_and_1", 158 configuration.getText(HEADER_KEYS[i]), 159 configuration.getText("doclet.Description")); 160 // DeprecatedAPIListBuilder.PACKAGE == 0, so if i == 0, it is 161 // a PackageDoc. 162 if (i == DeprecatedAPIListBuilder.PACKAGE) 163 addPackageDeprecatedAPI(deprapi.getList(i), 164 HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); 165 else 166 writers[i - 1].addDeprecatedAPI(deprapi.getList(i), 167 HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); 168 } 169 } 170 if (configuration.allowTag(HtmlTag.MAIN)) { 171 htmlTree.addContent(div); 172 body.addContent(htmlTree); 173 } else { 174 body.addContent(div); 175 } 176 htmlTree = (configuration.allowTag(HtmlTag.FOOTER)) 177 ? HtmlTree.FOOTER() 178 : body; 179 addNavLinks(false, htmlTree); 180 addBottom(htmlTree); 181 if (configuration.allowTag(HtmlTag.FOOTER)) { 182 body.addContent(htmlTree); 183 } 184 printHtmlDocument(null, true, body); 185 } 186 187 /** 188 * Add the index link. 189 * 190 * @param builder the deprecated list builder 191 * @param type the type of list being documented 192 * @param contentTree the content tree to which the index link will be added 193 */ 194 private void addIndexLink(DeprecatedAPIListBuilder builder, 195 int type, Content contentTree) { 196 if (builder.hasDocumentation(type)) { 197 Content li = HtmlTree.LI(getHyperLink(ANCHORS[type], 198 getResource(HEADING_KEYS[type]))); 199 contentTree.addContent(li); 200 } 201 } 202 203 /** 204 * Get the contents list. 205 * 206 * @param deprapi the deprecated list builder 207 * @return a content tree for the contents list 208 */ 209 public Content getContentsList(DeprecatedAPIListBuilder deprapi) { 210 Content headContent = getResource("doclet.Deprecated_API"); 211 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 212 HtmlStyle.title, headContent); 213 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 214 Content headingContent = getResource("doclet.Contents"); 215 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, 216 headingContent)); 217 Content ul = new HtmlTree(HtmlTag.UL); 218 for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { 219 addIndexLink(deprapi, i, ul); 220 } 221 div.addContent(ul); 222 return div; 223 } 224 225 /** 226 * Add the anchor. 227 * 228 * @param builder the deprecated list builder 229 * @param type the type of list being documented 230 * @param htmlTree the content tree to which the anchor will be added 231 */ 232 private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) { 233 if (builder.hasDocumentation(type)) { 234 htmlTree.addContent(getMarkerAnchor(ANCHORS[type])); 235 } 236 } 237 238 /** 239 * Get the header for the deprecated API Listing. 240 * 241 * @return a content tree for the header 242 */ 243 public HtmlTree getHeader() { 244 String title = configuration.getText("doclet.Window_Deprecated_List"); 245 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 246 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 247 ? HtmlTree.HEADER() 248 : bodyTree; 249 addTop(htmlTree); 250 addNavLinks(true, htmlTree); 251 if (configuration.allowTag(HtmlTag.HEADER)) { 252 bodyTree.addContent(htmlTree); 253 } 254 return bodyTree; 255 } 256 257 /** 258 * Get the deprecated label. 259 * 260 * @return a content tree for the deprecated label 261 */ 262 protected Content getNavLinkDeprecated() { 263 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, deprecatedLabel); 264 return li; 265 } 266 }