diff --git a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java index c08c80c432fc1b6c47bf9f97af2747d288ca71e4..b11153669b9bd1705840e01ce2345357a0a1e1cd 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java @@ -29,7 +29,6 @@ import java.util.TimeZone; import org.springframework.format.Formatter; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** @@ -45,6 +44,7 @@ import org.springframework.util.StringUtils; public class DateFormatter implements Formatter { private static final Map ISO_PATTERNS; + static { Map formats = new HashMap(4); formats.put(ISO.DATE, "yyyy-MM-dd"); @@ -170,34 +170,36 @@ public class DateFormatter implements Formatter { if (StringUtils.hasLength(this.pattern)) { return new SimpleDateFormat(this.pattern, locale); } - if (iso != null && iso != ISO.NONE) { - String pattern = ISO_PATTERNS.get(iso); - Assert.state(pattern != null, "Unsupported ISO format " + iso); + if (this.iso != null && this.iso != ISO.NONE) { + String pattern = ISO_PATTERNS.get(this.iso); + if (pattern == null) { + throw new IllegalStateException("Unsupported ISO format " + this.iso); + } SimpleDateFormat format = new SimpleDateFormat(pattern); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; } - if(StringUtils.hasLength(stylePattern)) { + if (StringUtils.hasLength(this.stylePattern)) { int dateStyle = getStylePatternForChar(0); int timeStyle = getStylePatternForChar(1); - if(dateStyle != -1 && timeStyle != -1) { + if (dateStyle != -1 && timeStyle != -1) { return DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); } - if(dateStyle != -1) { + if (dateStyle != -1) { return DateFormat.getDateInstance(dateStyle, locale); } - if(timeStyle != -1) { + if (timeStyle != -1) { return DateFormat.getTimeInstance(timeStyle, locale); } - throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'"); + throw new IllegalStateException("Unsupported style pattern '"+ this.stylePattern+ "'"); } return DateFormat.getDateInstance(this.style, locale); } private int getStylePatternForChar(int index) { - if(stylePattern != null && stylePattern.length() > index) { - switch (stylePattern.charAt(index)) { + if (this.stylePattern != null && this.stylePattern.length() > index) { + switch (this.stylePattern.charAt(index)) { case 'S': return DateFormat.SHORT; case 'M': return DateFormat.MEDIUM; case 'L': return DateFormat.LONG; @@ -205,7 +207,7 @@ public class DateFormatter implements Formatter { case '-': return -1; } } - throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'"); + throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'"); } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java index cb6796a2d12efce38310af3b35b51d7708b0cc91..3020a58ee0086d6c31cdd1c715ee8911d8bce874 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; /** - * The HSQL specific implementation of the {@link TableMetaDataProvider}. Suports a feature for - * retreiving generated keys without the JDBC 3.0 getGeneratedKeys support. + * The HSQL specific implementation of the {@link TableMetaDataProvider}. + * Supports a feature for retreiving generated keys without the JDBC 3.0 getGeneratedKeys support. * * @author Thomas Risberg * @since 2.5 @@ -32,15 +32,14 @@ public class HsqlTableMetaDataProvider extends GenericTableMetaDataProvider { super(databaseMetaData); } - @Override public boolean isGetGeneratedKeysSimulated() { return true; } - @Override public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { return "select max(identity()) from " + tableName; } + } diff --git a/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java b/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java index c9662a365bf54e1b21acdc601e1209a7d75e2a21..c79a59e6a219aa51c33b3531ca36f36603176e97 100644 --- a/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java +++ b/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,15 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; + /** * Helper class for cookie generation, carrying cookie descriptor settings * as bean properties and being able to add and remove cookie to/from a * given response. * *

Can serve as base class for components that generate specific cookies, - * like CookieLocaleResolcer and CookieThemeResolver. + * such as CookieLocaleResolver and CookieThemeResolver. * * @author Juergen Hoeller * @since 1.1.4 @@ -177,6 +179,7 @@ public class CookieGenerator { * @see #setCookieMaxAge */ public void addCookie(HttpServletResponse response, String cookieValue) { + Assert.notNull(response, "HttpServletResponse must not be null"); Cookie cookie = createCookie(cookieValue); Integer maxAge = getCookieMaxAge(); if (maxAge != null) { @@ -204,6 +207,7 @@ public class CookieGenerator { * @see #setCookiePath */ public void removeCookie(HttpServletResponse response) { + Assert.notNull(response, "HttpServletResponse must not be null"); Cookie cookie = createCookie(""); cookie.setMaxAge(0); response.addCookie(cookie); diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java index 71f834b87f273505c58b6d1ffd872e07668b9f84..e0078a8a97860e4878684c65c93af27b42b27a4e 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java @@ -22,7 +22,6 @@ import java.util.Enumeration; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; - import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestWrapper; @@ -199,7 +198,6 @@ public abstract class WebUtils { if (servletContext == null) { return null; } - Assert.notNull(servletContext, "ServletContext must not be null"); String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM); return (StringUtils.hasText(param)? Boolean.valueOf(param) : null); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java index d580afe766e80245834455976524536f17cf7e3a..380bdfd397780786d7753e82d76fde8ea87a3ca5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.web.servlet; import java.util.Locale; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -27,22 +26,22 @@ import javax.servlet.http.HttpServletResponse; * request and response. * *

This interface allows for implementations based on request, session, - * cookies, etc. The default implementation is AcceptHeaderLocaleResolver, + * cookies, etc. The default implementation is + * {@link org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver}, * simply using the request's locale provided by the respective HTTP header. * - *

Use {@code RequestContext.getLocale()} to retrieve the current locale - * in controllers or views, independent of the actual resolution strategy. + *

Use {@link org.springframework.web.servlet.support.RequestContext#getLocale()} + * to retrieve the current locale in controllers or views, independent + * of the actual resolution strategy. * * @author Juergen Hoeller * @since 27.02.2003 - * @see org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver - * @see org.springframework.web.servlet.support.RequestContext#getLocale */ public interface LocaleResolver { /** * Resolve the current locale via the given request. - * Should return a default locale as fallback in any case. + * Can return a default locale as fallback in any case. * @param request the request to resolve the locale for * @return the current locale (never {@code null}) */ @@ -54,7 +53,7 @@ public interface LocaleResolver { * @param response the response to be used for locale modification * @param locale the new locale, or {@code null} to clear the locale * @throws UnsupportedOperationException if the LocaleResolver implementation - * does not support dynamic changing of the theme + * does not support dynamic changing of the locale */ void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java index 39c0cbd8b1883b661fb441b27d2cc82e9558cf47..6da2e2afd34d414ec8c063f4abe9874bcc19a51c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,8 @@ import javax.servlet.http.HttpServletResponse; * request and response. * *

This interface allows for implementations based on session, - * cookies, etc. The default implementation is FixedThemeResolver, + * cookies, etc. The default implementation is + * {@link org.springframework.web.servlet.theme.FixedThemeResolver}, * simply using a configured default theme. * *

Note that this resolver is only responsible for determining the @@ -33,35 +34,34 @@ import javax.servlet.http.HttpServletResponse; * gets looked up by DispatcherServlet via the respective ThemeSource, * i.e. the current WebApplicationContext. * - *

Use RequestContext.getTheme() to retrieve the current theme in - * controllers or views, independent of the actual resolution strategy. + *

Use {@link org.springframework.web.servlet.support.RequestContext#getTheme()} + * to retrieve the current theme in controllers or views, independent + * of the actual resolution strategy. * * @author Jean-Pierre Pawlak * @author Juergen Hoeller * @since 17.06.2003 - * @see org.springframework.web.servlet.theme.FixedThemeResolver * @see org.springframework.ui.context.Theme * @see org.springframework.ui.context.ThemeSource - * @see org.springframework.web.servlet.support.RequestContext#getTheme */ public interface ThemeResolver { - /** - * Resolve the current theme name via the given request. - * Should return a default theme as fallback in any case. - * @param request request to be used for resolution - * @return the current theme name - */ + /** + * Resolve the current theme name via the given request. + * Should return a default theme as fallback in any case. + * @param request request to be used for resolution + * @return the current theme name + */ String resolveThemeName(HttpServletRequest request); - /** - * Set the current theme name to the given one. - * @param request request to be used for theme name modification - * @param response response to be used for theme name modification - * @param themeName the new theme name + /** + * Set the current theme name to the given one. + * @param request request to be used for theme name modification + * @param response response to be used for theme name modification + * @param themeName the new theme name * @throws UnsupportedOperationException if the ThemeResolver implementation * does not support dynamic changing of the theme - */ + */ void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName); }