duke@1: /* jjg@1606: * Copyright (c) 2003, 2013, 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.internal.toolkit.builders; duke@1: bpatel@766: import java.io.*; jjg@1357: bpatel@766: import com.sun.javadoc.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Builds the summary for a given package. 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. duke@1: * duke@1: * @author Jamie Ho bpatel@243: * @author Bhavesh Patel (Modified) duke@1: * @since 1.5 duke@1: */ duke@1: public class PackageSummaryBuilder extends AbstractBuilder { bpatel@766: /** bpatel@766: * The root element of the package summary XML is {@value}. bpatel@766: */ bpatel@766: public static final String ROOT = "PackageDoc"; duke@1: bpatel@766: /** bpatel@766: * The package being documented. bpatel@766: */ jjg@1410: private final PackageDoc packageDoc; duke@1: bpatel@766: /** bpatel@766: * The doclet specific writer that will output the result. bpatel@766: */ jjg@1410: private final PackageSummaryWriter packageWriter; duke@1: bpatel@766: /** bpatel@766: * The content that will be added to the package summary documentation tree. bpatel@766: */ bpatel@766: private Content contentTree; duke@1: jjg@1410: /** jjg@1410: * Construct a new PackageSummaryBuilder. jjg@1410: * jjg@1410: * @param context the build context. jjg@1410: * @param pkg the package being documented. jjg@1410: * @param packageWriter the doclet specific writer that will output the jjg@1410: * result. jjg@1410: */ jjg@1410: private PackageSummaryBuilder(Context context, jjg@1410: PackageDoc pkg, jjg@1410: PackageSummaryWriter packageWriter) { jjg@1410: super(context); jjg@1410: this.packageDoc = pkg; jjg@1410: this.packageWriter = packageWriter; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Construct a new PackageSummaryBuilder. jjg@1410: * jjg@1410: * @param context the build context. bpatel@766: * @param pkg the package being documented. bpatel@766: * @param packageWriter the doclet specific writer that will output the bpatel@766: * result. bpatel@766: * bpatel@766: * @return an instance of a PackageSummaryBuilder. bpatel@766: */ jjg@1410: public static PackageSummaryBuilder getInstance(Context context, jjg@1410: PackageDoc pkg, PackageSummaryWriter packageWriter) { jjg@1410: return new PackageSummaryBuilder(context, pkg, packageWriter); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the package summary. bpatel@766: */ bpatel@766: public void build() throws IOException { bpatel@766: if (packageWriter == null) { bpatel@766: //Doclet does not support this output. bpatel@766: return; duke@1: } jjg@1410: build(layoutParser.parseXML(ROOT), contentTree); bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public String getName() { bpatel@766: return ROOT; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the package documentation. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param contentTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildPackageDoc(XMLNode node, Content contentTree) throws Exception { bpatel@766: contentTree = packageWriter.getPackageHeader( bpatel@766: Util.getPackageName(packageDoc)); bpatel@766: buildChildren(node, contentTree); bpatel@766: packageWriter.addPackageFooter(contentTree); bpatel@766: packageWriter.printDocument(contentTree); bpatel@766: packageWriter.close(); jjg@1383: Util.copyDocFiles(configuration, packageDoc); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the content for the package doc. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param contentTree the content tree to which the package contents bpatel@766: * will be added bpatel@766: */ bpatel@766: public void buildContent(XMLNode node, Content contentTree) { bpatel@766: Content packageContentTree = packageWriter.getContentHeader(); bpatel@766: buildChildren(node, packageContentTree); bpatel@766: contentTree.addContent(packageContentTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the package summary. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param packageContentTree the package content tree to which the summaries will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildSummary(XMLNode node, Content packageContentTree) { bpatel@766: Content summaryContentTree = packageWriter.getSummaryHeader(); bpatel@766: buildChildren(node, summaryContentTree); bpatel@766: packageContentTree.addContent(summaryContentTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the summary for the interfaces in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the interface summary bpatel@766: * will be added bpatel@766: */ bpatel@766: public void buildInterfaceSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String interfaceTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Interface_Summary"), bpatel@766: configuration.getText("doclet.interfaces")); bpatel@766: String[] interfaceTableHeader = new String[] { bpatel@766: configuration.getText("doclet.Interface"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] interfaces = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.interfaces() bpatel@766: : configuration.classDocCatalog.interfaces( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: interfaces = Util.filterOutPrivateClasses(interfaces, configuration.javafx); bpatel@766: if (interfaces.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: interfaces, bpatel@766: configuration.getText("doclet.Interface_Summary"), bpatel@766: interfaceTableSummary, interfaceTableHeader, summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the summary for the classes in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the class summary will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildClassSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String classTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Class_Summary"), bpatel@766: configuration.getText("doclet.classes")); bpatel@766: String[] classTableHeader = new String[] { bpatel@766: configuration.getText("doclet.Class"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] classes = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.ordinaryClasses() bpatel@766: : configuration.classDocCatalog.ordinaryClasses( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: classes = Util.filterOutPrivateClasses(classes, configuration.javafx); bpatel@766: if (classes.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: classes, bpatel@766: configuration.getText("doclet.Class_Summary"), bpatel@766: classTableSummary, classTableHeader, summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the summary for the enums in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the enum summary will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildEnumSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String enumTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Enum_Summary"), bpatel@766: configuration.getText("doclet.enums")); bpatel@766: String[] enumTableHeader = new String[] { bpatel@766: configuration.getText("doclet.Enum"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] enums = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.enums() bpatel@766: : configuration.classDocCatalog.enums( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: enums = Util.filterOutPrivateClasses(enums, configuration.javafx); bpatel@766: if (enums.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: enums, bpatel@766: configuration.getText("doclet.Enum_Summary"), bpatel@766: enumTableSummary, enumTableHeader, summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the summary for the exceptions in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the exception summary will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildExceptionSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String exceptionTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Exception_Summary"), bpatel@766: configuration.getText("doclet.exceptions")); bpatel@766: String[] exceptionTableHeader = new String[] { bpatel@766: configuration.getText("doclet.Exception"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] exceptions = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.exceptions() bpatel@766: : configuration.classDocCatalog.exceptions( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: exceptions = Util.filterOutPrivateClasses(exceptions, configuration.javafx); bpatel@766: if (exceptions.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: exceptions, bpatel@766: configuration.getText("doclet.Exception_Summary"), bpatel@766: exceptionTableSummary, exceptionTableHeader, summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the summary for the errors in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the error summary will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildErrorSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String errorTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Error_Summary"), bpatel@766: configuration.getText("doclet.errors")); bpatel@766: String[] errorTableHeader = new String[] { bpatel@766: configuration.getText("doclet.Error"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] errors = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.errors() bpatel@766: : configuration.classDocCatalog.errors( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: errors = Util.filterOutPrivateClasses(errors, configuration.javafx); bpatel@766: if (errors.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: errors, bpatel@766: configuration.getText("doclet.Error_Summary"), bpatel@766: errorTableSummary, errorTableHeader, summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the summary for the annotation type in this package. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param summaryContentTree the summary tree to which the annotation type bpatel@766: * summary will be added bpatel@766: */ bpatel@766: public void buildAnnotationTypeSummary(XMLNode node, Content summaryContentTree) { bpatel@766: String annotationtypeTableSummary = bpatel@766: configuration.getText("doclet.Member_Table_Summary", bpatel@766: configuration.getText("doclet.Annotation_Types_Summary"), bpatel@766: configuration.getText("doclet.annotationtypes")); bpatel@766: String[] annotationtypeTableHeader = new String[] { bpatel@766: configuration.getText("doclet.AnnotationType"), bpatel@766: configuration.getText("doclet.Description") bpatel@766: }; bpatel@766: ClassDoc[] annotationTypes = bpatel@766: packageDoc.isIncluded() bpatel@766: ? packageDoc.annotationTypes() bpatel@766: : configuration.classDocCatalog.annotationTypes( bpatel@766: Util.getPackageName(packageDoc)); jjg@1606: annotationTypes = Util.filterOutPrivateClasses(annotationTypes, configuration.javafx); bpatel@766: if (annotationTypes.length > 0) { bpatel@766: packageWriter.addClassesSummary( bpatel@766: annotationTypes, bpatel@766: configuration.getText("doclet.Annotation_Types_Summary"), bpatel@766: annotationtypeTableSummary, annotationtypeTableHeader, bpatel@766: summaryContentTree); duke@1: } bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the description of the summary. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param packageContentTree the tree to which the package description will bpatel@766: * be added bpatel@766: */ bpatel@766: public void buildPackageDescription(XMLNode node, Content packageContentTree) { bpatel@766: if (configuration.nocomment) { bpatel@766: return; duke@1: } bpatel@766: packageWriter.addPackageDescription(packageContentTree); bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the tags of the summary. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param packageContentTree the tree to which the package tags will be added bpatel@766: */ bpatel@766: public void buildPackageTags(XMLNode node, Content packageContentTree) { bpatel@766: if (configuration.nocomment) { bpatel@766: return; duke@1: } bpatel@766: packageWriter.addPackageTags(packageContentTree); bpatel@766: } duke@1: }