KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > servlets > ServletsUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
22  */

23 public class ServletsUtil {
24
25     public static String JavaDoc getServerInfo(HttpServletRequest servletRequest) {
26         String JavaDoc host = servletRequest.getServerName();
27         int port = servletRequest.getServerPort();
28         String JavaDoc context = servletRequest.getContextPath();
29
30         Enumeration atts = servletRequest.getParameterNames();
31         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
32         for (; atts.hasMoreElements();) {
33             String JavaDoc attName = (String JavaDoc) atts.nextElement();
34             Object JavaDoc attValue = servletRequest.getParameter(attName);
35             buff.append(attName + "=" + "\"" + attValue + "\"+"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
36
}
37         return host + ":" + port + context + "?" + buff.toString(); //$NON-NLS-1$ //$NON-NLS-2$
38
}
39
40     public static PrintWriter createResponsePrologue(HttpServletResponse response)
41         throws IOException {
42         response.setContentType("text/html"); //$NON-NLS-1$
43
PrintWriter writer = response.getWriter();
44         String JavaDoc title = UpdateUI.getString("ServletsUtil.responseTitle"); //$NON-NLS-1$
45
writer.println(
46             "" //$NON-NLS-1$
47
+ "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.0 Transitional//EN\">" //$NON-NLS-1$
48
+ "\n <HTML> \n <HEAD> \n" //$NON-NLS-1$
49
+ "<TITLE>"+title+"</TITLE>\n" //$NON-NLS-1$ //$NON-NLS-2$
50
+ "<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" //$NON-NLS-1$
51
+ "</HEAD>"); //$NON-NLS-1$
52
writer.println(" <BODY topmargin=\"0\" leftmargin=\"0\">"); //$NON-NLS-1$
53
return writer;
54     }
55
56     public static void createError(
57         PrintWriter writer,
58         String JavaDoc problem,
59         String JavaDoc resolution) {
60         createHeading(writer, UpdateUI.getString("ServletsUtil.updateFailed")); //$NON-NLS-1$
61
startTextArea(writer);
62         createParagraph(writer, UpdateUI.getString("ServletsUtil.problem"), problem); //$NON-NLS-1$
63
if (resolution != null) {
64             writer.println("<p>"); //$NON-NLS-1$
65
createParagraph(writer, UpdateUI.getString("ServletsUtil.whatToDo"), resolution); //$NON-NLS-1$
66
}
67         endTextArea(writer);
68     }
69
70     public static void createParagraph(
71         PrintWriter writer,
72         String JavaDoc heading,
73         String JavaDoc text) {
74         writer.print("<b><font color=\"#5B78AC\">"); //$NON-NLS-1$
75
writer.print(heading);
76         writer.println("</b></font><br>"); //$NON-NLS-1$
77
writer.println(text);
78     }
79
80     public static void createInfo(PrintWriter writer) {
81         createHeading(writer, UpdateUI.getString("ServletsUtil.updateInProgress")); //$NON-NLS-1$
82
startTextArea(writer);
83         writer.println(
84             UpdateUI.getString("ServletsUtil.updateInitiated")); //$NON-NLS-1$
85
endTextArea(writer);
86     }
87     
88     private static boolean isWin32() {
89         return BootLoader.getWS().equals("win32"); //$NON-NLS-1$
90
}
91
92     private static void startTextArea(PrintWriter writer) {
93         writer.println(
94             "<table border=\"0\" width=\"100%\" cellspacing=\"5\" cellpadding=\"5\">"); //$NON-NLS-1$
95
writer.println("<tr>"); //$NON-NLS-1$
96
writer.print("<td width=\"100%\">"); //$NON-NLS-1$
97
if (isWin32())
98             writer.println("<font face=\"MS Sans Serif\" size=\"1\">"); //$NON-NLS-1$
99
else
100             writer.println(""); //$NON-NLS-1$
101
}
102     private static void endTextArea(PrintWriter writer) {
103         if (isWin32())
104             writer.println("</font>"); //$NON-NLS-1$
105
writer.println("</td>"); //$NON-NLS-1$
106
writer.println("</tr>"); //$NON-NLS-1$
107
writer.println("</table>"); //$NON-NLS-1$
108
}
109
110     public static void createHeading(PrintWriter writer, String JavaDoc title) {
111         writer.println(
112             "<table cols=1 width=\"588\" cellspacing=\"0\" cellpadding=\"0\">"); //$NON-NLS-1$
113
writer.println("<tr>"); //$NON-NLS-1$
114
writer.println(
115             "<td background=\"images/form_banner.jpg\" width=\"580\" height=\"30\">"); //$NON-NLS-1$
116
writer.print("<p><b><font size=\"3\" face=\"Tahoma\">&nbsp;"); //$NON-NLS-1$
117
writer.print(title);
118         writer.println("</font></b></p>"); //$NON-NLS-1$
119
writer.println("</td>"); //$NON-NLS-1$
120
writer.println("</tr>"); //$NON-NLS-1$
121

122         writer.println("<tr>"); //$NON-NLS-1$
123
writer.println(
124             "<td width=\"580\"><img border=\"0\" SRC=\"images/form_underline.jpg\" width=\"600\" height=\"15\"></td>"); //$NON-NLS-1$
125
writer.println("</td>"); //$NON-NLS-1$
126
writer.println("</tr>"); //$NON-NLS-1$
127
writer.println("</table>"); //$NON-NLS-1$
128
}
129
130     public static void createResponseEpilogue(
131         HttpServletRequest request,
132         HttpServletResponse response,
133         PrintWriter writer) {
134
135         String JavaDoc backURL = getOriginatingURL(request);
136         if (backURL != null) {
137             startTextArea(writer);
138             String JavaDoc backText = UpdateUI.getString("ServletsUtil.back"); //$NON-NLS-1$
139
writer.print("<img border=\"0\" SRC=\"images/backward_nav.gif\"/><a HREF=\""); //$NON-NLS-1$
140
writer.print(getOriginatingURL(request));
141             writer.print("\">"+backText+"</a>"); //$NON-NLS-1$ //$NON-NLS-2$
142
endTextArea(writer);
143         }
144         writer.println(" </BODY> "); //$NON-NLS-1$
145
writer.println("</HTML>"); //$NON-NLS-1$
146
writer.close();
147     }
148     private static String JavaDoc getOriginatingURL(HttpServletRequest request) {
149         return request.getParameter("backURL"); //$NON-NLS-1$
150
}
151 }
152
Popular Tags