01: /*
02: Mdarad-Toolobox is a collection of tools for Architected RAD
03: (Rapid Application Development) based on an MDA approach.
04: The toolbox contains frameworks and generators for many environments
05: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
06: applications from a design Model
07: Copyright (C) 2004-2005 Elapse Technologies Inc.
08:
09: This library is free software; you can redistribute it and/or
10: modify it under the terms of the GNU General Public
11: License as published by the Free Software Foundation; either
12: version 2.1 of the License, or (at your option) any later version.
13:
14: This library is distributed in the hope that it will be useful,
15: but WITHOUT ANY WARRANTY; without even the implied warranty of
16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: General Public License for more details.
18:
19: You should have received a copy of the GNU General Public
20: License along with this library; if not, write to the Free Software
21: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: */
23: package org.mdarad.framework.util.struts;
24:
25: import org.apache.struts.action.ActionForm;
26: import org.apache.struts.action.ActionForward;
27: import org.apache.struts.action.ActionMapping;
28:
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.http.HttpServletResponse;
31: import java.util.List;
32: import java.util.Locale;
33:
34: public class SwitchLocaleAction extends AbstractAction {
35: /**
36: * @see org.apache.struts.action.Action#execute
37: */
38: public ActionForward execute(ActionMapping actionMapping,
39: ActionForm actionForm,
40: HttpServletRequest httpServletRequest,
41: HttpServletResponse httpServletResponse) throws Exception {
42: String localeString = httpServletRequest.getParameter("locale");
43:
44: if (!(localeString == null || "".equals(localeString))) {
45: Locale locale = new Locale(localeString);
46: org.dataisland.primitives.bean.LocalizationContext localizationContext = StrutsLocalizationUtils
47: .getLocalizationContext(httpServletRequest);
48: List locales = localizationContext.getLocales();
49: if (locales.contains(locale)) {
50: locales.remove(locale);
51: }
52: locales.add(0, locale);
53: }
54:
55: org.mdarad.framework.util.struts.StrutsLocalizationUtils
56: .processLocale(httpServletRequest,
57: WEB_CONTEXT_LOCALIZATION_CONTEXT_KEY);
58:
59: return forwardDisplay(actionMapping, actionForm,
60: httpServletRequest, httpServletResponse);
61: }
62: }
|