import java.util.*;
import java.io.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HtmlGen
{ 

  
  HtmlGen() {}

  public static int AddHtmlHeader(String fname,String title, 
                           String heading,String imgUrl)
  {  
    try
    {
     FileOutputStream fos = new FileOutputStream(fname);
     DataOutputStream dos = new DataOutputStream(fos);
     dos.writeBytes("<HTML> \n <HEAD> \n <TITLE> "+ title );
     dos.writeBytes(" </TITLE> \n</HEAD>\n");
     dos.writeBytes("\n <BODY> ");
     dos.writeBytes("<IMG SRC=\""+imgUrl+"\" ALIGN=RIGHT ></IMG>\n");
    dos.writeBytes(" <br> <br> \n <center> <H1> " + heading + " </H1> </center>\n");
    dos.close();
    return 1;
    }

    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }

  public static int AddHtmlHeader(PrintWriter out,String title,String heading,
			 String imgUrl)
  {  
    try
    { out.println("<HTML> \n <HEAD> \n <TITLE> "+ title);
      out.println(" </TITLE> \n</HEAD>\n ");
      out.println(" \n <BODY> ");
      out.println(" <IMG SRC=\""+imgUrl+"\" ALIGN=RIGHT ></IMG>\n");
      out.println("<br><br> \n <center> <H1> " + heading + "</H1> </center>\n");
      return 1;
    }

    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }


 public static int AddFormHead(String actionUrl, String method,String fname)
 { try
   { FileOutputStream fos = new FileOutputStream(fname,true);
     DataOutputStream dos = new DataOutputStream(fos);
     dos.writeBytes("\n <FORM action="+actionUrl+" method="+method+">");
     dos.close();
     return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }

 public static int AddFormHead(String actionUrl, String method, PrintWriter out)
 { try
   { out.println("\n <FORM action="+actionUrl+" method="+method+">");
     return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }

 public static int AddFormTail(String fname) 
 { try
   { FileOutputStream fos = new FileOutputStream(fname,true);
     DataOutputStream dos = new DataOutputStream(fos);
     dos.writeBytes("\n </FORM>");
     dos.close();
     return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }

 }

 public static int AddFormTail(PrintWriter out)
 { try
   { out.println("\n /FORM> ");
     return 1;
   } 
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }


 public static int AddSubmit(String name, String val,String fname)
 { try
   { FileOutputStream fos = new FileOutputStream(fname,true);
     DataOutputStream dos = new DataOutputStream(fos);
    dos.writeBytes("\n <input type=submit value="+val+" name="+name+">");
     dos.close();
    return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }

 public static int AddSubmit(String name, String val, PrintWriter out)
 { try
   { out.println("\n <input type=submit value="+val+" name="+name+">");
     return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }

 public static int AddReset(String name, String val,String fname)
  { try
     { FileOutputStream fos = new FileOutputStream(fname,true);
       DataOutputStream dos = new DataOutputStream(fos);
      dos.writeBytes("\n <input type=reset value="+val+" name="+name+">");
      return 1;
     }
     catch(Exception e)
     { System.out.println(e.getMessage());
       e.printStackTrace();
       return -1;
     }
  }

  public static int AddReset(String name, String val, PrintWriter out)
  { try
    { out.println("\n <input type=reset value="+val+" name="+name+">");
      return 1;
    } 
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }
      

  public static int AddText(String name, int size, int maxlen,String fname)
  { try
    { FileOutputStream fos = new FileOutputStream(fname,true);
      DataOutputStream dos = new DataOutputStream(fos);
      dos.writeBytes("\n <input type=text size="+size+" maxlength="+maxlen+" name="+name+">");
      dos.close();
      return 1;
    }
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }

  public static int AddText(String name, int size, int maxlen, PrintWriter out)
  { try
    { out.println("\n <input type=text size="+size+" maxlength="+maxlen+" name="+name+">");
      return 1;
    }
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }

  public static int AddPasswd(String name, int size, int maxlen ,String fname)
  { try
    { FileOutputStream fos = new FileOutputStream(fname,true);
      DataOutputStream dos = new DataOutputStream(fos);
    dos.writeBytes("\n<input type=password size="+size+" maxlength="+maxlen+" name="+name+">");
      dos.close();
      return 1;
    }
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  }
	
  public static int AddPasswd(String name, int size, int maxlen, PrintWriter out)
  { try
    { out.println("\n<input type=password size="+size+" maxlength="+maxlen+" name="+name+">");
      return 1;
    }
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
 }


  public static int AddHtmlFooter(String fname)
  { try
    { FileOutputStream fos = new FileOutputStream(fname,true);
      DataOutputStream dos = new DataOutputStream(fos);
      dos.writeBytes("\n </BODY> ");
      dos.writeBytes("\n </HTML> ");
      dos.close();
      return 1;
    }
    catch(Exception e)
    { System.out.println(e.getMessage());
      e.printStackTrace();
      return -1;
    }
  } 

 public static int AddHtmlFooter(PrintWriter out)
 { try
   { out.println("\n </BODY> ");
     out.println("\n </HTML> ");
     return 1;
   }
   catch(Exception e)
   { System.out.println(e.getMessage());
     e.printStackTrace();
     return -1;
   }
 }


}
      
