001: /*
002: * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html;
027:
028: import com.sun.tools.doclets.internal.toolkit.util.*;
029: import com.sun.tools.doclets.internal.toolkit.*;
030:
031: import com.sun.javadoc.*;
032: import java.io.*;
033: import java.util.*;
034:
035: /**
036: * Class to generate file for each package contents in the left-hand bottom
037: * frame. This will list all the Class Kinds in the package. A click on any
038: * class-kind will update the right-hand frame with the clicked class-kind page.
039: *
040: * @author Atul M Dambalkar
041: */
042: public class PackageFrameWriter extends HtmlDocletWriter {
043:
044: /**
045: * The package being documented.
046: */
047: private PackageDoc packageDoc;
048:
049: /**
050: * The classes to be documented. Use this to filter out classes
051: * that will not be documented.
052: */
053: private Set documentedClasses;
054:
055: /**
056: * The name of the output file.
057: */
058: public static final String OUTPUT_FILE_NAME = "package-frame.html";
059:
060: /**
061: * Constructor to construct PackageFrameWriter object and to generate
062: * "package-frame.html" file in the respective package directory.
063: * For example for package "java.lang" this will generate file
064: * "package-frame.html" file in the "java/lang" directory. It will also
065: * create "java/lang" directory in the current or the destination directory
066: * if it doesen't exist.
067: *
068: * @param configuration the configuration of the doclet.
069: * @param packageDoc PackageDoc under consideration.
070: */
071: public PackageFrameWriter(ConfigurationImpl configuration,
072: PackageDoc packageDoc) throws IOException {
073: super (configuration, DirectoryManager
074: .getDirectoryPath(packageDoc), OUTPUT_FILE_NAME,
075: DirectoryManager.getRelativePath(packageDoc));
076: this .packageDoc = packageDoc;
077: if (configuration.root.specifiedPackages().length == 0) {
078: documentedClasses = new HashSet(Arrays
079: .asList(configuration.root.classes()));
080: }
081: }
082:
083: /**
084: * Generate a package summary page for the left-hand bottom frame. Construct
085: * the PackageFrameWriter object and then uses it generate the file.
086: *
087: * @param configuration the current configuration of the doclet.
088: * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
089: */
090: public static void generate(ConfigurationImpl configuration,
091: PackageDoc packageDoc) {
092: PackageFrameWriter packgen;
093: try {
094: packgen = new PackageFrameWriter(configuration, packageDoc);
095: String pkgName = Util.getPackageName(packageDoc);
096: packgen.printHtmlHeader(pkgName, configuration.metakeywords
097: .getMetaKeywords(packageDoc), false);
098: packgen.printPackageHeader(pkgName);
099: packgen.generateClassListing();
100: packgen.printBodyHtmlEnd();
101: packgen.close();
102: } catch (IOException exc) {
103: configuration.standardmessage.error(
104: "doclet.exception_encountered", exc.toString(),
105: OUTPUT_FILE_NAME);
106: throw new DocletAbortException();
107: }
108: }
109:
110: /**
111: * Generate class listing for all the classes in this package. Divide class
112: * listing as per the class kind and generate separate listing for
113: * Classes, Interfaces, Exceptions and Errors.
114: */
115: protected void generateClassListing() {
116: Configuration config = configuration();
117: if (packageDoc.isIncluded()) {
118: generateClassKindListing(packageDoc.interfaces(),
119: configuration.getText("doclet.Interfaces"));
120: generateClassKindListing(packageDoc.ordinaryClasses(),
121: configuration.getText("doclet.Classes"));
122: generateClassKindListing(packageDoc.enums(), configuration
123: .getText("doclet.Enums"));
124: generateClassKindListing(packageDoc.exceptions(),
125: configuration.getText("doclet.Exceptions"));
126: generateClassKindListing(packageDoc.errors(), configuration
127: .getText("doclet.Errors"));
128: generateClassKindListing(packageDoc.annotationTypes(),
129: configuration.getText("doclet.AnnotationTypes"));
130: } else {
131: String name = Util.getPackageName(packageDoc);
132: generateClassKindListing(config.classDocCatalog
133: .interfaces(name), configuration
134: .getText("doclet.Interfaces"));
135: generateClassKindListing(config.classDocCatalog
136: .ordinaryClasses(name), configuration
137: .getText("doclet.Classes"));
138: generateClassKindListing(
139: config.classDocCatalog.enums(name), configuration
140: .getText("doclet.Enums"));
141: generateClassKindListing(config.classDocCatalog
142: .exceptions(name), configuration
143: .getText("doclet.Exceptions"));
144: generateClassKindListing(config.classDocCatalog
145: .errors(name), configuration
146: .getText("doclet.Errors"));
147: generateClassKindListing(config.classDocCatalog
148: .annotationTypes(name), configuration
149: .getText("doclet.AnnotationTypes"));
150: }
151: }
152:
153: /**
154: * Generate specific class kind listing. Also add label to the listing.
155: *
156: * @param arr Array of specific class kinds, namely Class or Interface or
157: * Exception or Error.
158: * @param label Label for the listing
159: */
160: protected void generateClassKindListing(ClassDoc[] arr, String label) {
161: if (arr.length > 0) {
162: Arrays.sort(arr);
163: printPackageTableHeader();
164: fontSizeStyle("+1", "FrameHeadingFont");
165: boolean printedHeader = false;
166: for (int i = 0; i < arr.length; i++) {
167: if (documentedClasses != null
168: && !documentedClasses.contains(arr[i])) {
169: continue;
170: }
171: if (!Util.isCoreClass(arr[i])
172: || !configuration.isGeneratedDoc(arr[i])) {
173: continue;
174: }
175: if (!printedHeader) {
176: print(label);
177: fontEnd();
178: println(" ");
179: fontStyle("FrameItemFont");
180: printedHeader = true;
181: }
182: br();
183: printLink(new LinkInfoImpl(LinkInfoImpl.PACKAGE_FRAME,
184: arr[i],
185: (arr[i].isInterface() ? italicsText(arr[i]
186: .name()) : arr[i].name()), "classFrame"));
187: }
188: fontEnd();
189: printPackageTableFooter();
190: println();
191: }
192: }
193:
194: /**
195: * Print the package link at the top of the class kind listing. Clicking
196: * this link, package-summary page will appear in the right hand frame.
197: *
198: * @param heading Top Heading to be used for the class kind listing.
199: */
200: protected void printPackageHeader(String heading) {
201: fontSizeStyle("+1", "FrameTitleFont");
202: printTargetPackageLink(packageDoc, "classFrame", heading);
203: fontEnd();
204: }
205:
206: /**
207: * The table for the class kind listing.
208: */
209: protected void printPackageTableHeader() {
210: table();
211: tr();
212: tdNowrap();
213: }
214:
215: /**
216: * Closing Html tags for table of class kind listing.
217: */
218: protected void printPackageTableFooter() {
219: tdEnd();
220: trEnd();
221: tableEnd();
222: }
223: }
|