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.Melati;
59
60
61
62
63 public class CharsetServletTest extends ConfigServlet {
64 private static final long serialVersionUID = 1L;
65
66 protected void doConfiguredRequest(Melati melati)
67 throws ServletException, IOException {
68
69 melati.setResponseContentType("text/html");
70 PrintWriter w = melati.getWriter().getPrintWriter();
71 String charset = melati.getResponse().getCharacterEncoding();
72
73 w.println("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>");
74 w.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
75 w.println("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
76 w.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
77 w.println("<head>");
78 w.println("<title>" + getServletName() + "</title>");
79 w.println("</head>");
80 w.println("<body>");
81 w.println("<h1>Characters Displayed in a Servlet</h1>");
82 w.println("<p>Based on available configuration information Melati" +
83 " has suggested the response encoding " + charset +
84 " and we are using it for this test.</p>");
85 w.println("<p>The test data originally comes from the Unicode Database.");
86 w.println("If you are viewing it online then for copyright information ");
87 w.println("and UCD Terms click here: ");
88 w.println("<a href=\"http://www.unicode.org/unicode/copyright.html\">");
89 w.println("http://www.unicode.org/unicode/copyright.html</a>.");
90 w.println("Offline please refer to the Javadocs.</p>");
91 w.println("<table border=\"1\">");
92 w.println("<thead><tr><th>Description</th><th>Character Reference</th>" +
93 "<th>Character</th><th>Entitied</th><th>Encoding Test</th></tr></thead>");
94 w.println("<tbody>");
95 for (Iterator i = CharData.getItems(); i.hasNext();) {
96 CharData.Item cd = (CharData.Item)i.next();
97 w.println("<tr>");
98 w.println("<td>" + cd.getDescription() + "</td>");
99 w.println("<td>" + cd.getReference() + "</td>");
100 w.println("<td>" + cd.getChar() + "</td>");
101 w.println("<td>" + melati.getMarkupLanguage().rendered(
102 cd.getChar()) + "</td>");
103 w.println("<td>" + cd.encodingTest(melati) + "</td>");
104 w.println("</tr>");
105 }
106 w.println("</tbody>");
107 w.println("</table>");
108 w.println("</body>");
109 w.println("</html>");
110 }
111
112
113 }