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 | 0 | public class SetupRequestEncoding implements ServletRequestServicerFilter |
35 | |
{ |
36 | |
private boolean _skipSet; |
37 | |
|
38 | |
private String _outputEncoding; |
39 | |
|
40 | |
public void service(HttpServletRequest request, HttpServletResponse response, |
41 | |
ServletRequestServicer servicer) throws IOException, ServletException |
42 | |
{ |
43 | 0 | if (!_skipSet) |
44 | |
{ |
45 | 0 | String encoding = request.getCharacterEncoding(); |
46 | |
|
47 | 0 | if (encoding == null) |
48 | 0 | setRequestEncodingToOutputEncoding(request); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | 0 | servicer.service(request, response); |
54 | 0 | } |
55 | |
|
56 | |
private void setRequestEncodingToOutputEncoding(HttpServletRequest request) |
57 | |
{ |
58 | |
try |
59 | |
{ |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | request.setCharacterEncoding(_outputEncoding); |
65 | |
} |
66 | 0 | catch (UnsupportedEncodingException ex) |
67 | |
{ |
68 | 0 | throw new ApplicationRuntimeException( |
69 | |
ImplMessages.invalidEncoding(_outputEncoding, ex), ex); |
70 | |
} |
71 | 0 | catch (NoSuchMethodError ex) |
72 | |
{ |
73 | 0 | _skipSet = true; |
74 | |
} |
75 | 0 | catch (AbstractMethodError ex) |
76 | |
{ |
77 | 0 | _skipSet = true; |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | |
public void setOutputEncoding(String outputEncoding) |
82 | |
{ |
83 | 0 | _outputEncoding = outputEncoding; |
84 | 0 | } |
85 | |
} |