duke@1: /* ohair@798: * Copyright (c) 2003, 2010, 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.*; bpatel@766: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: duke@1: /** duke@1: * Builds the summary for a given package. duke@1: * duke@1: * This code is not part of an API. duke@1: * It is implementation that is subject to change. duke@1: * Do not use it as an API 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: */ bpatel@766: private PackageDoc packageDoc; duke@1: bpatel@766: /** bpatel@766: * The doclet specific writer that will output the result. bpatel@766: */ bpatel@766: private 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: bpatel@766: private PackageSummaryBuilder(Configuration configuration) { bpatel@766: super(configuration); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Construct a new PackageSummaryBuilder. bpatel@766: * @param configuration the current configuration of the doclet. 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: */ bpatel@766: public static PackageSummaryBuilder getInstance( bpatel@766: Configuration configuration, bpatel@766: PackageDoc pkg, bpatel@766: PackageSummaryWriter packageWriter) { bpatel@766: PackageSummaryBuilder builder = bpatel@766: new PackageSummaryBuilder(configuration); bpatel@766: builder.packageDoc = pkg; bpatel@766: builder.packageWriter = packageWriter; bpatel@766: return builder; 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: } bpatel@766: build(LayoutParser.getInstance(configuration).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(); bpatel@766: Util.copyDocFiles( bpatel@766: configuration, bpatel@766: Util.getPackageSourcePath(configuration, packageDoc), bpatel@766: DirectoryManager.getDirectoryPath(packageDoc) bpatel@766: + File.separator bpatel@766: + DocletConstants.DOC_FILES_DIR_NAME, bpatel@766: true); 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)); 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)); 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)); 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)); 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)); 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)); 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: }