author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 17 May 2010 15:31:00 -0700 | |
changeset 336 | 131c321bf080 |
parent 191 | 61c04b3eb3e7 |
permissions | -rw-r--r-- |
191
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
// |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
// $Id: check.java,v 1.14 2009-02-24 21:45:14 ylafon Exp $ |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
// |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
// (c) COPYRIGHT MIT and INRIA, 1997. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
// Please first read the full copyright statement in file COPYRIGHT.html |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
package org.w3c.css.servlet; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
import java.io.IOException; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
import java.net.URLEncoder; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
import java.util.Enumeration; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
import javax.servlet.ServletConfig; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
import javax.servlet.ServletException; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
import javax.servlet.http.HttpServlet; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
import javax.servlet.http.HttpServletRequest; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
import javax.servlet.http.HttpServletResponse; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
/** |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
* This class is a servlet to use the validator. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
* |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
* @version $Revision: 1.14 $ |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
*/ |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
public final class check extends HttpServlet { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
private static String validatorURI = null; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
/** |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
* Performs the HTTP GET operation. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
* It redirects to the value contained in "Referer" |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
35 |
* |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
* @param req encapsulates the request to the servlet. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
* @param resp encapsulates the response from the servlet. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
* @exception ServletException if the request could not be handled. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
* @exception IOException if detected when handling the request. |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
*/ |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
public void doGet(HttpServletRequest req, HttpServletResponse res) |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
throws ServletException, IOException |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
{ |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
String uri = req.getHeader("Referer"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
String encodeEnc = req.getCharacterEncoding(); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
if (encodeEnc == null) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
48 |
encodeEnc = "8859_1"; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
uri = URLEncoder.encode(uri, encodeEnc); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
if (uri == null) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
res.setContentType("text/plain"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
res.sendError(400, "Referer field empty"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
return; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
res.setHeader("Cache-Control", "max-age=86400"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
res.setHeader("Vary", "Referer"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
Enumeration e = req.getParameterNames(); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
StringBuilder sb = new StringBuilder(validatorURI); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
boolean first = true; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
boolean uridone = false; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
65 |
if (e != null) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
while (e.hasMoreElements()) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
String paramname = (String) e.nextElement(); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
68 |
String paramvalue = req.getParameter(paramname); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
if ("uri".equals(paramname)) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
uridone = true; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
paramvalue = uri; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
if (first) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
74 |
sb.append('?'); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
75 |
first = false; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
76 |
} else { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
sb.append('&'); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
79 |
sb.append(paramname); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
if (paramvalue != null) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
sb.append('='); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
sb.append(paramvalue); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
86 |
if (!uridone) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
if (first) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
88 |
sb.append("?uri="); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
89 |
} else { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
90 |
sb.append("&uri="); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
sb.append(uri); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
res.sendRedirect(sb.toString()); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
|
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
public void init(ServletConfig config) throws ServletException { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
super.init(config); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
if (config.getInitParameter("validatorURI") == null) { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
validatorURI = "validator"; |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
} else { |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
validatorURI = config.getInitParameter("validatorURI"); |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
103 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
104 |
} |
61c04b3eb3e7
Bug 2001 - css validator to separate plug-in
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
} |