1 16 17 package org.springframework.web.servlet.i18n; 18 19 import java.util.Locale ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 24 import org.springframework.web.util.WebUtils; 25 26 42 public class SessionLocaleResolver extends AbstractLocaleResolver { 43 44 52 public static final String LOCALE_SESSION_ATTRIBUTE_NAME = SessionLocaleResolver.class.getName() + ".LOCALE"; 53 54 55 public Locale resolveLocale(HttpServletRequest request) { 56 Locale locale = (Locale ) WebUtils.getSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME); 57 if (locale == null) { 58 locale = determineDefaultLocale(request); 59 } 60 return locale; 61 } 62 63 73 protected Locale determineDefaultLocale(HttpServletRequest request) { 74 Locale defaultLocale = getDefaultLocale(); 75 if (defaultLocale == null) { 76 defaultLocale = request.getLocale(); 77 } 78 return defaultLocale; 79 } 80 81 public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { 82 WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale); 83 } 84 85 } 86 | Popular Tags |