1 11 package org.eclipse.update.internal.ui.servlets; 12 13 import java.io.*; 14 import java.util.*; 15 16 import javax.servlet.http.*; 17 18 import org.eclipse.core.boot.*; 19 import org.eclipse.update.internal.ui.*; 20 21 23 public class ServletsUtil { 24 25 public static String getServerInfo(HttpServletRequest servletRequest) { 26 String host = servletRequest.getServerName(); 27 int port = servletRequest.getServerPort(); 28 String context = servletRequest.getContextPath(); 29 30 Enumeration atts = servletRequest.getParameterNames(); 31 StringBuffer buff = new StringBuffer (); 32 for (; atts.hasMoreElements();) { 33 String attName = (String ) atts.nextElement(); 34 Object attValue = servletRequest.getParameter(attName); 35 buff.append(attName + "=" + "\"" + attValue + "\"+"); } 37 return host + ":" + port + context + "?" + buff.toString(); } 39 40 public static PrintWriter createResponsePrologue(HttpServletResponse response) 41 throws IOException { 42 response.setContentType("text/html"); PrintWriter writer = response.getWriter(); 44 String title = UpdateUI.getString("ServletsUtil.responseTitle"); writer.println( 46 "" + "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.0 Transitional//EN\">" + "\n <HTML> \n <HEAD> \n" + "<TITLE>"+title+"</TITLE>\n" + "<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" + "</HEAD>"); writer.println(" <BODY topmargin=\"0\" leftmargin=\"0\">"); return writer; 54 } 55 56 public static void createError( 57 PrintWriter writer, 58 String problem, 59 String resolution) { 60 createHeading(writer, UpdateUI.getString("ServletsUtil.updateFailed")); startTextArea(writer); 62 createParagraph(writer, UpdateUI.getString("ServletsUtil.problem"), problem); if (resolution != null) { 64 writer.println("<p>"); createParagraph(writer, UpdateUI.getString("ServletsUtil.whatToDo"), resolution); } 67 endTextArea(writer); 68 } 69 70 public static void createParagraph( 71 PrintWriter writer, 72 String heading, 73 String text) { 74 writer.print("<b><font color=\"#5B78AC\">"); writer.print(heading); 76 writer.println("</b></font><br>"); writer.println(text); 78 } 79 80 public static void createInfo(PrintWriter writer) { 81 createHeading(writer, UpdateUI.getString("ServletsUtil.updateInProgress")); startTextArea(writer); 83 writer.println( 84 UpdateUI.getString("ServletsUtil.updateInitiated")); endTextArea(writer); 86 } 87 88 private static boolean isWin32() { 89 return BootLoader.getWS().equals("win32"); } 91 92 private static void startTextArea(PrintWriter writer) { 93 writer.println( 94 "<table border=\"0\" width=\"100%\" cellspacing=\"5\" cellpadding=\"5\">"); writer.println("<tr>"); writer.print("<td width=\"100%\">"); if (isWin32()) 98 writer.println("<font face=\"MS Sans Serif\" size=\"1\">"); else 100 writer.println(""); } 102 private static void endTextArea(PrintWriter writer) { 103 if (isWin32()) 104 writer.println("</font>"); writer.println("</td>"); writer.println("</tr>"); writer.println("</table>"); } 109 110 public static void createHeading(PrintWriter writer, String title) { 111 writer.println( 112 "<table cols=1 width=\"588\" cellspacing=\"0\" cellpadding=\"0\">"); writer.println("<tr>"); writer.println( 115 "<td background=\"images/form_banner.jpg\" width=\"580\" height=\"30\">"); writer.print("<p><b><font size=\"3\" face=\"Tahoma\"> "); writer.print(title); 118 writer.println("</font></b></p>"); writer.println("</td>"); writer.println("</tr>"); 122 writer.println("<tr>"); writer.println( 124 "<td width=\"580\"><img border=\"0\" SRC=\"images/form_underline.jpg\" width=\"600\" height=\"15\"></td>"); writer.println("</td>"); writer.println("</tr>"); writer.println("</table>"); } 129 130 public static void createResponseEpilogue( 131 HttpServletRequest request, 132 HttpServletResponse response, 133 PrintWriter writer) { 134 135 String backURL = getOriginatingURL(request); 136 if (backURL != null) { 137 startTextArea(writer); 138 String backText = UpdateUI.getString("ServletsUtil.back"); writer.print("<img border=\"0\" SRC=\"images/backward_nav.gif\"/><a HREF=\""); writer.print(getOriginatingURL(request)); 141 writer.print("\">"+backText+"</a>"); endTextArea(writer); 143 } 144 writer.println(" </BODY> "); writer.println("</HTML>"); writer.close(); 147 } 148 private static String getOriginatingURL(HttpServletRequest request) { 149 return request.getParameter("backURL"); } 151 } 152 | Popular Tags |