01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * See the License for the specific language governing rights and
10: * limitations under the License.
11: *
12: * The Initial Developer of the Original Code is John King .
13: * Portions created by John King are Copyright (C) John King, 2003.
14: *
15: * All Rights Reserved.
16: *
17: * Contributor(s): John King, Simulacra Media Ltd
18: *
19: * Created: 02-Dec-2004 by jejking
20: * Version: $Revision: 1.1 $
21: * Last Updated: $Date: 2004/12/07 12:25:48 $
22: */
23: package org.openharmonise.rm.view.servlet.utils;
24:
25: import java.io.*;
26: import javax.servlet.*;
27: import javax.servlet.http.*;
28:
29: /**
30: * Simple filter that checks whether a response has a character encoding set,
31: * and if it doesn't, sets that to UTF8.
32: * @author jejking
33: * @version $Revision: 1.1 $
34: */
35: public class CharsetFilter implements Filter {
36:
37: /** Creates a new instance of CharSetFilter */
38: public CharsetFilter() {
39: }
40:
41: public void destroy() {
42: }
43:
44: public void doFilter(ServletRequest servletRequest,
45: ServletResponse servletResponse, FilterChain filterChain)
46: throws IOException, ServletException {
47:
48: HttpServletRequest req = (HttpServletRequest) servletRequest;
49: if (req.getCharacterEncoding() == null
50: || req.getCharacterEncoding().equals("")) {
51: try {
52: req.setCharacterEncoding("UTF-8");
53: } catch (UnsupportedEncodingException uee) {
54: throw new ServletException(uee);
55: }
56: }
57: filterChain.doFilter(servletRequest, servletResponse);
58: }
59:
60: public void init(javax.servlet.FilterConfig filterConfig)
61: throws javax.servlet.ServletException {
62: }
63:
64: }
|