1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
72
72
* @see org.springframework.web.servlet.DispatcherServlet
73
73
* @see org.springframework.web.servlet.view.AbstractView#setRequestContextAttribute
74
74
* @see org.springframework.web.servlet.view.UrlBasedViewResolver#setRequestContextAttribute
75
- * @see #getFallbackLocale()
76
75
*/
77
76
public class RequestContext {
78
77
@@ -91,8 +90,8 @@ public class RequestContext {
91
90
public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = RequestContext .class .getName () + ".CONTEXT" ;
92
91
93
92
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 ());
96
95
97
96
private HttpServletRequest request ;
98
97
@@ -276,56 +275,6 @@ else if (localeResolver != null) {
276
275
}
277
276
}
278
277
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
-
329
278
330
279
/**
331
280
* Return the underlying HttpServletRequest. Only intended for cooperating classes in this package.
@@ -383,6 +332,39 @@ public TimeZone getTimeZone() {
383
332
return this .timeZone ;
384
333
}
385
334
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
+
386
368
/**
387
369
* Change the current locale to the specified one,
388
370
* storing the new locale through the configured {@link LocaleResolver}.
@@ -434,6 +416,23 @@ public Theme getTheme() {
434
416
return this .theme ;
435
417
}
436
418
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
+
437
436
/**
438
437
* Change the current theme to the specified one,
439
438
* storing the new theme name through the configured {@link ThemeResolver}.
@@ -870,7 +869,8 @@ else if (!htmlEscape && errors instanceof EscapedErrors) {
870
869
}
871
870
872
871
/**
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.
874
874
* @param modelName the name of the model object
875
875
* @return the model object
876
876
*/
0 commit comments