src/share/classes/com/sun/tools/doclets/formats/html/DeprecatedListWriter.java

Fri, 04 Mar 2011 19:53:03 -0800

author
jjg
date
Fri, 04 Mar 2011 19:53:03 -0800
changeset 910
ebf7c13df6c0
parent 798
4868a36f6fd8
child 995
62bc3775d5bb
permissions
-rw-r--r--

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
Reviewed-by: bpatel

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

mercurial