/* * @(#)PackageWriter.java 1.21 98/04/28 * * Copyright 1997, 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.tools.doclets.standard; import com.sun.tools.doclets.*; import com.sun.javadoc.*; import java.io.*; import java.lang.*; import java.util.*; /** * Class to generate file for each package contents. * * @author Atul M Dambalkar */ public class PackageWriter extends AbstractPackageWriter { /** * The prev package name in the alpha-ordr list. */ protected PackageDoc prev; /** * The next package name in the alpha-ordr list. */ protected PackageDoc next; /** * Constructor. */ public PackageWriter(String path, String filename, PackageDoc packagedoc, PackageDoc prev, PackageDoc next) throws IOException, DocletAbortException { super(path, filename, packagedoc); this.prev = prev; this.next = next; } /** * Generate a package page. * * @param package the package to generate. */ public static void generate(PackageDoc pkg, PackageDoc prev, PackageDoc next) throws DocletAbortException { PackageWriter packgen; String path = DirectoryManager.getDirectoryPath(pkg); String filename = "package-summary.html"; try { packgen = new PackageWriter(path, filename, pkg, prev, next); packgen.generatePackageFile(); packgen.close(); packgen.copyDocFiles(path); } catch (IOException exc) { Standard.configuration().standardmessage. error("doclet.exception_encountered", exc.toString(), filename); throw new DocletAbortException(); } } /** * Generate class listing for all classes in this package. */ protected void generateClassListing() { generateClassKindListing(packagedoc.interfaces(), getText("doclet.Interface_Summary")); generateClassKindListing(packagedoc.ordinaryClasses(), getText("doclet.Class_Summary")); generateClassKindListing(packagedoc.exceptions(), getText("doclet.Exception_Summary")); generateClassKindListing(packagedoc.errors(), getText("doclet.Error_Summary")); } /** * This method is used by genIndPackageFiles method to generate * the Class/Interface... Listing. */ protected void generateClassKindListing(ClassDoc[] arr, String label) { if(arr.length > 0) { boolean deprecated = false; Arrays.sort(arr); tableIndexSummary(); printFirstRow(label); for (int i = 0; i < arr.length; i++) { trBgcolorClass("white", "TableRowColor"); summaryRow(15); bold(); printClassLinkForSameDir(arr[i]); boldEnd(); summaryRowEnd(); summaryRow(0); if (arr[i].tags("deprecated").length > 0) { deprecated = true; boldText("doclet.Deprecated"); space(); } printCommentTags(arr[i].firstSentenceTags(), deprecated); summaryRowEnd(); trEnd(); } tableEnd(); println(" "); p(); } } /** * Print the table heading for the class-listing. */ protected void printFirstRow(String label) { tableHeaderStart("#CCCCFF"); bold(label); tableHeaderEnd(); } /** * Print the package comment. */ protected void printPackageComment() { Tag[] commenttags = packagedoc.inlineTags(); if (commenttags.length > 0) { h2(getText("doclet.Package_Description")); p(); printCommentTags(commenttags); p(); } } /** * Print the package comment and the tag information. */ protected void printPackageDescription() throws IOException { printPackageComment(); generateTagInfo(packagedoc); } /** * Print the navigation bar links at the top. */ protected void printPackageHeader(String heading) { navLinks(true); hr(); h2(getText("doclet.Package") + " " + heading); } /** * Print the navigation bar links at the bottom. */ protected void printPackageFooter() { hr(); navLinks(false); printBottom(); } protected void copyDocFiles(String path) throws IOException { String srcpath = Standard.configuration().sourcepath.length() > 0? Standard.configuration().sourcepath + fileseparator: ""; String destname = destdir.length() > 0? destdir + fileseparator: ""; String src = srcpath + path + fileseparator + "doc-files"; String dest = destname + path + fileseparator + "doc-files"; try { File srcdir = new File(src); File destdir = new File(dest); if (srcdir.exists()) { DirectoryManager.createDirectory(dest); String[] files = srcdir.list(); for (int i = 0; i < files.length; i++) { File srcfile = new File(srcdir, files[i]); File destfile = new File(destdir, files[i]); if (srcfile.isFile()) { notice("doclet.Copying_File_0_To_Dir_1", srcfile.toString(), destdir.toString()); Standard.copyFile(destfile, srcfile); } } } } catch (SecurityException exc) { exc.printStackTrace(); System.exit(1); } } /** * Print previous package link */ protected void navLinkPrevious() { if (prev == null) { printText("doclet.Prev_Package"); } else { String path = DirectoryManager.getRelativePath(packagedoc.name(), prev.name()); printHyperLink(path + "package-summary.html", getText("doclet.Prev_Package")); } } /** * Print next package link */ protected void navLinkNext() { if (next == null) { printText("doclet.Next_Package"); } else { String path = DirectoryManager.getRelativePath(packagedoc.name(), next.name()); printHyperLink(path + "package-summary.html", getText("doclet.Next_Package")); } } protected void navLinkTree() { printHyperLink("tree.html", getText("doclet.Tree")); } }