001: /*
002: * GenerateTocXML.java
003: * Copyright (C) 1999, 2003 Slava Pestov
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019:
020: package doclet;
021:
022: import com.sun.javadoc.*;
023: import com.sun.tools.doclets.standard.Standard;
024:
025: import java.io.*;
026: import java.util.Arrays;
027:
028: public class GenerateTocXML {
029: public static final String OUT = "toc.xml";
030: public static final String HEADER = "<?xml version='1.0'?>\n<TOC>\n"
031: + "<ENTRY HREF='overview-summary.html'><TITLE>jEdit API Reference</TITLE>";
032: public static final String FOOTER = "</ENTRY></TOC>\n";
033:
034: public static boolean start(RootDoc root) {
035: if (!Standard.start(root)) {
036: return false;
037: }
038: try {
039: FileWriter out = new FileWriter(Standard.htmlDoclet
040: .configuration().destDirName
041: + OUT);
042: out.write(HEADER);
043:
044: PackageDoc[] packages = root.specifiedPackages();
045: for (int i = 0; i < packages.length; ++i) {
046: processPackage(out, packages[i]);
047: }
048:
049: out.write(FOOTER);
050: out.close();
051:
052: return true;
053: } catch (IOException e) {
054: e.printStackTrace();
055: return false;
056: }
057: }
058:
059: public static int optionLength(String option) {
060: return Standard.optionLength(option);
061: }
062:
063: public static boolean validOptions(String[][] options,
064: DocErrorReporter reporter) {
065: return Standard.validOptions(options, reporter);
066: }
067:
068: public static LanguageVersion languageVersion() {
069: return Standard.languageVersion();
070: }
071:
072: private static void processPackage(Writer out, PackageDoc pkg)
073: throws IOException {
074: out.write("<ENTRY HREF='");
075: String pkgPath = pkg.name().replace('.', '/') + "/";
076: out.write(pkgPath);
077: out.write("package-summary.html'><TITLE>");
078: out.write(pkg.name());
079: out.write("</TITLE>\n");
080:
081: ClassDoc[] classes = pkg.allClasses();
082: String[] classNames = new String[classes.length];
083: for (int i = 0; i < classes.length; i++) {
084: classNames[i] = classes[i].name();
085: }
086: Arrays.sort(classNames);
087:
088: for (int i = 0; i < classes.length; i++) {
089: processClass(out, pkgPath, classNames[i]);
090: }
091:
092: out.write("</ENTRY>");
093: }
094:
095: private static void processClass(Writer out, String pkgPath,
096: String clazz) throws IOException {
097: out.write("<ENTRY HREF='");
098: out.write(pkgPath);
099: out.write(clazz);
100: out.write(".html'><TITLE>");
101: out.write(clazz);
102: out.write("</TITLE>\n");
103: out.write("</ENTRY>");
104: }
105: }
|