1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.services.impl; |
16 |
| |
17 |
| import java.io.IOException; |
18 |
| import java.io.UnsupportedEncodingException; |
19 |
| |
20 |
| import javax.servlet.ServletException; |
21 |
| import javax.servlet.http.HttpServletRequest; |
22 |
| import javax.servlet.http.HttpServletResponse; |
23 |
| |
24 |
| import org.apache.hivemind.ApplicationRuntimeException; |
25 |
| import org.apache.tapestry.services.ServletRequestServicer; |
26 |
| import org.apache.tapestry.services.ServletRequestServicerFilter; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public class SetupRequestEncoding implements ServletRequestServicerFilter |
35 |
| { |
36 |
| private boolean _skipSet; |
37 |
| |
38 |
| private String _outputEncoding; |
39 |
| |
40 |
260
| public void service(HttpServletRequest request, HttpServletResponse response,
|
41 |
| ServletRequestServicer servicer) throws IOException, ServletException |
42 |
| { |
43 |
260
| if (!_skipSet)
|
44 |
| { |
45 |
256
| String encoding = request.getCharacterEncoding();
|
46 |
| |
47 |
256
| if (encoding == null)
|
48 |
254
| setRequestEncodingToOutputEncoding(request);
|
49 |
| } |
50 |
| |
51 |
| |
52 |
| |
53 |
258
| servicer.service(request, response);
|
54 |
| } |
55 |
| |
56 |
254
| private void setRequestEncodingToOutputEncoding(HttpServletRequest request)
|
57 |
| { |
58 |
254
| try
|
59 |
| { |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
254
| request.setCharacterEncoding(_outputEncoding);
|
65 |
| } |
66 |
| catch (UnsupportedEncodingException ex) |
67 |
| { |
68 |
2
| throw new ApplicationRuntimeException(
|
69 |
| ImplMessages.invalidEncoding(_outputEncoding, ex), ex); |
70 |
| } |
71 |
| catch (NoSuchMethodError ex) |
72 |
| { |
73 |
2
| _skipSet = true;
|
74 |
| } |
75 |
| catch (AbstractMethodError ex) |
76 |
| { |
77 |
2
| _skipSet = true;
|
78 |
| } |
79 |
| } |
80 |
| |
81 |
88
| public void setOutputEncoding(String outputEncoding)
|
82 |
| { |
83 |
88
| _outputEncoding = outputEncoding;
|
84 |
| } |
85 |
| } |