PageRenderTime 54ms CodeModel.GetById 48ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/doclet/GenerateTocXML.java

#
Java | 116 lines | 82 code | 16 blank | 18 comment | 4 complexity | 623c4abc53c8cf2fe8fcb4413c7d403b MD5 | raw file
  1/*
  2 * GenerateTocXML.java
  3 * Copyright (C) 1999, 2003 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package doclet;
 21
 22import com.sun.javadoc.*;
 23import com.sun.tools.doclets.standard.Standard;
 24
 25import java.io.*;
 26import java.util.Arrays;
 27
 28public class GenerateTocXML
 29{
 30	public static final String OUT = "toc.xml";
 31	public static final String HEADER = "<?xml version='1.0'?>\n<TOC>\n"
 32		+ "<ENTRY HREF='overview-summary.html'><TITLE>jEdit API Reference</TITLE>";
 33	public static final String FOOTER = "</ENTRY></TOC>\n";
 34
 35	public static boolean start(RootDoc root)
 36	{
 37		if (!Standard.start(root))
 38		{
 39			return false;
 40		}
 41		try
 42		{
 43			FileWriter out = new FileWriter(Standard.htmlDoclet.configuration().destDirName + OUT);
 44			out.write(HEADER);
 45
 46			PackageDoc[] packages = root.specifiedPackages();
 47			for(int i = 0; i < packages.length; ++i)
 48			{
 49				processPackage(out,packages[i]);
 50			}
 51
 52			out.write(FOOTER);
 53			out.close();
 54
 55			return true;
 56		}
 57		catch(IOException e)
 58		{
 59			e.printStackTrace();
 60			return false;
 61		}
 62	}
 63
 64	public static int optionLength(String option)
 65	{
 66		return Standard.optionLength(option);
 67	}
 68
 69	public static boolean validOptions(String[][] options, DocErrorReporter reporter)
 70	{
 71		return Standard.validOptions(options,reporter);
 72	}
 73
 74	public static LanguageVersion languageVersion()
 75	{
 76		return Standard.languageVersion();
 77	}
 78
 79	private static void processPackage(Writer out, PackageDoc pkg)
 80		throws IOException
 81	{
 82		out.write("<ENTRY HREF='");
 83		String pkgPath = pkg.name().replace('.','/') + "/";
 84		out.write(pkgPath);
 85		out.write("package-summary.html'><TITLE>");
 86		out.write(pkg.name());
 87		out.write("</TITLE>\n");
 88
 89		ClassDoc[] classes = pkg.allClasses();
 90		String[] classNames = new String[classes.length];
 91		for(int i = 0; i < classes.length; i++)
 92		{
 93			classNames[i] = classes[i].name();
 94		}
 95		Arrays.sort(classNames);
 96
 97		for(int i = 0; i < classes.length; i++)
 98		{
 99			processClass(out,pkgPath,classNames[i]);
100		}
101
102		out.write("</ENTRY>");
103	}
104
105	private static void processClass(Writer out, String pkgPath, String clazz)
106		throws IOException
107	{
108		out.write("<ENTRY HREF='");
109		out.write(pkgPath);
110		out.write(clazz);
111		out.write(".html'><TITLE>");
112		out.write(clazz);
113		out.write("</TITLE>\n");
114		out.write("</ENTRY>");
115	}
116}