1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Locale ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 29 import org.apache.struts.Globals; 30 import org.apache.struts.action.Action; 31 import org.apache.struts.action.ActionErrors; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 36 37 44 45 public final class SetLocaleAction extends Action { 46 47 48 50 51 66 public ActionForward execute(ActionMapping mapping, 67 ActionForm form, 68 HttpServletRequest request, 69 HttpServletResponse response) 70 throws IOException , ServletException { 71 72 String requestedLocale = ((SetLocaleForm) form).getLocale(); 74 75 if (requestedLocale != null) { 77 ApplicationLocales locales = (ApplicationLocales) 78 getServlet().getServletContext().getAttribute 79 (ApplicationServlet.LOCALES_KEY); 80 Iterator iterator = locales.getSupportedLocales().iterator(); 81 Locale currentLocale = null; 82 while (iterator.hasNext()) { 83 currentLocale = (Locale ) iterator.next(); 84 if (requestedLocale.equals(currentLocale.toString())) { 85 HttpSession session = request.getSession(); 86 session.setAttribute(Globals.LOCALE_KEY, currentLocale); 87 session.removeAttribute(mapping.getAttribute()); 89 break; 90 } 91 } 92 } 93 94 return (mapping.findForward("Main Menu")); 96 97 } 98 99 100 } 101 | Popular Tags |