Skip to content

Commit 73acab7

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java
2 parents 4191958 + e276737 commit 73acab7

File tree

10 files changed

+99
-78
lines changed

10 files changed

+99
-78
lines changed

spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -37,9 +37,9 @@ public class SimpleLocaleContext implements LocaleContext {
3737

3838

3939
/**
40-
* Create a new SimpleLocaleContext that exposes the specified Locale.
41-
* Every {@link #getLocale()} call will return this Locale.
42-
* @param locale the Locale to expose, or {@code null} for no specific one
40+
* Create a new {@code SimpleLocaleContext} that exposes the specified {@link Locale}.
41+
* <p>Every {@link #getLocale()} call will return this locale.
42+
* @param locale the {@code Locale} to expose, or {@code null} for no specific one
4343
*/
4444
public SimpleLocaleContext(@Nullable Locale locale) {
4545
this.locale = locale;

spring-core/src/main/java/org/springframework/util/unit/DataSize.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -52,11 +52,6 @@
5252
@SuppressWarnings("serial")
5353
public final class DataSize implements Comparable<DataSize>, Serializable {
5454

55-
/**
56-
* The pattern for parsing.
57-
*/
58-
private static final Pattern PATTERN = Pattern.compile("^([+\\-]?\\d+)([a-zA-Z]{0,2})$");
59-
6055
/**
6156
* Bytes per Kilobyte.
6257
*/
@@ -179,9 +174,9 @@ public static DataSize parse(CharSequence text) {
179174
public static DataSize parse(CharSequence text, @Nullable DataUnit defaultUnit) {
180175
Assert.notNull(text, "Text must not be null");
181176
try {
182-
Matcher matcher = PATTERN.matcher(text);
177+
Matcher matcher = DataSizeUtils.PATTERN.matcher(text);
183178
Assert.state(matcher.matches(), "Does not match data size pattern");
184-
DataUnit unit = determineDataUnit(matcher.group(2), defaultUnit);
179+
DataUnit unit = DataSizeUtils.determineDataUnit(matcher.group(2), defaultUnit);
185180
long amount = Long.parseLong(matcher.group(1));
186181
return DataSize.of(amount, unit);
187182
}
@@ -190,11 +185,6 @@ public static DataSize parse(CharSequence text, @Nullable DataUnit defaultUnit)
190185
}
191186
}
192187

193-
private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) {
194-
DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES);
195-
return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse);
196-
}
197-
198188
/**
199189
* Checks if this size is negative, excluding zero.
200190
* @return true if this size has a size less than zero bytes
@@ -271,4 +261,23 @@ public int hashCode() {
271261
return Long.hashCode(this.bytes);
272262
}
273263

264+
265+
/**
266+
* Static nested class to support lazy loading of the {@link #PATTERN}.
267+
* @since 5.3.21
268+
*/
269+
private static class DataSizeUtils {
270+
271+
/**
272+
* The pattern for parsing.
273+
*/
274+
private static final Pattern PATTERN = Pattern.compile("^([+\\-]?\\d+)([a-zA-Z]{0,2})$");
275+
276+
private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) {
277+
DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES);
278+
return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse);
279+
}
280+
281+
}
282+
274283
}

spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleContextResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -25,7 +25,7 @@
2525
import org.springframework.lang.Nullable;
2626

2727
/**
28-
* Extension of {@link LocaleResolver}, adding support for a rich locale context
28+
* Extension of {@link LocaleResolver} that adds support for a rich locale context
2929
* (potentially including locale and time zone information).
3030
*
3131
* @author Juergen Hoeller

spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -55,7 +55,7 @@ public interface LocaleResolver {
5555

5656
/**
5757
* Resolve the current locale via the given request.
58-
* Can return a default locale as fallback in any case.
58+
* <p>Can return a default locale as fallback in any case.
5959
* @param request the request to resolve the locale for
6060
* @return the current locale (never {@code null})
6161
*/

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleContextResolver.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -28,7 +28,9 @@
2828

2929
/**
3030
* Abstract base class for {@link LocaleContextResolver} implementations.
31-
* Provides support for a default locale and a default time zone.
31+
*
32+
* <p>Provides support for a {@linkplain #setDefaultLocale(Locale) default locale}
33+
* and a {@linkplain #setDefaultTimeZone(TimeZone) default time zone}.
3234
*
3335
* <p>Also provides pre-implemented versions of {@link #resolveLocale} and {@link #setLocale},
3436
* delegating to {@link #resolveLocaleContext} and {@link #setLocaleContext}.
@@ -45,14 +47,16 @@ public abstract class AbstractLocaleContextResolver extends AbstractLocaleResolv
4547

4648

4749
/**
48-
* Set a default TimeZone that this resolver will return if no other time zone found.
50+
* Set a default {@link TimeZone} that this resolver will return if no other
51+
* time zone is found.
4952
*/
5053
public void setDefaultTimeZone(@Nullable TimeZone defaultTimeZone) {
5154
this.defaultTimeZone = defaultTimeZone;
5255
}
5356

5457
/**
55-
* Return the default TimeZone that this resolver is supposed to fall back to, if any.
58+
* Get the default {@link TimeZone} that this resolver is supposed to fall
59+
* back to, if any.
5660
*/
5761
@Nullable
5862
public TimeZone getDefaultTimeZone() {

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleResolver.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -23,7 +23,8 @@
2323

2424
/**
2525
* Abstract base class for {@link LocaleResolver} implementations.
26-
* Provides support for a default locale.
26+
*
27+
* <p>Provides support for a {@linkplain #setDefaultLocale(Locale) default locale}.
2728
*
2829
* @author Juergen Hoeller
2930
* @since 1.2.9
@@ -36,14 +37,16 @@ public abstract class AbstractLocaleResolver implements LocaleResolver {
3637

3738

3839
/**
39-
* Set a default Locale that this resolver will return if no other locale found.
40+
* Set a default {@link Locale} that this resolver will return if no other
41+
* locale is found.
4042
*/
4143
public void setDefaultLocale(@Nullable Locale defaultLocale) {
4244
this.defaultLocale = defaultLocale;
4345
}
4446

4547
/**
46-
* Return the default Locale that this resolver is supposed to fall back to, if any.
48+
* Get the default {@link Locale} that this resolver is supposed to fall back
49+
* to, if any.
4750
*/
4851
@Nullable
4952
protected Locale getDefaultLocale() {

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -30,11 +30,11 @@
3030

3131
/**
3232
* {@link LocaleResolver} implementation that simply uses the primary locale
33-
* specified in the "accept-language" header of the HTTP request (that is,
33+
* specified in the {@code Accept-Language} header of the HTTP request (that is,
3434
* the locale sent by the client browser, normally that of the client's OS).
3535
*
36-
* <p>Note: Does not support {@code setLocale}, since the accept header
37-
* can only be changed through changing the client's locale settings.
36+
* <p>Note: Does not support {@link #setLocale} since the {@code Accept-Language}
37+
* header can only be changed by changing the client's locale settings.
3838
*
3939
* @author Juergen Hoeller
4040
* @author Rossen Stoyanchev
@@ -62,7 +62,7 @@ public void setSupportedLocales(List<Locale> locales) {
6262
}
6363

6464
/**
65-
* Return the configured list of supported locales.
65+
* Get the configured list of supported locales.
6666
* @since 4.3
6767
*/
6868
public List<Locale> getSupportedLocales() {
@@ -140,7 +140,7 @@ else if (languageMatch == null) {
140140
@Override
141141
public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) {
142142
throw new UnsupportedOperationException(
143-
"Cannot change HTTP accept header - use a different locale resolution strategy");
143+
"Cannot change HTTP Accept-Language header - use a different locale resolution strategy");
144144
}
145145

146146
}

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
/**
3838
* {@link LocaleResolver} implementation that uses a cookie sent back to the user
39-
* in case of a custom setting, with a fallback to the specified default locale
40-
* or the request's accept-header locale.
39+
* in case of a custom setting, with a fallback to the configured default locale,
40+
* the request's {@code Accept-Language} header, or the default locale for the server.
4141
*
4242
* <p>This is particularly useful for stateless applications without user sessions.
4343
* The cookie may optionally contain an associated time zone value as well;
@@ -96,8 +96,8 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
9696

9797

9898
/**
99-
* Create a new instance of the {@link CookieLocaleResolver} class
100-
* using the {@link #DEFAULT_COOKIE_NAME default cookie name}.
99+
* Create a new instance of {@link CookieLocaleResolver} using the
100+
* {@linkplain #DEFAULT_COOKIE_NAME default cookie name}.
101101
*/
102102
public CookieLocaleResolver() {
103103
setCookieName(DEFAULT_COOKIE_NAME);
@@ -153,14 +153,14 @@ public boolean isRejectInvalidCookies() {
153153
}
154154

155155
/**
156-
* Set a fixed locale that this resolver will return if no cookie found.
156+
* Set a fixed locale that this resolver will return if no cookie is found.
157157
*/
158158
public void setDefaultLocale(@Nullable Locale defaultLocale) {
159159
this.defaultLocale = defaultLocale;
160160
}
161161

162162
/**
163-
* Return the fixed locale that this resolver will return if no cookie found,
163+
* Return the fixed locale that this resolver will return if no cookie is found,
164164
* if any.
165165
*/
166166
@Nullable
@@ -169,15 +169,15 @@ protected Locale getDefaultLocale() {
169169
}
170170

171171
/**
172-
* Set a fixed time zone that this resolver will return if no cookie found.
172+
* Set a fixed time zone that this resolver will return if no cookie is found.
173173
* @since 4.0
174174
*/
175175
public void setDefaultTimeZone(@Nullable TimeZone defaultTimeZone) {
176176
this.defaultTimeZone = defaultTimeZone;
177177
}
178178

179179
/**
180-
* Return the fixed time zone that this resolver will return if no cookie found,
180+
* Return the fixed time zone that this resolver will return if no cookie is found,
181181
* if any.
182182
* @since 4.0
183183
*/
@@ -326,10 +326,11 @@ protected String toLocaleValue(Locale locale) {
326326
}
327327

328328
/**
329-
* Determine the default locale for the given request,
330-
* Called if no locale cookie has been found.
331-
* <p>The default implementation returns the specified default locale,
332-
* if any, else falls back to the request's accept-header locale.
329+
* Determine the default locale for the given request, called if no locale
330+
* cookie has been found.
331+
* <p>The default implementation returns the configured default locale, if any,
332+
* and otherwise falls back to the request's {@code Accept-Language} header
333+
* locale or the default locale for the server.
333334
* @param request the request to resolve the locale for
334335
* @return the default locale (never {@code null})
335336
* @see #setDefaultLocale
@@ -344,9 +345,9 @@ protected Locale determineDefaultLocale(HttpServletRequest request) {
344345
}
345346

346347
/**
347-
* Determine the default time zone for the given request,
348-
* Called if no time zone cookie has been found.
349-
* <p>The default implementation returns the specified default time zone,
348+
* Determine the default time zone for the given request, called if no locale
349+
* cookie has been found.
350+
* <p>The default implementation returns the configured default time zone,
350351
* if any, or {@code null} otherwise.
351352
* @param request the request to resolve the time zone for
352353
* @return the default time zone (or {@code null} if none defined)

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -30,8 +30,8 @@
3030
/**
3131
* {@link org.springframework.web.servlet.LocaleResolver} implementation that
3232
* uses a locale attribute in the user's session in case of a custom setting,
33-
* with a fallback to the specified default locale or the request's
34-
* accept-header locale.
33+
* with a fallback to the configured default locale, the request's
34+
* {@code Accept-Language} header, or the default locale for the server.
3535
*
3636
* <p>This is most appropriate if the application needs user sessions anyway,
3737
* i.e. when the {@code HttpSession} does not have to be created just for storing
@@ -61,8 +61,8 @@
6161
public class SessionLocaleResolver extends AbstractLocaleContextResolver {
6262

6363
/**
64-
* Name of the session attribute that holds the Locale.
65-
* Only used internally by this implementation.
64+
* Default name of the session attribute that holds the Locale.
65+
* <p>Only used internally by this implementation.
6666
* <p>Use {@code RequestContext(Utils).getLocale()}
6767
* to retrieve the current locale in controllers or views.
6868
* @see org.springframework.web.servlet.support.RequestContext#getLocale
@@ -71,8 +71,8 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver {
7171
public static final String LOCALE_SESSION_ATTRIBUTE_NAME = SessionLocaleResolver.class.getName() + ".LOCALE";
7272

7373
/**
74-
* Name of the session attribute that holds the TimeZone.
75-
* Only used internally by this implementation.
74+
* Default name of the session attribute that holds the TimeZone.
75+
* <p>Only used internally by this implementation.
7676
* <p>Use {@code RequestContext(Utils).getTimeZone()}
7777
* to retrieve the current time zone in controllers or views.
7878
* @see org.springframework.web.servlet.support.RequestContext#getTimeZone
@@ -157,10 +157,12 @@ public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletRe
157157

158158

159159
/**
160-
* Determine the default locale for the given request,
161-
* Called if no Locale session attribute has been found.
162-
* <p>The default implementation returns the specified default locale,
163-
* if any, else falls back to the request's accept-header locale.
160+
* Determine the default locale for the given request, called if no
161+
* {@link Locale} session attribute has been found.
162+
* <p>The default implementation returns the configured
163+
* {@linkplain #setDefaultLocale(Locale) default locale}, if any, and otherwise
164+
* falls back to the request's {@code Accept-Language} header locale or the
165+
* default locale for the server.
164166
* @param request the request to resolve the locale for
165167
* @return the default locale (never {@code null})
166168
* @see #setDefaultLocale
@@ -175,9 +177,9 @@ protected Locale determineDefaultLocale(HttpServletRequest request) {
175177
}
176178

177179
/**
178-
* Determine the default time zone for the given request,
179-
* Called if no TimeZone session attribute has been found.
180-
* <p>The default implementation returns the specified default time zone,
180+
* Determine the default time zone for the given request, called if no
181+
* {@link TimeZone} session attribute has been found.
182+
* <p>The default implementation returns the configured default time zone,
181183
* if any, or {@code null} otherwise.
182184
* @param request the request to resolve the time zone for
183185
* @return the default time zone (or {@code null} if none defined)

0 commit comments

Comments
 (0)