提交 52cca48f 编写于 作者: J Juergen Hoeller

Polishing

上级 8b3afda6
......@@ -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<Date> {
private static final Map<ISO, String> ISO_PATTERNS;
static {
Map<ISO, String> formats = new HashMap<DateTimeFormat.ISO, String>(4);
formats.put(ISO.DATE, "yyyy-MM-dd");
......@@ -170,34 +170,36 @@ public class DateFormatter implements Formatter<Date> {
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<Date> {
case '-': return -1;
}
}
throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'");
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
}
}
/*
* 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;
}
}
/*
* 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.
*
* <p>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);
......
......@@ -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);
}
......
/*
* 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.
*
* <p>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.
*
* <p>Use {@code RequestContext.getLocale()} to retrieve the current locale
* in controllers or views, independent of the actual resolution strategy.
* <p>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);
......
/*
* 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.
*
* <p>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.
*
* <p>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.
*
* <p>Use RequestContext.getTheme() to retrieve the current theme in
* controllers or views, independent of the actual resolution strategy.
* <p>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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册