duke@1: /* jjg@1357: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@766: import java.io.*; jjg@1357: jjg@1357: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Generate File to list all the deprecated classes and class members with the duke@1: * appropriate links. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @see java.util.List duke@1: * @author Atul M Dambalkar bpatel@243: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class DeprecatedListWriter extends SubWriterHolderWriter { duke@1: duke@1: private static final String[] ANCHORS = new String[] { bpatel@995: "package", "interface", "class", "enum", "exception", "error", bpatel@995: "annotation_type", "field", "method", "constructor", "enum_constant", duke@1: "annotation_type_member" duke@1: }; duke@1: duke@1: private static final String[] HEADING_KEYS = new String[] { bpatel@995: "doclet.Deprecated_Packages", "doclet.Deprecated_Interfaces", bpatel@995: "doclet.Deprecated_Classes", "doclet.Deprecated_Enums", bpatel@995: "doclet.Deprecated_Exceptions", "doclet.Deprecated_Errors", duke@1: "doclet.Deprecated_Annotation_Types", duke@1: "doclet.Deprecated_Fields", duke@1: "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors", duke@1: "doclet.Deprecated_Enum_Constants", duke@1: "doclet.Deprecated_Annotation_Type_Members" duke@1: }; duke@1: bpatel@243: private static final String[] SUMMARY_KEYS = new String[] { bpatel@995: "doclet.deprecated_packages", "doclet.deprecated_interfaces", bpatel@995: "doclet.deprecated_classes", "doclet.deprecated_enums", bpatel@995: "doclet.deprecated_exceptions", "doclet.deprecated_errors", bpatel@243: "doclet.deprecated_annotation_types", bpatel@243: "doclet.deprecated_fields", bpatel@243: "doclet.deprecated_methods", "doclet.deprecated_constructors", bpatel@243: "doclet.deprecated_enum_constants", bpatel@243: "doclet.deprecated_annotation_type_members" bpatel@243: }; bpatel@243: bpatel@243: private static final String[] HEADER_KEYS = new String[] { bpatel@995: "doclet.Package", "doclet.Interface", "doclet.Class", bpatel@243: "doclet.Enum", "doclet.Exceptions", bpatel@243: "doclet.Errors", bpatel@243: "doclet.AnnotationType", bpatel@243: "doclet.Field", bpatel@243: "doclet.Method", "doclet.Constructor", bpatel@243: "doclet.Enum_Constant", bpatel@243: "doclet.Annotation_Type_Member" bpatel@243: }; bpatel@243: duke@1: private AbstractMemberWriter[] writers; duke@1: duke@1: private ConfigurationImpl configuration; duke@1: duke@1: /** duke@1: * Constructor. duke@1: * duke@1: * @param filename the file to be generated. duke@1: */ duke@1: public DeprecatedListWriter(ConfigurationImpl configuration, duke@1: String filename) throws IOException { duke@1: super(configuration, filename); duke@1: this.configuration = configuration; duke@1: NestedClassWriterImpl classW = new NestedClassWriterImpl(this); duke@1: writers = new AbstractMemberWriter[] duke@1: {classW, classW, classW, classW, classW, classW, duke@1: new FieldWriterImpl(this), duke@1: new MethodWriterImpl(this), duke@1: new ConstructorWriterImpl(this), duke@1: new EnumConstantWriterImpl(this), duke@1: new AnnotationTypeOptionalMemberWriterImpl(this, null)}; duke@1: } duke@1: duke@1: /** duke@1: * Get list of all the deprecated classes and members in all the Packages duke@1: * specified on the Command Line. duke@1: * Then instantiate DeprecatedListWriter and generate File. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: */ duke@1: public static void generate(ConfigurationImpl configuration) { duke@1: String filename = "deprecated-list.html"; duke@1: try { duke@1: DeprecatedListWriter depr = duke@1: new DeprecatedListWriter(configuration, filename); duke@1: depr.generateDeprecatedListFile( bpatel@995: new DeprecatedAPIListBuilder(configuration)); duke@1: depr.close(); duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( duke@1: "doclet.exception_encountered", duke@1: exc.toString(), filename); duke@1: throw new DocletAbortException(); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Generate the deprecated API list. duke@1: * duke@1: * @param deprapi list of deprecated API built already. duke@1: */ duke@1: protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) bpatel@766: throws IOException { bpatel@766: Content body = getHeader(); bpatel@766: body.addContent(getContentsList(deprapi)); bpatel@243: String memberTableSummary; bpatel@243: String[] memberTableHeader = new String[1]; bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.contentContainer); duke@1: for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { duke@1: if (deprapi.hasDocumentation(i)) { bpatel@766: addAnchor(deprapi, i, div); bpatel@243: memberTableSummary = bpatel@243: configuration.getText("doclet.Member_Table_Summary", bpatel@243: configuration.getText(HEADING_KEYS[i]), bpatel@243: configuration.getText(SUMMARY_KEYS[i])); bpatel@243: memberTableHeader[0] = configuration.getText("doclet.0_and_1", bpatel@243: configuration.getText(HEADER_KEYS[i]), bpatel@243: configuration.getText("doclet.Description")); bpatel@995: // DeprecatedAPIListBuilder.PACKAGE == 0, so if i == 0, it is bpatel@995: // a PackageDoc. bpatel@995: if (i == DeprecatedAPIListBuilder.PACKAGE) bpatel@995: addPackageDeprecatedAPI(deprapi.getList(i), bpatel@995: HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); bpatel@995: else bpatel@995: writers[i - 1].addDeprecatedAPI(deprapi.getList(i), bpatel@995: HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); duke@1: } duke@1: } bpatel@766: body.addContent(div); bpatel@766: addNavLinks(false, body); bpatel@766: addBottom(body); bpatel@766: printHtmlDocument(null, true, body); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add the index link. bpatel@766: * bpatel@766: * @param builder the deprecated list builder bpatel@766: * @param type the type of list being documented bpatel@766: * @param contentTree the content tree to which the index link will be added bpatel@766: */ bpatel@766: private void addIndexLink(DeprecatedAPIListBuilder builder, bpatel@766: int type, Content contentTree) { duke@1: if (builder.hasDocumentation(type)) { bpatel@766: Content li = HtmlTree.LI(getHyperLink("#" + ANCHORS[type], bpatel@766: getResource(HEADING_KEYS[type]))); bpatel@766: contentTree.addContent(li); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get the contents list. bpatel@766: * bpatel@766: * @param deprapi the deprecated list builder bpatel@766: * @return a content tree for the contents list duke@1: */ bpatel@766: public Content getContentsList(DeprecatedAPIListBuilder deprapi) { bpatel@766: Content headContent = getResource("doclet.Deprecated_API"); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, bpatel@766: HtmlStyle.title, headContent); bpatel@766: Content div = HtmlTree.DIV(HtmlStyle.header, heading); bpatel@766: Content headingContent = getResource("doclet.Contents"); bpatel@766: div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, bpatel@766: headingContent)); bpatel@766: Content ul = new HtmlTree(HtmlTag.UL); bpatel@766: for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { bpatel@766: addIndexLink(deprapi, i, ul); bpatel@766: } bpatel@766: div.addContent(ul); bpatel@766: return div; duke@1: } duke@1: duke@1: /** bpatel@766: * Add the anchor. bpatel@766: * bpatel@766: * @param builder the deprecated list builder bpatel@766: * @param type the type of list being documented jjg@1358: * @param htmlTree the content tree to which the anchor will be added duke@1: */ bpatel@766: private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) { bpatel@766: if (builder.hasDocumentation(type)) { bpatel@766: htmlTree.addContent(getMarkerAnchor(ANCHORS[type])); bpatel@766: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get the header for the deprecated API Listing. bpatel@766: * bpatel@766: * @return a content tree for the header duke@1: */ bpatel@766: public Content getHeader() { bpatel@766: String title = configuration.getText("doclet.Window_Deprecated_List"); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(title)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: return bodyTree; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the deprecated label. bpatel@766: * bpatel@766: * @return a content tree for the deprecated label bpatel@766: */ bpatel@766: protected Content getNavLinkDeprecated() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, deprecatedLabel); bpatel@766: return li; duke@1: } duke@1: }