11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2017 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
7272 * @see org.springframework.web.servlet.DispatcherServlet
7373 * @see org.springframework.web.servlet.view.AbstractView#setRequestContextAttribute
7474 * @see org.springframework.web.servlet.view.UrlBasedViewResolver#setRequestContextAttribute
75- * @see #getFallbackLocale()
7675 */
7776public class RequestContext {
7877
@@ -91,8 +90,8 @@ public class RequestContext {
9190 public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = RequestContext .class .getName () + ".CONTEXT" ;
9291
9392
94- protected static final boolean jstlPresent = ClassUtils .isPresent ("javax.servlet.jsp.jstl.core.Config" ,
95- RequestContext .class .getClassLoader ());
93+ protected static final boolean jstlPresent = ClassUtils .isPresent (
94+ "javax.servlet.jsp.jstl.core.Config" , RequestContext .class .getClassLoader ());
9695
9796 private HttpServletRequest request ;
9897
@@ -276,56 +275,6 @@ else if (localeResolver != null) {
276275 }
277276 }
278277
279- /**
280- * Determine the fallback locale for this context.
281- * <p>The default implementation checks for a JSTL locale attribute in request, session
282- * or application scope; if not found, returns the {@code HttpServletRequest.getLocale()}.
283- * @return the fallback locale (never {@code null})
284- * @see javax.servlet.http.HttpServletRequest#getLocale()
285- */
286- protected Locale getFallbackLocale () {
287- if (jstlPresent ) {
288- Locale locale = JstlLocaleResolver .getJstlLocale (getRequest (), getServletContext ());
289- if (locale != null ) {
290- return locale ;
291- }
292- }
293- return getRequest ().getLocale ();
294- }
295-
296- /**
297- * Determine the fallback time zone for this context.
298- * <p>The default implementation checks for a JSTL time zone attribute in request,
299- * session or application scope; returns {@code null} if not found.
300- * @return the fallback time zone (or {@code null} if none derivable from the request)
301- */
302- protected TimeZone getFallbackTimeZone () {
303- if (jstlPresent ) {
304- TimeZone timeZone = JstlLocaleResolver .getJstlTimeZone (getRequest (), getServletContext ());
305- if (timeZone != null ) {
306- return timeZone ;
307- }
308- }
309- return null ;
310- }
311-
312- /**
313- * Determine the fallback theme for this context.
314- * <p>The default implementation returns the default theme (with name "theme").
315- * @return the fallback theme (never {@code null})
316- */
317- protected Theme getFallbackTheme () {
318- ThemeSource themeSource = RequestContextUtils .getThemeSource (getRequest ());
319- if (themeSource == null ) {
320- themeSource = new ResourceBundleThemeSource ();
321- }
322- Theme theme = themeSource .getTheme (DEFAULT_THEME_NAME );
323- if (theme == null ) {
324- throw new IllegalStateException ("No theme defined and no fallback theme found" );
325- }
326- return theme ;
327- }
328-
329278
330279 /**
331280 * Return the underlying HttpServletRequest. Only intended for cooperating classes in this package.
@@ -383,6 +332,39 @@ public TimeZone getTimeZone() {
383332 return this .timeZone ;
384333 }
385334
335+ /**
336+ * Determine the fallback locale for this context.
337+ * <p>The default implementation checks for a JSTL locale attribute in request, session
338+ * or application scope; if not found, returns the {@code HttpServletRequest.getLocale()}.
339+ * @return the fallback locale (never {@code null})
340+ * @see javax.servlet.http.HttpServletRequest#getLocale()
341+ */
342+ protected Locale getFallbackLocale () {
343+ if (jstlPresent ) {
344+ Locale locale = JstlLocaleResolver .getJstlLocale (getRequest (), getServletContext ());
345+ if (locale != null ) {
346+ return locale ;
347+ }
348+ }
349+ return getRequest ().getLocale ();
350+ }
351+
352+ /**
353+ * Determine the fallback time zone for this context.
354+ * <p>The default implementation checks for a JSTL time zone attribute in request,
355+ * session or application scope; returns {@code null} if not found.
356+ * @return the fallback time zone (or {@code null} if none derivable from the request)
357+ */
358+ protected TimeZone getFallbackTimeZone () {
359+ if (jstlPresent ) {
360+ TimeZone timeZone = JstlLocaleResolver .getJstlTimeZone (getRequest (), getServletContext ());
361+ if (timeZone != null ) {
362+ return timeZone ;
363+ }
364+ }
365+ return null ;
366+ }
367+
386368 /**
387369 * Change the current locale to the specified one,
388370 * storing the new locale through the configured {@link LocaleResolver}.
@@ -434,6 +416,23 @@ public Theme getTheme() {
434416 return this .theme ;
435417 }
436418
419+ /**
420+ * Determine the fallback theme for this context.
421+ * <p>The default implementation returns the default theme (with name "theme").
422+ * @return the fallback theme (never {@code null})
423+ */
424+ protected Theme getFallbackTheme () {
425+ ThemeSource themeSource = RequestContextUtils .getThemeSource (getRequest ());
426+ if (themeSource == null ) {
427+ themeSource = new ResourceBundleThemeSource ();
428+ }
429+ Theme theme = themeSource .getTheme (DEFAULT_THEME_NAME );
430+ if (theme == null ) {
431+ throw new IllegalStateException ("No theme defined and no fallback theme found" );
432+ }
433+ return theme ;
434+ }
435+
437436 /**
438437 * Change the current theme to the specified one,
439438 * storing the new theme name through the configured {@link ThemeResolver}.
@@ -870,7 +869,8 @@ else if (!htmlEscape && errors instanceof EscapedErrors) {
870869 }
871870
872871 /**
873- * Retrieve the model object for the given model name, either from the model or from the request attributes.
872+ * Retrieve the model object for the given model name, either from the model
873+ * or from the request attributes.
874874 * @param modelName the name of the model object
875875 * @return the model object
876876 */
0 commit comments