
package rob.servlets.addressbook ;

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


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

public class EditPage {

    private String name, email, address1, address2, city, state, zipcode, 
	telephone, addressid, userid ;
    

    public EditPage(String name, String email, String address1, String address2, 
		    String city, String state, String zipcode, String telephone, 
		    String addressid, String userid) {
	this.name = name ;
	this.email = email ;
	this.address1 = address1 ;
	this.address2 = address2 ;
	this.city = city ;
	this.state = state ;
	this.zipcode = zipcode ;
	this.telephone = telephone ;
	this.addressid = addressid ;
	this.userid = userid ;
    }

    public EditPage(String[] info) {
	this(info[0], info[1], info[2], info[3], info[4], 
	     info[5], info[6], info[7], info[8], info[9]) ;
    } 
    
    
    public void write(PrintWriter w) {


	for (int i=0, max=data.length; i<max; ++i) {
	    switch (i) {
		case TITLE_LINE:
		    w.println("Edit address of "+name) ;
		    break ;
		case NAME_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"name\" size=\"20\" value=\"") ;
		    w.print(name) ;
		    w.println("\"></td>") ;
		    break ;
		case EMAIL_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"email\" size=\"20\" value=\"") ;
		    w.print(email) ;
		    w.println("\"></td>") ;
		    break ;
		case ADDRESS1_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"address1\" size=\"20\" value=\"") ;
		    w.print(address1) ;
		    w.println("\"></td>") ;
		    break ;
		case ADDRESS2_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"address2\" size=\"20\" value=\"") ;
		    w.print(address2) ;
		    w.println("\"></td>") ;
		    break ;
		case CITY_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"city\" size=\"20\" value=\"") ;
		    w.print(city) ;
		    w.println("\"></td>") ;
		    break ;
		case STATE_LINE:
		    w.print("        <input maxlength=\"2\" type=\"text\" ") ;
		    w.print("name=\"state\" size=\"2\" value=\"") ;
		    w.println(state+"\">") ;
		    break ;
		case ZIPCODE_LINE:
		    w.print("        <input maxlength=\"10\" type=\"text\" ") ;
		    w.print("name=\"zipcode\" size=\"10\" value=\"") ;
		    w.println(zipcode+"\">") ;
		    break ;
		case TELEPHONE_LINE:
		    w.print("    <td><input maxlength=\"40\" type=\"text\" ") ;
		    w.print("name=\"telephone\" size=\"20\" value=\"") ;
		    w.print(telephone) ;
		    w.println("\"></td>") ;
		    break ;
		case ADDRESSID_LINE:
		    w.print("    <td><input type=\"hidden\" ") ;
		    w.print("name=\"addressid\" value=\"") ;
		    w.print(addressid) ;
		    w.println("\">") ;
		    w.print("     <input type=\"hidden\" name=\"userid\" value=\"");
		    w.print(userid) ;
		    w.println("\"></td>") ;
		    break ;
		case MESSAGE_LINE:
		    w.println
			("Generated by AddressBookServlet "+new Date().toString()) ;
		    break ;
	    default:
		w.println(data[i]) ;
		break ;
	    }
	}
	w.flush() ;
	w.close() ;
    }

    public static void main(String[] args) {

	try {

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

	     EditPage ep = new  EditPage
		 ("name", "email", "address1", "address2", 
		  "city", "state", "zipcode", "telephone", "addressid", "userid") ;
	     ep.write(w) ;

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


    }

    public static final int TITLE_LINE = 42 ;
    public static final int NAME_LINE = 53 ;
    public static final int EMAIL_LINE = 55 ;
    public static final int ADDRESS1_LINE = 59 ;
    public static final int ADDRESS2_LINE = 61 ;
    public static final int CITY_LINE = 65 ;
    public static final int STATE_LINE = 68 ;
    public static final int ZIPCODE_LINE = 70 ;
    public static final int TELEPHONE_LINE = 75 ;
    public static final int ADDRESSID_LINE = 76 ;
    public static final int MESSAGE_LINE = 115 ;
    public static final String[] data = new String[] {





	"<html>",
	"<head>",
	"",
	"<title>AddressBook</title>",
	"",
	"<style type=\"text/css\">",
	"<!--",
	"a:link {  text-decoration: none}",
	"a:visited {  text-decoration: none}",
	"a:hover {  text-decoration: underline}",
	"-->",
	"</style>",
	"",
	"<script language=\"JavaScript\">",
	"",
	"<!--- Hide me ",
	"// Check input fields and submit form. ",
	"function submitForm(action) {",
	"    // Make sure the userid field is not blank",
	"    if (action == 'Save') {",
	"        if(document.address.name.value.length == 0 ||",
	"           document.address.email.value.length == 0){",
	"            alert(\"The name and email fields should not be blank.\");",
	"            document.address.name.focus();",
	"            return;",
	"        }",
	"    }",
	"    document.address.action.value = action ;",
	"    document.address.submit(); ",
	"    document.address.reset(); ",
	"} ",
	"//End hiding--> ",
	"",
	"",
	"</script>",
	"",
	"</head>",
	"<body bgcolor=\"#FFFFFF\" link=\"#767E9E\" vlink=\"#767E9E\" alink=\"#767E9E\">",
	" ",
	"<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>",
	"    Edit address of Robert Judd",
	"    </b></font></td></tr>",
	"</table>",
	"",
	"<br>",
	"",
	"<form method=\"POST\" name=\"address\" action=\"/servlet/rob.servlets.addressbook.AddressBookServlet\">",
	"",
	"<table>",
	"  <tr>",
	"    <td>Name </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"name\" size=\"20\" value=\"\"></td>",
	"    <td>Email </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"email\" size=\"20\" value=\"\"></td>",
	"  </tr>",
	"  <tr>",
	"    <td>Address (1) </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"address1\" size=\"20\" value=\"\"></td>",
	"    <td>Address (2) </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"address2\" size=\"20\" value=\"\"></td>",
	"  </tr>",
	"  <tr>",
	"    <td>City </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"city\" size=\"20\" value=\"\"></td>",
	"    <td>State </td> ",
	"    <td>",
	"	<input maxlength=\"2\" type=\"text\" name=\"state\" size=\"2\" value=\"\">",
	"	&nbsp; Zip code &nbsp;",
	"	<input maxlength=\"10\" type=\"text\" name=\"zipcode\" size=\"10\" value=\"\">",
	"    </td>",
	"  </tr>",
	"  <tr>",
	"    <td>Telephone </td> ",
	"    <td><input maxlength=\"40\" type=\"text\" name=\"telephone\" size=\"20\" value=\"\"></td>",
	"    <td><input type=\"hidden\" name=\"addressid\" value=\"\"> </td> ",
	"    <td></td>",
	"  </tr>",
	"  <tr>",
	"    <td colspan=2>",
	"    <input type=\"button\" onClick=\"submitForm('Save')\" value=\"Save\">",
	"    &nbsp; &nbsp; ",
	"    <input type=\"button\" onClick=\"submitForm('Delete')\" value=\"Delete\">",
	"    &nbsp; &nbsp; ",
	"    <input type=\"hidden\" name=\"action\" value=\"\">",
	"    <input type=\"button\" onClick=\"reset()\" value=\"Reset\">",
	"    </td>",
	"  </tr>",
	"  <tr>",
	"    <td colspan=4>",
	"	<noscript>",
	"	If your browser does not support JavaScript use these buttons:",
	"	<input type=\"submit\" name=\"action\" value=\"Save\">",
	"	<input type=\"submit\" name=\"action\" value=\"Delete\">",
	"	<input type=\"reset\"  value=\"Reset\">",
	"	</noscript>",
	"    </td>",
	"  </tr>",
	"</table>",
	"",
	"",
	"</form>",
	"<br>",
	"<table border=0 cellspacing=0 cellpadding=10 width=100% bgcolor=\"#767E9E\">",
	"  <tr>",
	"    <td align=right>",
	"    <a href=\"/servlet/rob.servlets.addressbook.AddressBookServlet?action=Log+Out\">",
	"    <font color=\"#C2D7EA\"><b>Log Out</b></font></a>",
	"    </td>",
	"  </tr>",
	"</table>",
	"<br>",
	"<address>",
	"<font color=\"#767E9E\">",
	"Generated by AddressBookServlet Fri Mar  9 16:05:14 2001",
	"</font>",
	"</address>",
	"",
	"</body>",
	"</html>"

    } ;


}// EditPage
