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 |
5 |
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 |
7 |
if (!_skipSet) |
44 |
|
{ |
45 |
5 |
String encoding = request.getCharacterEncoding(); |
46 |
|
|
47 |
5 |
if (encoding == null) |
48 |
4 |
setRequestEncodingToOutputEncoding(request); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
6 |
servicer.service(request, response); |
54 |
6 |
} |
55 |
|
|
56 |
|
private void setRequestEncodingToOutputEncoding(HttpServletRequest request) |
57 |
|
{ |
58 |
|
try |
59 |
|
{ |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
4 |
request.setCharacterEncoding(_outputEncoding); |
65 |
|
} |
66 |
1 |
catch (UnsupportedEncodingException ex) |
67 |
|
{ |
68 |
1 |
throw new ApplicationRuntimeException( |
69 |
|
ImplMessages.invalidEncoding(_outputEncoding, ex), ex); |
70 |
|
} |
71 |
1 |
catch (NoSuchMethodError ex) |
72 |
|
{ |
73 |
1 |
_skipSet = true; |
74 |
|
} |
75 |
1 |
catch (AbstractMethodError ex) |
76 |
|
{ |
77 |
1 |
_skipSet = true; |
78 |
2 |
} |
79 |
3 |
} |
80 |
|
|
81 |
|
public void setOutputEncoding(String outputEncoding) |
82 |
|
{ |
83 |
5 |
_outputEncoding = outputEncoding; |
84 |
5 |
} |
85 |
|
} |