1
1
/*
2
- * Copyright 2002-2015 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.
@@ -79,9 +79,35 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver {
79
79
public static final String TIME_ZONE_SESSION_ATTRIBUTE_NAME = SessionLocaleResolver .class .getName () + ".TIME_ZONE" ;
80
80
81
81
82
+ private String localeAttributeName = LOCALE_SESSION_ATTRIBUTE_NAME ;
83
+
84
+ private String timeZoneAttributeName = TIME_ZONE_SESSION_ATTRIBUTE_NAME ;
85
+
86
+
87
+ /**
88
+ * Specify the name of the corresponding attribute in the {@code HttpSession},
89
+ * holding the current {@link Locale} value.
90
+ * <p>The default is an internal {@link #LOCALE_SESSION_ATTRIBUTE_NAME}.
91
+ * @since 4.3.8
92
+ */
93
+ public void setLocaleAttributeName (String localeAttributeName ) {
94
+ this .localeAttributeName = localeAttributeName ;
95
+ }
96
+
97
+ /**
98
+ * Specify the name of the corresponding attribute in the {@code HttpSession},
99
+ * holding the current {@link TimeZone} value.
100
+ * <p>The default is an internal {@link #TIME_ZONE_SESSION_ATTRIBUTE_NAME}.
101
+ * @since 4.3.8
102
+ */
103
+ public void setTimeZoneAttributeName (String timeZoneAttributeName ) {
104
+ this .timeZoneAttributeName = timeZoneAttributeName ;
105
+ }
106
+
107
+
82
108
@ Override
83
109
public Locale resolveLocale (HttpServletRequest request ) {
84
- Locale locale = (Locale ) WebUtils .getSessionAttribute (request , LOCALE_SESSION_ATTRIBUTE_NAME );
110
+ Locale locale = (Locale ) WebUtils .getSessionAttribute (request , this . localeAttributeName );
85
111
if (locale == null ) {
86
112
locale = determineDefaultLocale (request );
87
113
}
@@ -93,15 +119,15 @@ public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
93
119
return new TimeZoneAwareLocaleContext () {
94
120
@ Override
95
121
public Locale getLocale () {
96
- Locale locale = (Locale ) WebUtils .getSessionAttribute (request , LOCALE_SESSION_ATTRIBUTE_NAME );
122
+ Locale locale = (Locale ) WebUtils .getSessionAttribute (request , localeAttributeName );
97
123
if (locale == null ) {
98
124
locale = determineDefaultLocale (request );
99
125
}
100
126
return locale ;
101
127
}
102
128
@ Override
103
129
public TimeZone getTimeZone () {
104
- TimeZone timeZone = (TimeZone ) WebUtils .getSessionAttribute (request , TIME_ZONE_SESSION_ATTRIBUTE_NAME );
130
+ TimeZone timeZone = (TimeZone ) WebUtils .getSessionAttribute (request , timeZoneAttributeName );
105
131
if (timeZone == null ) {
106
132
timeZone = determineDefaultTimeZone (request );
107
133
}
@@ -120,8 +146,8 @@ public void setLocaleContext(HttpServletRequest request, HttpServletResponse res
120
146
timeZone = ((TimeZoneAwareLocaleContext ) localeContext ).getTimeZone ();
121
147
}
122
148
}
123
- WebUtils .setSessionAttribute (request , LOCALE_SESSION_ATTRIBUTE_NAME , locale );
124
- WebUtils .setSessionAttribute (request , TIME_ZONE_SESSION_ATTRIBUTE_NAME , timeZone );
149
+ WebUtils .setSessionAttribute (request , this . localeAttributeName , locale );
150
+ WebUtils .setSessionAttribute (request , this . timeZoneAttributeName , timeZone );
125
151
}
126
152
127
153
0 commit comments