1 package org.apache.myfaces.tobago.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.myfaces.tobago.portlet.PortletUtils;
23
24 import javax.faces.context.FacesContext;
25 import javax.servlet.http.HttpServletRequest;
26 import java.io.UnsupportedEncodingException;
27
28
29
30
31
32 public class RequestUtils {
33
34 private static final Log LOG = LogFactory.getLog(RequestUtils.class);
35
36 public static void ensureEncoding(FacesContext facesContext) {
37 Object requestObject = facesContext.getExternalContext().getRequest();
38 try {
39 if (requestObject instanceof HttpServletRequest) {
40 HttpServletRequest request = (HttpServletRequest) requestObject;
41 if (request.getCharacterEncoding() == null) {
42 request.setCharacterEncoding("UTF-8");
43 }
44 } else if (PortletUtils.isPortletRequest(facesContext)) {
45 PortletUtils.ensureEncoding(facesContext);
46 }
47
48 } catch (UnsupportedEncodingException e) {
49 LOG.error("" + e, e);
50 }
51 }
52 }