FileDocCategorySizeDatePackage
ImageIndex.javaAPI DocExample4412Tue Mar 13 15:32:36 GMT 2001None

ImageIndex

public class ImageIndex extends Object
ImageIndex -- make an index.html for an image directory based on some images and a "captions.txt" file.
For each image x, assume there is the following:
a file x+THUMB_SUFFIX which is the thumbnail
a file x+IMAGE_SUFFIX which is the large image
an entry in the "captions.txt" file, of the form
x Group shot in front of statue
author
Ian F. Darwin, ian@darwinsys.com
Version
$Id: ImageIndex.java,v 1.3 2001/03/13 20:32:37 ian Exp $

Fields Summary
protected String
image_suffix
protected String
thumb_suffix
public static final String
CAPTIONS_FILE
The captions file (created by hand)
protected BufferedReader
cap
A reader for the captions file
protected HashMap
map
The map from filename to caption
Vector
names
Vector for listing names for sorting
public static final String
OUTPUTFILE
The output file that we create
PrintWriter
out
The main output stream
Properties
pprops
Properties
String
PROPS_FILE
Properties file
public String
bgcolor
The background color for the page
String
title
The title of this show
Constructors Summary
Methods Summary
voidBEGIN()
Write the HTML headers

		println("<HTML>");
		println("<HEAD>");
		println("    <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">");
		println("    <META NAME=\"GENERATOR\" CONTENT=\"Java ImageIndex\">");
		println("    <TITLE>" + title + "</TITLE>");
		println("</HEAD>");
		println("<BODY BGCOLOR=\"" + pprops.get("bgcolor") + "\">");
		println("<H1>" + title + "</H1>");
		println("<P>All files are Copyright ©: All rights reserved.");
		println("</P>");
		println("<HR>");
	
voidEND()
Write the trailers and a signature

		System.out.println("Finishing the HTML");
		println("</UL>");
		println("<P>This file generated by the Java program ");
		print("<A HREF=\"ImageIndex.java\">ImageIndex</A> at ");
		println(new Date().toString());
		println("</P>");
		println("</BODY>");
		println("</HTML>");
	
voidclose()
Close open files

		System.out.println("Closing output files...");
		if (out != null)
			out.close();
	
public static voidmain(java.lang.String[] av)
Make an index


	    
	     
		ImageIndex mi = new ImageIndex();
		try {
			mi.open(CAPTIONS_FILE, OUTPUTFILE);		// open files
			mi.read();		// read caption file
			mi.BEGIN();		// print HTML header
			mi.process();		// do bulk of work
			mi.END();		// print trailer.
			mi.close();		// close files
		} catch (IOException e) {
			System.err.println(e);
		}
	
voidmkLink(java.lang.String href, java.lang.String descrip)

		// System.out.println(href + "==>" + descrip);
		String thumbnail = href + thumb_suffix;
		String image = href + image_suffix;
		print("<tr><td>");
		print("<a href=\"" + image + "\">");
		print("<img src=\"" + thumbnail + "\"></a>");
		print("</td><td>");
		print("<a href=\"" + image + "\">");
		print(descrip + "</a>");
		print("</td></tr>");
		println();
	
voidopen(java.lang.String captions, java.lang.String outFile)
Open the files

		cap = new BufferedReader(new FileReader(captions));
		out = new PrintWriter(new FileWriter(outFile));
		pprops = new FileProperties(PROPS_FILE);
		title = pprops.getProperty("title");
		thumb_suffix = pprops.getProperty("thumb_suffix");
		image_suffix = pprops.getProperty("image_suffix");
	
voidprint(java.lang.String s)
Convenience routine for out.print

		out.print(s);
	
voidprintln(java.lang.String s)
Convenience routine for out.println

		out.println(s);
	
voidprintln()

		out.println();
	
voidprocess()
Do the bulk of the work


		System.out.println("Generating HTML...");
		println("<table>");

		String fn;
		for (int i=0; i<names.size(); i++) {
			fn = (String)names.elementAt(i);
			mkLink(fn, (String)map.get(fn));
		}
		println("</table>");
		System.out.println("*** process - done ***");
	
voidread()
read the captions file


		String line;
		while ((line = cap.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(line, "\t");
			String name = st.nextToken();
			String desc = st.nextToken();
			names.addElement(name);
			map.put(name, desc);
		}
		cap.close();