01 package com.bea.medrec.actions;
02
03 import com.bea.medrec.utils.MedRecLog4jFactory;
04 import java.util.Locale;
05 import javax.servlet.http.Cookie;
06 import javax.servlet.http.HttpServletRequest;
07 import javax.servlet.http.HttpServletResponse;
08 import org.apache.log4j.Logger;
09 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12
13 /**
14 * <p>Controller to handle setting of user's locale.</p>
15 *
16 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
17 */
18 public class ChangeLocaleAction extends BaseAction {
19 private static Logger logger = MedRecLog4jFactory.getLogger(ChangeLocaleAction.class.getName());
20
21 /**
22 * <p>Process the specified HTTP request, and create the corresponding HTTP
23 * response (or forward to another web component that will create it).
24 * Return an <code>ActionForward</code> instance describing where and how
25 * control should be forwarded.
26 * </p>
27 *
28 * @param mapping The ActionMapping used to select this instance
29 * @param form The optional ActionForm bean for this request (if any)
30 * @param request The HTTP request we are processing
31 * @param response The HTTP response we are creating
32 */
33 public ActionForward executeAction(ActionMapping mapping,
34 ActionForm form,
35 HttpServletRequest request,
36 HttpServletResponse response)
37 throws Exception {
38
39 String language = (String)request.getParameter("Language");
40 String country = (String)request.getParameter("Country");
41
42 logger.debug("Changing to " + language + ", " + country);
43
44 Locale newLocale = new Locale(language, country);
45 setLocale(request, newLocale);
46
47 Cookie languageCookie = new Cookie("Language", language);
48 Cookie countryCookie = new Cookie("Country", country);
49 languageCookie.setMaxAge(Integer.MAX_VALUE);
50 countryCookie.setMaxAge(Integer.MAX_VALUE);
51 response.addCookie(languageCookie);
52 response.addCookie(countryCookie);
53
54 return mapping.findForward("medrec.startpage");
55 }
56 }
|