KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > util > struts > SwitchLocaleAction


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     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 JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Locale JavaDoc;
33
34 public class SwitchLocaleAction extends AbstractAction {
35     /**
36      * @see org.apache.struts.action.Action#execute
37      */

38     public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest JavaDoc httpServletRequest, HttpServletResponse JavaDoc httpServletResponse) throws Exception JavaDoc {
39         String JavaDoc localeString = httpServletRequest.getParameter("locale");
40
41         if (!(localeString == null || "".equals(localeString))) {
42             Locale JavaDoc locale = new Locale JavaDoc(localeString);
43             org.dataisland.primitives.bean.LocalizationContext localizationContext = StrutsLocalizationUtils.getLocalizationContext(httpServletRequest);
44             List JavaDoc locales = localizationContext.getLocales();
45             if (locales.contains(locale)) {
46                 locales.remove(locale);
47             }
48             locales.add(0, locale);
49         }
50
51         org.mdarad.framework.util.struts.StrutsLocalizationUtils.processLocale(httpServletRequest, WEB_CONTEXT_LOCALIZATION_CONTEXT_KEY);
52
53         return forwardDisplay(actionMapping, actionForm, httpServletRequest, httpServletResponse);
54     }
55 }
56
Popular Tags