1 16 17 package org.springframework.web.servlet.support; 18 19 import java.util.Locale ; 20 import java.util.Map ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.PageContext ; 24 25 36 public class JspAwareRequestContext extends RequestContext { 37 38 protected static final String PAGE_SCOPE_SUFFIX = ".page"; 39 40 private PageContext pageContext; 41 42 43 48 public JspAwareRequestContext(PageContext pageContext) { 49 initContext(pageContext, null); 50 } 51 52 59 public JspAwareRequestContext(PageContext pageContext, Map model) { 60 initContext(pageContext, model); 61 } 62 63 70 protected void initContext(PageContext pageContext, Map model) { 71 if (!(pageContext.getRequest() instanceof HttpServletRequest )) { 72 throw new IllegalArgumentException ("RequestContext only supports HTTP requests"); 73 } 74 this.pageContext = pageContext; 75 initContext((HttpServletRequest ) pageContext.getRequest(), pageContext.getServletContext(), model); 76 } 77 78 79 83 protected PageContext getPageContext() { 84 return pageContext; 85 } 86 87 92 protected Locale getFallbackLocale() { 93 Locale locale = (Locale ) getPageContext().getAttribute(JSTL_LOCALE_ATTRIBUTE); 94 if (locale == null) { 95 locale = (Locale ) getPageContext().getAttribute(JSTL_LOCALE_ATTRIBUTE + PAGE_SCOPE_SUFFIX); 96 if (locale == null) { 97 locale = super.getFallbackLocale(); 98 } 99 } 100 return locale; 101 } 102 103 } 104 | Popular Tags |