src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PackageSummaryBuilder.java

Wed, 10 Oct 2012 18:44:21 -0700

author
jjg
date
Wed, 10 Oct 2012 18:44:21 -0700
changeset 1362
c46e0c9940d6
parent 1359
25e14ad23cef
child 1372
78962d89f283
permissions
-rw-r--r--

8000310: Clean up use of StringBuffer in langtools
Reviewed-by: bpatel

     1 /*
     2  * Copyright (c) 2003, 2012, 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.internal.toolkit.builders;
    28 import java.io.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * Builds the summary for a given package.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  *
    42  * @author Jamie Ho
    43  * @author Bhavesh Patel (Modified)
    44  * @since 1.5
    45  */
    46 public class PackageSummaryBuilder extends AbstractBuilder {
    47     /**
    48      * The root element of the package summary XML is {@value}.
    49      */
    50     public static final String ROOT = "PackageDoc";
    52     /**
    53      * The package being documented.
    54      */
    55     private PackageDoc packageDoc;
    57     /**
    58      * The doclet specific writer that will output the result.
    59      */
    60     private PackageSummaryWriter packageWriter;
    62     /**
    63      * The content that will be added to the package summary documentation tree.
    64      */
    65     private Content contentTree;
    67     private PackageSummaryBuilder(Configuration configuration) {
    68         super(configuration);
    69     }
    71     /**
    72      * Construct a new PackageSummaryBuilder.
    73      * @param configuration the current configuration of the doclet.
    74      * @param pkg the package being documented.
    75      * @param packageWriter the doclet specific writer that will output the
    76      *        result.
    77      *
    78      * @return an instance of a PackageSummaryBuilder.
    79      */
    80     public static PackageSummaryBuilder getInstance(
    81         Configuration configuration,
    82         PackageDoc pkg,
    83         PackageSummaryWriter packageWriter) {
    84         PackageSummaryBuilder builder =
    85                 new PackageSummaryBuilder(configuration);
    86         builder.packageDoc = pkg;
    87         builder.packageWriter = packageWriter;
    88         return builder;
    89     }
    91     /**
    92      * Build the package summary.
    93      */
    94     public void build() throws IOException {
    95         if (packageWriter == null) {
    96             //Doclet does not support this output.
    97             return;
    98         }
    99         build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree);
   100     }
   102     /**
   103      * {@inheritDoc}
   104      */
   105     public String getName() {
   106         return ROOT;
   107     }
   109     /**
   110      * Build the package documentation.
   111      *
   112      * @param node the XML element that specifies which components to document
   113      * @param contentTree the content tree to which the documentation will be added
   114      */
   115     public void buildPackageDoc(XMLNode node, Content contentTree) throws Exception {
   116         contentTree = packageWriter.getPackageHeader(
   117                 Util.getPackageName(packageDoc));
   118         buildChildren(node, contentTree);
   119         packageWriter.addPackageFooter(contentTree);
   120         packageWriter.printDocument(contentTree);
   121         packageWriter.close();
   122         Util.copyDocFiles(
   123                 configuration,
   124                 Util.getPackageSourcePath(configuration, packageDoc),
   125                 DirectoryManager.getDirectoryPath(packageDoc)
   126                         + File.separator
   127                         + DocletConstants.DOC_FILES_DIR_NAME,
   128                 true);
   129     }
   131     /**
   132      * Build the content for the package doc.
   133      *
   134      * @param node the XML element that specifies which components to document
   135      * @param contentTree the content tree to which the package contents
   136      *                    will be added
   137      */
   138     public void buildContent(XMLNode node, Content contentTree) {
   139         Content packageContentTree = packageWriter.getContentHeader();
   140         buildChildren(node, packageContentTree);
   141         contentTree.addContent(packageContentTree);
   142     }
   144     /**
   145      * Build the package summary.
   146      *
   147      * @param node the XML element that specifies which components to document
   148      * @param packageContentTree the package content tree to which the summaries will
   149      *                           be added
   150      */
   151     public void buildSummary(XMLNode node, Content packageContentTree) {
   152         Content summaryContentTree = packageWriter.getSummaryHeader();
   153         buildChildren(node, summaryContentTree);
   154         packageContentTree.addContent(summaryContentTree);
   155     }
   157     /**
   158      * Build the summary for the interfaces in this package.
   159      *
   160      * @param node the XML element that specifies which components to document
   161      * @param summaryContentTree the summary tree to which the interface summary
   162      *                           will be added
   163      */
   164     public void buildInterfaceSummary(XMLNode node, Content summaryContentTree) {
   165         String interfaceTableSummary =
   166                 configuration.getText("doclet.Member_Table_Summary",
   167                 configuration.getText("doclet.Interface_Summary"),
   168                 configuration.getText("doclet.interfaces"));
   169         String[] interfaceTableHeader = new String[] {
   170             configuration.getText("doclet.Interface"),
   171             configuration.getText("doclet.Description")
   172         };
   173         ClassDoc[] interfaces =
   174                 packageDoc.isIncluded()
   175                         ? packageDoc.interfaces()
   176                         : configuration.classDocCatalog.interfaces(
   177                                 Util.getPackageName(packageDoc));
   178         if (interfaces.length > 0) {
   179             packageWriter.addClassesSummary(
   180                     interfaces,
   181                     configuration.getText("doclet.Interface_Summary"),
   182                     interfaceTableSummary, interfaceTableHeader, summaryContentTree);
   183         }
   184     }
   186     /**
   187      * Build the summary for the classes in this package.
   188      *
   189      * @param node the XML element that specifies which components to document
   190      * @param summaryContentTree the summary tree to which the class summary will
   191      *                           be added
   192      */
   193     public void buildClassSummary(XMLNode node, Content summaryContentTree) {
   194         String classTableSummary =
   195                 configuration.getText("doclet.Member_Table_Summary",
   196                 configuration.getText("doclet.Class_Summary"),
   197                 configuration.getText("doclet.classes"));
   198         String[] classTableHeader = new String[] {
   199             configuration.getText("doclet.Class"),
   200             configuration.getText("doclet.Description")
   201         };
   202         ClassDoc[] classes =
   203                 packageDoc.isIncluded()
   204                         ? packageDoc.ordinaryClasses()
   205                         : configuration.classDocCatalog.ordinaryClasses(
   206                                 Util.getPackageName(packageDoc));
   207         if (classes.length > 0) {
   208             packageWriter.addClassesSummary(
   209                     classes,
   210                     configuration.getText("doclet.Class_Summary"),
   211                     classTableSummary, classTableHeader, summaryContentTree);
   212         }
   213     }
   215     /**
   216      * Build the summary for the enums in this package.
   217      *
   218      * @param node the XML element that specifies which components to document
   219      * @param summaryContentTree the summary tree to which the enum summary will
   220      *                           be added
   221      */
   222     public void buildEnumSummary(XMLNode node, Content summaryContentTree) {
   223         String enumTableSummary =
   224                 configuration.getText("doclet.Member_Table_Summary",
   225                 configuration.getText("doclet.Enum_Summary"),
   226                 configuration.getText("doclet.enums"));
   227         String[] enumTableHeader = new String[] {
   228             configuration.getText("doclet.Enum"),
   229             configuration.getText("doclet.Description")
   230         };
   231         ClassDoc[] enums =
   232                 packageDoc.isIncluded()
   233                         ? packageDoc.enums()
   234                         : configuration.classDocCatalog.enums(
   235                                 Util.getPackageName(packageDoc));
   236         if (enums.length > 0) {
   237             packageWriter.addClassesSummary(
   238                     enums,
   239                     configuration.getText("doclet.Enum_Summary"),
   240                     enumTableSummary, enumTableHeader, summaryContentTree);
   241         }
   242     }
   244     /**
   245      * Build the summary for the exceptions in this package.
   246      *
   247      * @param node the XML element that specifies which components to document
   248      * @param summaryContentTree the summary tree to which the exception summary will
   249      *                           be added
   250      */
   251     public void buildExceptionSummary(XMLNode node, Content summaryContentTree) {
   252         String exceptionTableSummary =
   253                 configuration.getText("doclet.Member_Table_Summary",
   254                 configuration.getText("doclet.Exception_Summary"),
   255                 configuration.getText("doclet.exceptions"));
   256         String[] exceptionTableHeader = new String[] {
   257             configuration.getText("doclet.Exception"),
   258             configuration.getText("doclet.Description")
   259         };
   260         ClassDoc[] exceptions =
   261                 packageDoc.isIncluded()
   262                         ? packageDoc.exceptions()
   263                         : configuration.classDocCatalog.exceptions(
   264                                 Util.getPackageName(packageDoc));
   265         if (exceptions.length > 0) {
   266             packageWriter.addClassesSummary(
   267                     exceptions,
   268                     configuration.getText("doclet.Exception_Summary"),
   269                     exceptionTableSummary, exceptionTableHeader, summaryContentTree);
   270         }
   271     }
   273     /**
   274      * Build the summary for the errors in this package.
   275      *
   276      * @param node the XML element that specifies which components to document
   277      * @param summaryContentTree the summary tree to which the error summary will
   278      *                           be added
   279      */
   280     public void buildErrorSummary(XMLNode node, Content summaryContentTree) {
   281         String errorTableSummary =
   282                 configuration.getText("doclet.Member_Table_Summary",
   283                 configuration.getText("doclet.Error_Summary"),
   284                 configuration.getText("doclet.errors"));
   285         String[] errorTableHeader = new String[] {
   286             configuration.getText("doclet.Error"),
   287             configuration.getText("doclet.Description")
   288         };
   289         ClassDoc[] errors =
   290                 packageDoc.isIncluded()
   291                         ? packageDoc.errors()
   292                         : configuration.classDocCatalog.errors(
   293                                 Util.getPackageName(packageDoc));
   294         if (errors.length > 0) {
   295             packageWriter.addClassesSummary(
   296                     errors,
   297                     configuration.getText("doclet.Error_Summary"),
   298                     errorTableSummary, errorTableHeader, summaryContentTree);
   299         }
   300     }
   302     /**
   303      * Build the summary for the annotation type in this package.
   304      *
   305      * @param node the XML element that specifies which components to document
   306      * @param summaryContentTree the summary tree to which the annotation type
   307      *                           summary will be added
   308      */
   309     public void buildAnnotationTypeSummary(XMLNode node, Content summaryContentTree) {
   310         String annotationtypeTableSummary =
   311                 configuration.getText("doclet.Member_Table_Summary",
   312                 configuration.getText("doclet.Annotation_Types_Summary"),
   313                 configuration.getText("doclet.annotationtypes"));
   314         String[] annotationtypeTableHeader = new String[] {
   315             configuration.getText("doclet.AnnotationType"),
   316             configuration.getText("doclet.Description")
   317         };
   318         ClassDoc[] annotationTypes =
   319                 packageDoc.isIncluded()
   320                         ? packageDoc.annotationTypes()
   321                         : configuration.classDocCatalog.annotationTypes(
   322                                 Util.getPackageName(packageDoc));
   323         if (annotationTypes.length > 0) {
   324             packageWriter.addClassesSummary(
   325                     annotationTypes,
   326                     configuration.getText("doclet.Annotation_Types_Summary"),
   327                     annotationtypeTableSummary, annotationtypeTableHeader,
   328                     summaryContentTree);
   329         }
   330     }
   332     /**
   333      * Build the description of the summary.
   334      *
   335      * @param node the XML element that specifies which components to document
   336      * @param packageContentTree the tree to which the package description will
   337      *                           be added
   338      */
   339     public void buildPackageDescription(XMLNode node, Content packageContentTree) {
   340         if (configuration.nocomment) {
   341             return;
   342         }
   343         packageWriter.addPackageDescription(packageContentTree);
   344     }
   346     /**
   347      * Build the tags of the summary.
   348      *
   349      * @param node the XML element that specifies which components to document
   350      * @param packageContentTree the tree to which the package tags will be added
   351      */
   352     public void buildPackageTags(XMLNode node, Content packageContentTree) {
   353         if (configuration.nocomment) {
   354             return;
   355         }
   356         packageWriter.addPackageTags(packageContentTree);
   357     }
   358 }

mercurial