1 18 19 20 package org.apache.struts.actions; 21 22 import java.util.Locale ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.apache.commons.beanutils.PropertyUtils; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.struts.Globals; 32 import org.apache.struts.action.Action; 33 import org.apache.struts.action.ActionForm; 34 import org.apache.struts.action.ActionForward; 35 import org.apache.struts.action.ActionMapping; 36 37 38 44 public final class LocaleAction extends Action { 45 46 49 private Log log = LogFactory.getFactory().getInstance(this.getClass().getName()); 50 51 78 public ActionForward execute(ActionMapping mapping, 79 ActionForm form, 80 HttpServletRequest request, 81 HttpServletResponse response) 82 throws Exception { 83 84 HttpSession session = request.getSession(); 86 Locale locale = getLocale(request); 87 88 String language = null; 89 String country = null; 90 String page = null; 91 92 try { 93 language = (String ) 94 PropertyUtils.getSimpleProperty(form, "language"); 95 country = (String ) 96 PropertyUtils.getSimpleProperty(form, "country"); 97 page = (String ) 98 PropertyUtils.getSimpleProperty(form, "page"); 99 } catch (Exception e) { 100 log.error(e.getMessage(), e); 101 } 102 103 boolean isLanguage = (language != null && language.length() > 0); 104 boolean isCountry = (country != null && country.length() > 0); 105 106 if ((isLanguage) && (isCountry)) { 107 locale = new java.util.Locale (language, country); 108 } else if (isLanguage) { 109 locale = new java.util.Locale (language, ""); 110 } 111 112 session.setAttribute(Globals.LOCALE_KEY, locale); 113 114 if (null==page) return mapping.findForward("success"); 115 else return new ActionForward(page); 116 117 } 118 119 } 120 | Popular Tags |