PageRenderTime 123ms CodeModel.GetById 102ms app.highlight 13ms RepoModel.GetById 5ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/doclet/GenerateTocXML.java

#
Java | 101 lines | 66 code | 14 blank | 21 comment | 3 complexity | c5432b7d402d32621c13f478e2b172b2 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.*;
 23
 24import java.io.*;
 25import java.util.Arrays;
 26
 27/**
 28 * This is very much of a hack.
 29 */
 30public class GenerateTocXML
 31{
 32	public static final String PATH = "doc/api/";
 33	public static final String OUT = PATH + "toc.xml";
 34	public static final String HEADER = "<?xml version='1.0'?>\n<TOC>\n"
 35		+ "<ENTRY HREF='overview-summary.html'><TITLE>jEdit API Reference</TITLE>";
 36	public static final String FOOTER = "</ENTRY></TOC>\n";
 37
 38	public static boolean start(RootDoc root)
 39	{
 40		try
 41		{
 42			FileWriter out = new FileWriter(OUT);
 43			out.write(HEADER);
 44
 45			PackageDoc[] packages = root.specifiedPackages();
 46			for(int i = 0; i < packages.length; ++i)
 47			{
 48				processPackage(out,packages[i]);
 49			}
 50
 51			out.write(FOOTER);
 52			out.close();
 53
 54			return true;
 55		}
 56		catch(IOException e)
 57		{
 58			e.printStackTrace();
 59			return false;
 60		}
 61	}
 62
 63	private static void processPackage(Writer out, PackageDoc pkg)
 64		throws IOException
 65	{
 66		out.write("<ENTRY HREF='");
 67		String pkgPath = pkg.name().replace('.','/') + "/";
 68		out.write(pkgPath);
 69		out.write("package-summary.html'><TITLE>");
 70		out.write(pkg.name());
 71		out.write("</TITLE>\n");
 72
 73		ClassDoc[] classes = pkg.allClasses();
 74		String[] classNames = new String[classes.length];
 75		for(int i = 0; i < classes.length; i++)
 76		{
 77			classNames[i] = classes[i].name();
 78		}
 79		Arrays.sort(classNames);
 80
 81		for(int i = 0; i < classes.length; i++)
 82		{
 83			processClass(out,pkgPath,classNames[i]);
 84		}
 85
 86		out.write("</ENTRY>");
 87	}
 88
 89	private static void processClass(Writer out, String pkgPath, String clazz)
 90		throws IOException
 91	{
 92		out.write("<ENTRY HREF='");
 93		out.write(pkgPath);
 94		out.write(clazz);
 95		out.write(".html'><TITLE>");
 96		out.write(clazz);
 97		out.write("</TITLE>\n");
 98		out.write("</ENTRY>");
 99	}
100}
101