|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SetupRequestEncoding.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
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 | * Analyzes the incoming request to set the correct output encoding. | |
30 | * | |
31 | * @author Howard M. Lewis Ship | |
32 | * @since 4.0 | |
33 | */ | |
34 | public class SetupRequestEncoding implements ServletRequestServicerFilter | |
35 | { | |
36 | private boolean _skipSet; | |
37 | ||
38 | private String _outputEncoding; | |
39 | ||
40 | 139 | public void service(HttpServletRequest request, HttpServletResponse response, |
41 | ServletRequestServicer servicer) throws IOException, ServletException | |
42 | { | |
43 | 139 | if (!_skipSet) |
44 | { | |
45 | 137 | String encoding = request.getCharacterEncoding(); |
46 | ||
47 | 137 | if (encoding == null) |
48 | 136 | setRequestEncodingToOutputEncoding(request); |
49 | } | |
50 | ||
51 | // Next in chain | |
52 | ||
53 | 138 | servicer.service(request, response); |
54 | } | |
55 | ||
56 | 136 | private void setRequestEncodingToOutputEncoding(HttpServletRequest request) |
57 | { | |
58 | 136 | try |
59 | { | |
60 | // We compile against the 2.3 API but allow | |
61 | // the code to execute against the 2.2 In the | |
62 | // later case, we can get some interesting errors. | |
63 | ||
64 | 136 | request.setCharacterEncoding(_outputEncoding); |
65 | } | |
66 | catch (UnsupportedEncodingException ex) | |
67 | { | |
68 | 1 | throw new ApplicationRuntimeException( |
69 | ImplMessages.invalidEncoding(_outputEncoding, ex), ex); | |
70 | } | |
71 | catch (NoSuchMethodError ex) | |
72 | { | |
73 | 1 | _skipSet = true; |
74 | } | |
75 | catch (AbstractMethodError ex) | |
76 | { | |
77 | 1 | _skipSet = true; |
78 | } | |
79 | } | |
80 | ||
81 | 46 | public void setOutputEncoding(String outputEncoding) |
82 | { | |
83 | 46 | _outputEncoding = outputEncoding; |
84 | } | |
85 | } |
|