1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package examples.localization;
23
24 import java.util.Locale;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.http.HttpSession;
29
30 import org.apache.struts.Globals;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36 /**
37 * Retrieve and process data from the submitted form
38 *
39 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
40 */
41 public class ProcessLocalizationAction extends Action {
42
43
44
45 /**
46 * Constructor for ProcessOptionsAction.
47 */
48 public ProcessLocalizationAction() {
49 super();
50 }
51
52
53
54 /**
55 * Process the request and return an <code>ActionForward</code> instance
56 * describing where and how control should be forwarded, or
57 * <code>null</code>if the response has already been completed.
58 *
59 * @param mapping The ActionMapping used to select this instance
60 * @param form The optional ActionForm bean for this request (if any)
61 * @param request The HTTP request we are processing
62 * @param response The HTTP response we are creating
63 *
64 * @exception Exception if the application logic throws an exception
65 *
66 * @return the ActionForward for the next view
67 */
68 public ActionForward execute(
69 ActionMapping mapping,
70 ActionForm form,
71 HttpServletRequest request,
72 HttpServletResponse response)
73 throws Exception {
74
75
76 HttpSession session = request.getSession();
77
78
79 Locale locale = request.getLocale();
80
81
82
83 String language = request.getParameter("language");
84 String country = request.getParameter("country");
85
86 if ((language != null && language.length() > 0)
87 && (country != null && country.length() > 0)) {
88 locale = new java.util.Locale(language, country);
89 } else if (language != null && language.length() > 0) {
90 locale = new java.util.Locale(language, "");
91 }
92
93
94 session.setAttribute(Globals.LOCALE_KEY, locale);
95
96
97 return mapping.findForward("success");
98 }
99
100 }