
package rob.servlets.addressbook ;

import java.io.* ;
import java.util.* ;


/**
 * ErrorPage 
 *
 *
 * Created: Fri Mar  9 16:05:14 2001
 *
 * @author <a href="mailto: "Robert Judd</a>
 * @version
 */

public class ErrorPage {

    private String error ;

    public ErrorPage(String error) {
	this.error = error ;
    }
    
    public void write(PrintWriter w) {
	for (int i=0, max=data.length; i<max; ++i) {
	    if (i == ERROR_LINE)
		w.println(error) ;
	    else if (i == MESSAGE_LINE)
		w.println("Generated by AddressBookServlet "+new Date().toString());
	    else 
		w.println(data[i]) ;
	}
	w.flush() ;
	w.close() ;
    }

    public static void main(String[] args) {

	try {

	    PrintWriter w ;
	    if (args[0].equals("-"))
		w = new PrintWriter(System.out) ;
	    else
		w = new PrintWriter(new FileWriter(args[0])) ;

	    ErrorPage ep = new ErrorPage("Doh!") ;
	    ep.write(w) ;

	} catch (Exception ex) {
	    System.out.println
		("Usage: java rob.servlets.addressbook.ErrorPage ( filename | - )");
	}


    }

    public static final int ERROR_LINE = 16 ;
    public static final int MESSAGE_LINE = 26 ;
    public static final String[] data = new String[] {
	"<html>",
	"<head>",
	"",
	"<title>AddressBookServlet Login</title>",
	"",
	"</head>",
	"<body bgcolor=\"#FFFFFF\">",
	" ",
	"<table border=0 cellspacing=0 cellpadding=10 width=100% bgcolor=\"#767E9E\">",
	"  <tr><td align=center valign=center height=60><font color=\"#C2D7EA\" size=7>",
	"    <b>AddressBookServlet Error</b></font></td></tr>",
	"</table>",
	"",
	"<br>",
	"Your request could not be processed for the following reason:",
	"<ul>",
	"  Unknown.",
	"</ul>",
	"<br>",
	"<table border=0 cellspacing=0 cellpadding=10 width=100% bgcolor=\"#767E9E\">",
	"  <tr><td align=right> &nbsp;",
	"  </td></tr>",
	"</table>",
	"<br>",
	"<address>",
	"<font color=\"#767E9E\">",
	"Generated by AddressBookServlet Fri Mar  9 16:05:14 2001",
	"</font>",
	"</address>",
	"",
	"</body>",
	"</html>",

    } ;


}// ErrorPage
