1 package edu.rice.rubis.beans.servlets; 2 3 import edu.rice.rubis.beans.*; 4 import java.io.PrintWriter ; 5 import java.io.IOException ; 6 import java.io.FileNotFoundException ; 7 import java.io.FileReader ; 8 import javax.servlet.*; 9 import javax.servlet.http.*; 10 import javax.rmi.PortableRemoteObject ; 11 import javax.naming.Context ; 12 import javax.naming.InitialContext ; 13 import java.rmi.RemoteException ; 14 import java.util.GregorianCalendar ; 15 import java.util.Enumeration ; 16 import java.net.URLEncoder ; 17 18 23 24 public class ServletPrinter 25 { 26 private PrintWriter out; 27 private String servletName; 28 private GregorianCalendar startDate; 29 30 31 37 public ServletPrinter(HttpServletResponse toWebServer, String callingServletName) 38 { 39 startDate = new GregorianCalendar (); 40 toWebServer.setContentType("text/html"); 41 try 42 { 43 out = toWebServer.getWriter(); 44 } 45 catch (IOException ioe) 46 { 47 ioe.printStackTrace(); 48 } 49 servletName = callingServletName; 50 } 51 52 void printFile (String filename) 53 { 54 FileReader fis = null; 55 try 56 { 57 fis = new FileReader (filename); 58 char[] data = new char[4*1024]; int bytesRead; 60 bytesRead = fis.read(data); 61 while ( bytesRead != -1) 62 { 63 out.write(data, 0, bytesRead); 64 bytesRead = fis.read(data); 65 } 66 } 67 catch (Exception e) 68 { 69 out.println("Unable to read file (exception: "+e+")<br>\n"); 70 } 71 finally 72 { 73 if (fis != null) 74 try 75 { 76 fis.close(); 77 } 78 catch (Exception ex) 79 { 80 out.println("Unable to close the file reader (exception: "+ex+")<br>\n"); 81 } 82 } 83 } 84 85 void printHTMLheader(String title) 86 { 87 printFile(Config.HTMLFilesPath+"/header.html"); 88 out.println("<title>"+title+"</title>\n"); 89 } 90 91 void printHTMLfooter() 92 { 93 GregorianCalendar endDate = new GregorianCalendar (); 94 95 out.println("<br><hr>RUBiS (C) Rice University/INRIA<br><i>Page generated by "+servletName+" in "+TimeManagement.diffTime(startDate, endDate)+"</i><br>\n"); 96 out.println("</body>\n"); 97 out.println("</html>\n"); 98 } 99 100 void printHTML(String msg) 101 { 102 out.println(msg); 103 } 104 105 void printHTMLHighlighted(String msg) 106 { 107 out.println("<TABLE width=\"100%\" bgcolor=\"#CCCCFF\">\n"); 108 out.println("<TR><TD align=\"center\" width=\"100%\"><FONT size=\"4\" color=\"#000000\"><B>"+msg+"</B></FONT></TD></TR>\n"); 109 out.println("</TABLE><p>\n"); 110 } 111 112 113 114 void printItemHeader() 115 { 116 out.println("<TABLE border=\"1\" summary=\"List of items\">\n"+ 117 "<THEAD>\n"+ 118 "<TR><TH>Designation<TH>Price<TH>Bids<TH>End Date<TH>Bid Now\n"+ 119 "<TBODY>\n"); 120 } 121 122 123 void printItemFooter(String URLprevious, String URLafter) 124 { 125 out.println("</TABLE>\n"); 126 out.println("<p><CENTER>\n"+URLprevious+"\n   "+URLafter+"\n</CENTER>\n"); 127 } 128 129 134 void printItemFooter() 135 { 136 out.println("</TABLE>\n"); 137 } 138 139 140 141 } 142 | Popular Tags |