001    /*
002     * Copyright 1997-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.*;
029    import com.sun.tools.doclets.internal.toolkit.util.*;
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 right-hand
037     * frame. This will list all the Class Kinds in the package. A click on any
038     * class-kind will update the frame with the clicked class-kind page.
039     *
040     * @author Atul M Dambalkar
041     */
042    public class PackageWriterImpl extends HtmlDocletWriter
043        implements PackageSummaryWriter {
044    
045        /**
046         * The prev package name in the alpha-order list.
047         */
048        protected PackageDoc prev;
049    
050        /**
051         * The next package name in the alpha-order list.
052         */
053        protected PackageDoc next;
054    
055        /**
056         * The package being documented.
057         */
058        protected PackageDoc packageDoc;
059    
060        /**
061         * The name of the output file.
062         */
063        private static final String OUTPUT_FILE_NAME = "package-summary.html";
064    
065        /**
066         * Constructor to construct PackageWriter object and to generate
067         * "package-summary.html" file in the respective package directory.
068         * For example for package "java.lang" this will generate file
069         * "package-summary.html" file in the "java/lang" directory. It will also
070         * create "java/lang" directory in the current or the destination directory
071         * if it doesen't exist.
072         *
073         * @param configuration the configuration of the doclet.
074         * @param packageDoc    PackageDoc under consideration.
075         * @param prev          Previous package in the sorted array.
076         * @param next            Next package in the sorted array.
077         */
078        public PackageWriterImpl(ConfigurationImpl configuration,
079            PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
080        throws IOException {
081            super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME,
082                 DirectoryManager.getRelativePath(packageDoc.name()));
083            this.prev = prev;
084            this.next = next;
085            this.packageDoc = packageDoc;
086        }
087    
088        /**
089         * Return the name of the output file.
090         *
091         * @return the name of the output file.
092         */
093        public String getOutputFileName() {
094            return OUTPUT_FILE_NAME;
095        }
096    
097        /**
098         * {@inheritDoc}
099         */
100        public void writeSummaryHeader() {}
101    
102        /**
103         * {@inheritDoc}
104         */
105        public void writeSummaryFooter() {}
106    
107        /**
108         * {@inheritDoc}
109         */
110        public void writeClassesSummary(ClassDoc[] classes, String label) {
111            if(classes.length > 0) {
112                Arrays.sort(classes);
113                tableIndexSummary();
114                boolean printedHeading = false;
115                for (int i = 0; i < classes.length; i++) {
116                    if (!printedHeading) {
117                        printFirstRow(label);
118                        printedHeading = true;
119                    }
120                    if (!Util.isCoreClass(classes[i]) ||
121                        !configuration.isGeneratedDoc(classes[i])) {
122                        continue;
123                    }
124                    trBgcolorStyle("white", "TableRowColor");
125                    summaryRow(15);
126                    strong();
127                    printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_PACKAGE,
128                        classes[i], false));
129                    strongEnd();
130                    summaryRowEnd();
131                    summaryRow(0);
132                    if (Util.isDeprecated(classes[i])) {
133                        strongText("doclet.Deprecated");
134                        if (classes[i].tags("deprecated").length > 0) {
135                            space();
136                            printSummaryDeprecatedComment(classes[i],
137                                classes[i].tags("deprecated")[0]);
138                        }
139                    } else {
140                        printSummaryComment(classes[i]);
141                    }
142                    summaryRowEnd();
143                    trEnd();
144                }
145                tableEnd();
146                println("&nbsp;");
147                p();
148            }
149        }
150    
151        /**
152         * Print the table heading for the class-listing.
153         *
154         * @param label Label for the Class kind listing.
155         */
156        protected void printFirstRow(String label) {
157            tableHeaderStart("#CCCCFF");
158            strong(label);
159            tableHeaderEnd();
160        }
161    
162        /**
163         * {@inheritDoc}
164         */
165        public void writePackageDescription() {
166            if (packageDoc.inlineTags().length > 0) {
167                anchor("package_description");
168                h2(configuration.getText("doclet.Package_Description", packageDoc.name()));
169                p();
170                printInlineComment(packageDoc);
171                p();
172            }
173        }
174    
175        /**
176         * {@inheritDoc}
177         */
178        public void writePackageTags() {
179            printTags(packageDoc);
180        }
181    
182        /**
183         * {@inheritDoc}
184         */
185        public void writePackageHeader(String heading) {
186            String pkgName = packageDoc.name();
187            printHtmlHeader(pkgName,
188                configuration.metakeywords.getMetaKeywords(packageDoc), true);
189            printTop();
190            navLinks(true);
191            hr();
192            writeAnnotationInfo(packageDoc);
193            h2(configuration.getText("doclet.Package") + " " + heading);
194            if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
195                printSummaryComment(packageDoc);
196                p();
197                strong(configuration.getText("doclet.See"));
198                br();
199                printNbsps();
200                printHyperLink("", "package_description",
201                    configuration.getText("doclet.Description"), true);
202                p();
203            }
204        }
205    
206        /**
207         * {@inheritDoc}
208         */
209        public void writePackageFooter() {
210            hr();
211            navLinks(false);
212            printBottom();
213            printBodyHtmlEnd();
214        }
215    
216        /**
217         * Print "Use" link for this pacakge in the navigation bar.
218         */
219        protected void navLinkClassUse() {
220            navCellStart();
221            printHyperLink("package-use.html", "", configuration.getText("doclet.navClassUse"),
222                           true, "NavBarFont1");
223            navCellEnd();
224        }
225    
226        /**
227         * Print "PREV PACKAGE" link in the navigation bar.
228         */
229        protected void navLinkPrevious() {
230            if (prev == null) {
231                printText("doclet.Prev_Package");
232            } else {
233                String path = DirectoryManager.getRelativePath(packageDoc.name(),
234                                                               prev.name());
235                printHyperLink(path + "package-summary.html", "",
236                    configuration.getText("doclet.Prev_Package"), true);
237            }
238        }
239    
240        /**
241         * Print "NEXT PACKAGE" link in the navigation bar.
242         */
243        protected void navLinkNext() {
244            if (next == null) {
245                printText("doclet.Next_Package");
246            } else {
247                String path = DirectoryManager.getRelativePath(packageDoc.name(),
248                                                               next.name());
249                printHyperLink(path + "package-summary.html", "",
250                    configuration.getText("doclet.Next_Package"), true);
251            }
252        }
253    
254        /**
255         * Print "Tree" link in the navigation bar. This will be link to the package
256         * tree file.
257         */
258        protected void navLinkTree() {
259            navCellStart();
260            printHyperLink("package-tree.html", "", configuration.getText("doclet.Tree"),
261                           true, "NavBarFont1");
262            navCellEnd();
263        }
264    
265        /**
266         * Highlight "Package" in the navigation bar, as this is the package page.
267         */
268        protected void navLinkPackage() {
269            navCellRevStart();
270            fontStyle("NavBarFont1Rev");
271            strongText("doclet.Package");
272            fontEnd();
273            navCellEnd();
274        }
275    }