1 24 package org.riotfamily.website.i18n; 25 26 import java.util.Locale ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.springframework.util.Assert; 32 import org.springframework.web.servlet.LocaleResolver; 33 import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; 34 35 39 public abstract class ChainedLocaleResolver implements LocaleResolver { 40 41 private LocaleResolver fallbackResolver = new AcceptHeaderLocaleResolver(); 42 43 public void setFallbackResolver(LocaleResolver fallbackResolver) { 44 Assert.notNull(fallbackResolver, "Fallback LocaleResolver must not be null"); 45 this.fallbackResolver = fallbackResolver; 46 } 47 48 public final Locale resolveLocale(HttpServletRequest request) { 49 Locale locale = resolveLocaleInternal(request); 50 if (locale == null) { 51 locale = fallbackResolver.resolveLocale(request); 52 } 53 return locale; 54 } 55 56 protected abstract Locale resolveLocaleInternal(HttpServletRequest request); 57 58 public final void setLocale(HttpServletRequest request, 59 HttpServletResponse response, Locale locale) { 60 61 if (!setLocaleInternal(request, response, locale)) { 62 fallbackResolver.setLocale(request, response, locale); 63 } 64 } 65 66 protected boolean setLocaleInternal(HttpServletRequest request, 67 HttpServletResponse response, Locale locale) { 68 69 return false; 70 } 71 } 72 | Popular Tags |