01: /*
02: * Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.tools.doclets.internal.toolkit.util;
27:
28: import com.sun.tools.doclets.internal.toolkit.*;
29: import com.sun.javadoc.*;
30: import java.io.*;
31: import java.util.*;
32:
33: /**
34: * Write out the package index.
35: *
36: * This code is not part of an API.
37: * It is implementation that is subject to change.
38: * Do not use it as an API
39: *
40: * @see com.sun.javadoc.PackageDoc
41: * @author Atul M Dambalkar
42: */
43: public class PackageListWriter extends PrintWriter {
44:
45: private Configuration configuration;
46:
47: /**
48: * Constructor.
49: *
50: * @param configuration the current configuration of the doclet.
51: */
52: public PackageListWriter(Configuration configuration)
53: throws IOException {
54: super (Util.genWriter(configuration, configuration.destDirName,
55: DocletConstants.PACKAGE_LIST_FILE_NAME,
56: configuration.docencoding));
57: this .configuration = configuration;
58: }
59:
60: /**
61: * Generate the package index.
62: *
63: * @param configuration the current configuration of the doclet.
64: * @throws DocletAbortException
65: */
66: public static void generate(Configuration configuration) {
67: PackageListWriter packgen;
68: try {
69: packgen = new PackageListWriter(configuration);
70: packgen.generatePackageListFile(configuration.root);
71: packgen.close();
72: } catch (IOException exc) {
73: configuration.message.error("doclet.exception_encountered",
74: exc.toString(),
75: DocletConstants.PACKAGE_LIST_FILE_NAME);
76: throw new DocletAbortException();
77: }
78: }
79:
80: protected void generatePackageListFile(RootDoc root) {
81: PackageDoc[] packages = configuration.packages;
82: String[] names = new String[packages.length];
83: for (int i = 0; i < packages.length; i++) {
84: names[i] = packages[i].name();
85: }
86: Arrays.sort(names);
87: for (int i = 0; i < packages.length; i++) {
88: println(names[i]);
89: }
90: }
91: }
|