Fields Summary |
---|
private boolean | verbose |
public static final String | OUTPUTFILEThe output file that we create |
public static final String | TITLEThe string for TITLE and H1 |
PrintWriter | outThe main output stream |
public static final String | BGCOLORThe background color for the page |
boolean[] | existsArray of letters that exist. Should
fold case here so don't get f and F as distinct entries!
This only works for ASCII characters (8-bit chars). |
ArrayList | listList for temporary storage, and sorting |
boolean[] | doneKeep track of each letter for #links |
Methods Summary |
---|
void | begin()Write the HTML headers
println("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'");
println(" 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'");
println(">");
println();
println("<html>");
println("<head>");
println(" <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>");
println(" <meta name='Generator' content='Java MkIndex'/>");
println(" <link rel='stylesheet' type='text/css' href='/stylesheet.css' title='style'/>");
println(" <title>" + TITLE + "</title>");
println("</head>");
println();
println("<body bgcolor=\"" + BGCOLOR + "\">");
println("<h1>" + TITLE + "</h1>");
if (new File("about.html").exists()) {
FileIO.copyFile("about.html", out, false);
} else {
println("<p>The following files are online.");
println("Some of these files are still experimental!</p>");
println("<p>Most of these files are Java source code.");
println("If you load an HTML file from here, the applets will not run!");
println("The HTML files must be saved to disk and the applets compiled,");
println("before you can run them!</p>");
}
println("<p>All files are Copyright (c): All rights reserved.");
println("See the accompanying <a href=\"legal-notice.txt\">Legal Notice</a> for conditions of use.");
println("May be used by readers of my Java Cookbook for educational purposes, and for commercial use if certain conditions are met.");
println("</p>");
println("<hr />");
|
void | close()Close open files
System.out.println("Closing output files...");
if (out != null)
out.close();
|
void | end()Write the trailers and a signature
System.out.println("Finishing the HTML");
println("</ul>");
flush();
println("<p>This file generated by ");
print("<a href=\"MkIndex.java\">MkIndex</a>, a Java program, at ");
println(Calendar.getInstance().getTime().toString());
println("</p>");
println("</body>");
println("</html>");
|
void | flush()Convenience for out.flush();
out.flush();
|
boolean | ignorable(java.lang.String name)Return true if a filename should be ignored.
if (name.startsWith("index") ||
name.endsWith(".class") ||
name.endsWith(".jar") ||
name.endsWith(".bak")) {
if (verbose) {
System.err.println("Ignoring " + name);
}
return true;
} else if (name.equals("CVS")) { // Ignore CVS subdirectories
return true; // don't mention it
} else if (name.charAt(0) == '." && name.length() > 1) {// UNIX dot-file
return true;
}
return false;
|
public static void | main(java.lang.String[] args)Make an index
MkIndex mi = new MkIndex();
mi.setWriter(new PrintWriter(new FileWriter(OUTPUTFILE)));
mi.begin(); // print HTML header
System.out.println("** Start Pass One **");
if (args.length > 0) {
for (int i=0; i<args.length; i++)
mi.process(new File(args[i])); // "We do ALL the work..."
} else {
mi.process(new File("."));
}
mi.writeNav(); // Write navigator
mi.writeList(); // Write huge list of files
mi.end(); // print trailer.
mi.close(); // close files
|
void | mkDirLink(java.lang.String index, java.lang.String dir)
// XXX Open the index and look for TITLE lines!
println("<a href='" + index + "'>" + dir + "</a>");
|
void | mkLink(java.lang.String name, java.lang.String path)
print("<li>");
char c = name.charAt(0);
if (!done[c]) {
print("<a name=\"" + c + "\"/>");
done[c] = true;
}
println("<a href=\"" + path + "\">" + name + "</a>");
|
void | print(java.lang.String s)Convenience routine for out.print
out.print(s);
|
void | println(java.lang.String s)Convenience routine for out.println
out.println(s);
|
void | println()Convenience routine for out.println
out.println();
|
void | process(java.io.File file)Do the bulk of the work
String name = file.getName();
if (ignorable(name)) {
return;
}
if (file.isDirectory()) {
System.out.println("Indexing directory " + name);
File[] files = file.listFiles();
for (int i=0; i<files.length; i++) {
String fn = files[i].getName();
process(new File(file, fn));
}
} else {
// file to be processed.
list.add(new NameMap(name, file.getPath()));
exists[name.charAt(0)] = true;
}
|
void | setWriter(java.io.PrintWriter aWriter)
out = aWriter;
|
void | writeList()
// ... the beginning of the HTML Unordered List...
println("<ul>");
System.out.println("Sorting the list...");
Collections.sort(list);
System.out.println("Start PASS TWO -- from List to " +
OUTPUTFILE + "...");
Iterator it = list.iterator();
while (it.hasNext()) {
NameMap map = (NameMap)it.next();
String fn = map.name;
String path = map.path;
// Need to make a link into this directory.
// IF there is a descr.txt file, use it for the text
// of the link, otherwise, use the directory name.
// But, if there is an index.html (or index.htm) file,
// make the link to that file, else to the directory itself.
if (fn.endsWith("/")) { // directory
String descr = null;
if (new File(fn + "descr.txt").exists()) {
descr = FileIO.readLine(fn + "descr.txt");
};
if (new File(fn + "index.html").exists())
mkDirLink(fn+"index.html", descr!=null?descr:fn);
else if (new File(fn + "index.htm").exists())
mkDirLink(fn+"index.htm", descr!=null?descr:fn);
else
mkLink(fn, descr!=null?descr:fn + " -- Directory");
} else // file
mkLink(fn, path);
}
System.out.println("*** process - ALL DONE***");
|
void | writeNav()
System.out.println("Writing the Alphabet Navigator...");
for (char c = 'A"; c<='Z"; c++)
if (exists[c])
print("<a href=\"#" + c + "\">" + c + "</a> ");
|