Skip to content

Commit 52cca48

Browse files
committed
Polishing
1 parent 8b3afda commit 52cca48

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.format.Formatter;
3030
import org.springframework.format.annotation.DateTimeFormat;
3131
import org.springframework.format.annotation.DateTimeFormat.ISO;
32-
import org.springframework.util.Assert;
3332
import org.springframework.util.StringUtils;
3433

3534
/**
@@ -45,6 +44,7 @@
4544
public class DateFormatter implements Formatter<Date> {
4645

4746
private static final Map<ISO, String> ISO_PATTERNS;
47+
4848
static {
4949
Map<ISO, String> formats = new HashMap<DateTimeFormat.ISO, String>(4);
5050
formats.put(ISO.DATE, "yyyy-MM-dd");
@@ -170,42 +170,44 @@ private DateFormat createDateFormat(Locale locale) {
170170
if (StringUtils.hasLength(this.pattern)) {
171171
return new SimpleDateFormat(this.pattern, locale);
172172
}
173-
if (iso != null && iso != ISO.NONE) {
174-
String pattern = ISO_PATTERNS.get(iso);
175-
Assert.state(pattern != null, "Unsupported ISO format " + iso);
173+
if (this.iso != null && this.iso != ISO.NONE) {
174+
String pattern = ISO_PATTERNS.get(this.iso);
175+
if (pattern == null) {
176+
throw new IllegalStateException("Unsupported ISO format " + this.iso);
177+
}
176178
SimpleDateFormat format = new SimpleDateFormat(pattern);
177179
format.setTimeZone(TimeZone.getTimeZone("UTC"));
178180
return format;
179181
}
180-
if(StringUtils.hasLength(stylePattern)) {
182+
if (StringUtils.hasLength(this.stylePattern)) {
181183
int dateStyle = getStylePatternForChar(0);
182184
int timeStyle = getStylePatternForChar(1);
183-
if(dateStyle != -1 && timeStyle != -1) {
185+
if (dateStyle != -1 && timeStyle != -1) {
184186
return DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
185187
}
186-
if(dateStyle != -1) {
188+
if (dateStyle != -1) {
187189
return DateFormat.getDateInstance(dateStyle, locale);
188190
}
189-
if(timeStyle != -1) {
191+
if (timeStyle != -1) {
190192
return DateFormat.getTimeInstance(timeStyle, locale);
191193
}
192-
throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'");
194+
throw new IllegalStateException("Unsupported style pattern '"+ this.stylePattern+ "'");
193195

194196
}
195197
return DateFormat.getDateInstance(this.style, locale);
196198
}
197199

198200
private int getStylePatternForChar(int index) {
199-
if(stylePattern != null && stylePattern.length() > index) {
200-
switch (stylePattern.charAt(index)) {
201+
if (this.stylePattern != null && this.stylePattern.length() > index) {
202+
switch (this.stylePattern.charAt(index)) {
201203
case 'S': return DateFormat.SHORT;
202204
case 'M': return DateFormat.MEDIUM;
203205
case 'L': return DateFormat.LONG;
204206
case 'F': return DateFormat.FULL;
205207
case '-': return -1;
206208
}
207209
}
208-
throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'");
210+
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
209211
}
210212

211213
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -20,8 +20,8 @@
2020
import java.sql.SQLException;
2121

2222
/**
23-
* The HSQL specific implementation of the {@link TableMetaDataProvider}. Suports a feature for
24-
* retreiving generated keys without the JDBC 3.0 getGeneratedKeys support.
23+
* The HSQL specific implementation of the {@link TableMetaDataProvider}.
24+
* Supports a feature for retreiving generated keys without the JDBC 3.0 getGeneratedKeys support.
2525
*
2626
* @author Thomas Risberg
2727
* @since 2.5
@@ -32,15 +32,14 @@ public HsqlTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLEx
3232
super(databaseMetaData);
3333
}
3434

35-
3635
@Override
3736
public boolean isGetGeneratedKeysSimulated() {
3837
return true;
3938
}
4039

41-
4240
@Override
4341
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
4442
return "select max(identity()) from " + tableName;
4543
}
44+
4645
}

spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -22,13 +22,15 @@
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424

25+
import org.springframework.util.Assert;
26+
2527
/**
2628
* Helper class for cookie generation, carrying cookie descriptor settings
2729
* as bean properties and being able to add and remove cookie to/from a
2830
* given response.
2931
*
3032
* <p>Can serve as base class for components that generate specific cookies,
31-
* like CookieLocaleResolcer and CookieThemeResolver.
33+
* such as CookieLocaleResolver and CookieThemeResolver.
3234
*
3335
* @author Juergen Hoeller
3436
* @since 1.1.4
@@ -177,6 +179,7 @@ public boolean isCookieHttpOnly() {
177179
* @see #setCookieMaxAge
178180
*/
179181
public void addCookie(HttpServletResponse response, String cookieValue) {
182+
Assert.notNull(response, "HttpServletResponse must not be null");
180183
Cookie cookie = createCookie(cookieValue);
181184
Integer maxAge = getCookieMaxAge();
182185
if (maxAge != null) {
@@ -204,6 +207,7 @@ public void addCookie(HttpServletResponse response, String cookieValue) {
204207
* @see #setCookiePath
205208
*/
206209
public void removeCookie(HttpServletResponse response) {
210+
Assert.notNull(response, "HttpServletResponse must not be null");
207211
Cookie cookie = createCookie("");
208212
cookie.setMaxAge(0);
209213
response.addCookie(cookie);

spring-web/src/main/java/org/springframework/web/util/WebUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Map;
2323
import java.util.StringTokenizer;
2424
import java.util.TreeMap;
25-
2625
import javax.servlet.ServletContext;
2726
import javax.servlet.ServletRequest;
2827
import javax.servlet.ServletRequestWrapper;
@@ -199,7 +198,6 @@ public static Boolean getDefaultHtmlEscape(ServletContext servletContext) {
199198
if (servletContext == null) {
200199
return null;
201200
}
202-
Assert.notNull(servletContext, "ServletContext must not be null");
203201
String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
204202
return (StringUtils.hasText(param)? Boolean.valueOf(param) : null);
205203
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet;
1818

1919
import java.util.Locale;
20-
2120
import javax.servlet.http.HttpServletRequest;
2221
import javax.servlet.http.HttpServletResponse;
2322

@@ -27,22 +26,22 @@
2726
* request and response.
2827
*
2928
* <p>This interface allows for implementations based on request, session,
30-
* cookies, etc. The default implementation is AcceptHeaderLocaleResolver,
29+
* cookies, etc. The default implementation is
30+
* {@link org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver},
3131
* simply using the request's locale provided by the respective HTTP header.
3232
*
33-
* <p>Use {@code RequestContext.getLocale()} to retrieve the current locale
34-
* in controllers or views, independent of the actual resolution strategy.
33+
* <p>Use {@link org.springframework.web.servlet.support.RequestContext#getLocale()}
34+
* to retrieve the current locale in controllers or views, independent
35+
* of the actual resolution strategy.
3536
*
3637
* @author Juergen Hoeller
3738
* @since 27.02.2003
38-
* @see org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
39-
* @see org.springframework.web.servlet.support.RequestContext#getLocale
4039
*/
4140
public interface LocaleResolver {
4241

4342
/**
4443
* Resolve the current locale via the given request.
45-
* Should return a default locale as fallback in any case.
44+
* Can return a default locale as fallback in any case.
4645
* @param request the request to resolve the locale for
4746
* @return the current locale (never {@code null})
4847
*/
@@ -54,7 +53,7 @@ public interface LocaleResolver {
5453
* @param response the response to be used for locale modification
5554
* @param locale the new locale, or {@code null} to clear the locale
5655
* @throws UnsupportedOperationException if the LocaleResolver implementation
57-
* does not support dynamic changing of the theme
56+
* does not support dynamic changing of the locale
5857
*/
5958
void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale);
6059

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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,43 +25,43 @@
2525
* request and response.
2626
*
2727
* <p>This interface allows for implementations based on session,
28-
* cookies, etc. The default implementation is FixedThemeResolver,
28+
* cookies, etc. The default implementation is
29+
* {@link org.springframework.web.servlet.theme.FixedThemeResolver},
2930
* simply using a configured default theme.
3031
*
3132
* <p>Note that this resolver is only responsible for determining the
3233
* current theme name. The Theme instance for the resolved theme name
3334
* gets looked up by DispatcherServlet via the respective ThemeSource,
3435
* i.e. the current WebApplicationContext.
3536
*
36-
* <p>Use RequestContext.getTheme() to retrieve the current theme in
37-
* controllers or views, independent of the actual resolution strategy.
37+
* <p>Use {@link org.springframework.web.servlet.support.RequestContext#getTheme()}
38+
* to retrieve the current theme in controllers or views, independent
39+
* of the actual resolution strategy.
3840
*
3941
* @author Jean-Pierre Pawlak
4042
* @author Juergen Hoeller
4143
* @since 17.06.2003
42-
* @see org.springframework.web.servlet.theme.FixedThemeResolver
4344
* @see org.springframework.ui.context.Theme
4445
* @see org.springframework.ui.context.ThemeSource
45-
* @see org.springframework.web.servlet.support.RequestContext#getTheme
4646
*/
4747
public interface ThemeResolver {
4848

49-
/**
50-
* Resolve the current theme name via the given request.
51-
* Should return a default theme as fallback in any case.
52-
* @param request request to be used for resolution
53-
* @return the current theme name
54-
*/
49+
/**
50+
* Resolve the current theme name via the given request.
51+
* Should return a default theme as fallback in any case.
52+
* @param request request to be used for resolution
53+
* @return the current theme name
54+
*/
5555
String resolveThemeName(HttpServletRequest request);
5656

57-
/**
58-
* Set the current theme name to the given one.
59-
* @param request request to be used for theme name modification
60-
* @param response response to be used for theme name modification
61-
* @param themeName the new theme name
57+
/**
58+
* Set the current theme name to the given one.
59+
* @param request request to be used for theme name modification
60+
* @param response response to be used for theme name modification
61+
* @param themeName the new theme name
6262
* @throws UnsupportedOperationException if the ThemeResolver implementation
6363
* does not support dynamic changing of the theme
64-
*/
64+
*/
6565
void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName);
6666

6767
}

0 commit comments

Comments
 (0)