1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
package org.melati.test; |
50 | |
|
51 | |
import java.io.IOException; |
52 | |
import java.io.PrintWriter; |
53 | |
import java.util.Iterator; |
54 | |
|
55 | |
import javax.servlet.ServletException; |
56 | |
|
57 | |
import org.melati.servlet.ConfigServlet; |
58 | |
import org.melati.test.CharData.Item; |
59 | |
import org.melati.Melati; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 1 | public class CharsetServletTest extends ConfigServlet { |
65 | |
private static final long serialVersionUID = 1L; |
66 | |
|
67 | |
protected void doConfiguredRequest(Melati melati) |
68 | |
throws ServletException, IOException { |
69 | |
|
70 | 1 | melati.setResponseContentType("text/html"); |
71 | 1 | PrintWriter w = new PrintWriter(melati.getWriter()); |
72 | 1 | String charset = melati.getResponse().getCharacterEncoding(); |
73 | |
|
74 | 1 | w.println("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>"); |
75 | 1 | w.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""); |
76 | 1 | w.println("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); |
77 | 1 | w.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); |
78 | 1 | w.println("<head>"); |
79 | 1 | w.println("<title>" + getServletName() + "</title>"); |
80 | 1 | w.println("</head>"); |
81 | 1 | w.println("<body>"); |
82 | 1 | w.println("<h1>Characters Displayed in a Servlet</h1>"); |
83 | 1 | w.println("<p>Based on available configuration information Melati" + |
84 | |
" has suggested the response encoding " + charset + |
85 | |
" and we are using it for this test.</p>"); |
86 | 1 | w.println("<p>The test data originally comes from the Unicode Database."); |
87 | 1 | w.println("If you are viewing it online then for copyright information "); |
88 | 1 | w.println("and UCD Terms click here: "); |
89 | 1 | w.println("<a href=\"http://www.unicode.org/unicode/copyright.html\">"); |
90 | 1 | w.println("http://www.unicode.org/unicode/copyright.html</a>."); |
91 | 1 | w.println("Offline please refer to the Javadocs.</p>"); |
92 | 1 | w.println("<table border=\"1\">"); |
93 | 1 | w.println("<thead><tr><th>Description</th><th>Character Reference</th>" + |
94 | |
"<th>Character</th><th>Entitied</th><th>Encoding Test</th></tr></thead>"); |
95 | 1 | w.println("<tbody>"); |
96 | 1 | for (Iterator<Item> i = CharData.getItems(); i.hasNext();) { |
97 | 924 | CharData.Item cd = (CharData.Item)i.next(); |
98 | 924 | w.println("<tr>"); |
99 | 924 | w.println("<td>" + cd.getDescription() + "</td>"); |
100 | 924 | w.println("<td>" + cd.getReference() + "</td>"); |
101 | 924 | w.println("<td>" + cd.getChar() + "</td>"); |
102 | 1848 | w.println("<td>" + melati.getMarkupLanguage().rendered( |
103 | 924 | cd.getChar()) + "</td>"); |
104 | 924 | w.println("<td>" + cd.encodingTest(melati) + "</td>"); |
105 | 924 | w.println("</tr>"); |
106 | 924 | } |
107 | 1 | w.println("</tbody>"); |
108 | 1 | w.println("</table>"); |
109 | 1 | w.println("</body>"); |
110 | 1 | w.println("</html>"); |
111 | 1 | } |
112 | |
|
113 | |
|
114 | |
} |