1 18 19 20 package org.apache.struts.webapp.validator; 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 77 public ActionForward execute(ActionMapping mapping, 78 ActionForm form, 79 HttpServletRequest request, 80 HttpServletResponse response) 81 throws Exception { 82 83 HttpSession session = request.getSession(); 85 Locale locale = getLocale(request); 86 87 String language = null; 88 String country = null; 89 String page = null; 90 91 try { 92 language = (String ) 93 PropertyUtils.getSimpleProperty(form, "language"); 94 country = (String ) 95 PropertyUtils.getSimpleProperty(form, "country"); 96 page = (String ) 97 PropertyUtils.getSimpleProperty(form, "page"); 98 } catch (Exception e) { 99 log.error(e.getMessage(), e); 100 } 101 102 if ((language != null && language.length() > 0) && 103 (country != null && country.length() > 0)) { 104 locale = new java.util.Locale (language, country); 105 } else if (language != null && language.length() > 0) { 106 locale = new java.util.Locale (language, ""); 107 } 108 109 session.setAttribute(Globals.LOCALE_KEY, locale); 110 111 if (null==page) return mapping.findForward("success"); 112 else return new ActionForward(page); 113 114 } 115 116 } 117 | Popular Tags |