01: /*
02: * $Id: ProcessLocalizationAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: // ------------------------------------------------------------ Constructors
44:
45: /**
46: * Constructor for ProcessOptionsAction.
47: */
48: public ProcessLocalizationAction() {
49: super ();
50: }
51:
52: // ---------------------------------------------------------- Action Methods
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(ActionMapping mapping,
69: ActionForm form, HttpServletRequest request,
70: HttpServletResponse response) throws Exception {
71:
72: // Extract attributes we will need
73: HttpSession session = request.getSession();
74:
75: // Get locale from request, if any
76: Locale locale = request.getLocale();
77:
78: // If supplied, set Locale based on request parameters;
79: // country and language
80: String language = request.getParameter("language");
81: String country = request.getParameter("country");
82:
83: if ((language != null && language.length() > 0)
84: && (country != null && country.length() > 0)) {
85: locale = new java.util.Locale(language, country);
86: } else if (language != null && language.length() > 0) {
87: locale = new java.util.Locale(language, "");
88: }
89:
90: //Save locale
91: session.setAttribute(Globals.LOCALE_KEY, locale);
92:
93: // Forward to result page
94: return mapping.findForward("success");
95: }
96:
97: }
|