|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover 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 | 155 |
public void service(HttpServletRequest request, HttpServletResponse response, |
41 |
ServletRequestServicer servicer) throws IOException, ServletException
|
|
42 |
{ |
|
43 | 155 |
if (!_skipSet)
|
44 |
{ |
|
45 | 153 |
String encoding = request.getCharacterEncoding(); |
46 |
|
|
47 | 153 |
if (encoding == null) |
48 | 152 |
setRequestEncodingToOutputEncoding(request); |
49 |
} |
|
50 |
|
|
51 |
// Next in chain
|
|
52 |
|
|
53 | 154 |
servicer.service(request, response); |
54 |
} |
|
55 |
|
|
56 | 152 |
private void setRequestEncodingToOutputEncoding(HttpServletRequest request) |
57 |
{ |
|
58 | 152 |
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 | 152 |
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 | 50 |
public void setOutputEncoding(String outputEncoding) |
82 |
{ |
|
83 | 50 |
_outputEncoding = outputEncoding; |
84 |
} |
|
85 |
} |
|