Polishing
This commit is contained in:
parent
8b3afda6f4
commit
52cca48f40
|
@ -29,7 +29,6 @@ import java.util.TimeZone;
|
||||||
import org.springframework.format.Formatter;
|
import org.springframework.format.Formatter;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +44,7 @@ import org.springframework.util.StringUtils;
|
||||||
public class DateFormatter implements Formatter<Date> {
|
public class DateFormatter implements Formatter<Date> {
|
||||||
|
|
||||||
private static final Map<ISO, String> ISO_PATTERNS;
|
private static final Map<ISO, String> ISO_PATTERNS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Map<ISO, String> formats = new HashMap<DateTimeFormat.ISO, String>(4);
|
Map<ISO, String> formats = new HashMap<DateTimeFormat.ISO, String>(4);
|
||||||
formats.put(ISO.DATE, "yyyy-MM-dd");
|
formats.put(ISO.DATE, "yyyy-MM-dd");
|
||||||
|
@ -170,34 +170,36 @@ public class DateFormatter implements Formatter<Date> {
|
||||||
if (StringUtils.hasLength(this.pattern)) {
|
if (StringUtils.hasLength(this.pattern)) {
|
||||||
return new SimpleDateFormat(this.pattern, locale);
|
return new SimpleDateFormat(this.pattern, locale);
|
||||||
}
|
}
|
||||||
if (iso != null && iso != ISO.NONE) {
|
if (this.iso != null && this.iso != ISO.NONE) {
|
||||||
String pattern = ISO_PATTERNS.get(iso);
|
String pattern = ISO_PATTERNS.get(this.iso);
|
||||||
Assert.state(pattern != null, "Unsupported ISO format " + iso);
|
if (pattern == null) {
|
||||||
|
throw new IllegalStateException("Unsupported ISO format " + this.iso);
|
||||||
|
}
|
||||||
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
if(StringUtils.hasLength(stylePattern)) {
|
if (StringUtils.hasLength(this.stylePattern)) {
|
||||||
int dateStyle = getStylePatternForChar(0);
|
int dateStyle = getStylePatternForChar(0);
|
||||||
int timeStyle = getStylePatternForChar(1);
|
int timeStyle = getStylePatternForChar(1);
|
||||||
if(dateStyle != -1 && timeStyle != -1) {
|
if (dateStyle != -1 && timeStyle != -1) {
|
||||||
return DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
|
return DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
|
||||||
}
|
}
|
||||||
if(dateStyle != -1) {
|
if (dateStyle != -1) {
|
||||||
return DateFormat.getDateInstance(dateStyle, locale);
|
return DateFormat.getDateInstance(dateStyle, locale);
|
||||||
}
|
}
|
||||||
if(timeStyle != -1) {
|
if (timeStyle != -1) {
|
||||||
return DateFormat.getTimeInstance(timeStyle, locale);
|
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);
|
return DateFormat.getDateInstance(this.style, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStylePatternForChar(int index) {
|
private int getStylePatternForChar(int index) {
|
||||||
if(stylePattern != null && stylePattern.length() > index) {
|
if (this.stylePattern != null && this.stylePattern.length() > index) {
|
||||||
switch (stylePattern.charAt(index)) {
|
switch (this.stylePattern.charAt(index)) {
|
||||||
case 'S': return DateFormat.SHORT;
|
case 'S': return DateFormat.SHORT;
|
||||||
case 'M': return DateFormat.MEDIUM;
|
case 'M': return DateFormat.MEDIUM;
|
||||||
case 'L': return DateFormat.LONG;
|
case 'L': return DateFormat.LONG;
|
||||||
|
@ -205,7 +207,7 @@ public class DateFormatter implements Formatter<Date> {
|
||||||
case '-': return -1;
|
case '-': return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Unsupported style pattern '"+ stylePattern+ "'");
|
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The HSQL specific implementation of the {@link TableMetaDataProvider}. Suports a feature for
|
* The HSQL specific implementation of the {@link TableMetaDataProvider}.
|
||||||
* retreiving generated keys without the JDBC 3.0 getGeneratedKeys support.
|
* Supports a feature for retreiving generated keys without the JDBC 3.0 getGeneratedKeys support.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
|
@ -32,15 +32,14 @@ public class HsqlTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||||
super(databaseMetaData);
|
super(databaseMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGetGeneratedKeysSimulated() {
|
public boolean isGetGeneratedKeysSimulated() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
|
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
|
||||||
return "select max(identity()) from " + tableName;
|
return "select max(identity()) from " + tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for cookie generation, carrying cookie descriptor settings
|
* Helper class for cookie generation, carrying cookie descriptor settings
|
||||||
* as bean properties and being able to add and remove cookie to/from a
|
* as bean properties and being able to add and remove cookie to/from a
|
||||||
* given response.
|
* given response.
|
||||||
*
|
*
|
||||||
* <p>Can serve as base class for components that generate specific cookies,
|
* <p>Can serve as base class for components that generate specific cookies,
|
||||||
* like CookieLocaleResolcer and CookieThemeResolver.
|
* such as CookieLocaleResolver and CookieThemeResolver.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 1.1.4
|
* @since 1.1.4
|
||||||
|
@ -177,6 +179,7 @@ public class CookieGenerator {
|
||||||
* @see #setCookieMaxAge
|
* @see #setCookieMaxAge
|
||||||
*/
|
*/
|
||||||
public void addCookie(HttpServletResponse response, String cookieValue) {
|
public void addCookie(HttpServletResponse response, String cookieValue) {
|
||||||
|
Assert.notNull(response, "HttpServletResponse must not be null");
|
||||||
Cookie cookie = createCookie(cookieValue);
|
Cookie cookie = createCookie(cookieValue);
|
||||||
Integer maxAge = getCookieMaxAge();
|
Integer maxAge = getCookieMaxAge();
|
||||||
if (maxAge != null) {
|
if (maxAge != null) {
|
||||||
|
@ -204,6 +207,7 @@ public class CookieGenerator {
|
||||||
* @see #setCookiePath
|
* @see #setCookiePath
|
||||||
*/
|
*/
|
||||||
public void removeCookie(HttpServletResponse response) {
|
public void removeCookie(HttpServletResponse response) {
|
||||||
|
Assert.notNull(response, "HttpServletResponse must not be null");
|
||||||
Cookie cookie = createCookie("");
|
Cookie cookie = createCookie("");
|
||||||
cookie.setMaxAge(0);
|
cookie.setMaxAge(0);
|
||||||
response.addCookie(cookie);
|
response.addCookie(cookie);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Enumeration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletRequestWrapper;
|
import javax.servlet.ServletRequestWrapper;
|
||||||
|
@ -199,7 +198,6 @@ public abstract class WebUtils {
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Assert.notNull(servletContext, "ServletContext must not be null");
|
|
||||||
String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
|
String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
|
||||||
return (StringUtils.hasText(param)? Boolean.valueOf(param) : null);
|
return (StringUtils.hasText(param)? Boolean.valueOf(param) : null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.web.servlet;
|
package org.springframework.web.servlet;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -27,22 +26,22 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
* request and response.
|
* request and response.
|
||||||
*
|
*
|
||||||
* <p>This interface allows for implementations based on request, session,
|
* <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.
|
* simply using the request's locale provided by the respective HTTP header.
|
||||||
*
|
*
|
||||||
* <p>Use {@code RequestContext.getLocale()} to retrieve the current locale
|
* <p>Use {@link org.springframework.web.servlet.support.RequestContext#getLocale()}
|
||||||
* in controllers or views, independent of the actual resolution strategy.
|
* to retrieve the current locale in controllers or views, independent
|
||||||
|
* of the actual resolution strategy.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 27.02.2003
|
* @since 27.02.2003
|
||||||
* @see org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
|
|
||||||
* @see org.springframework.web.servlet.support.RequestContext#getLocale
|
|
||||||
*/
|
*/
|
||||||
public interface LocaleResolver {
|
public interface LocaleResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the current locale via the given request.
|
* 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
|
* @param request the request to resolve the locale for
|
||||||
* @return the current locale (never {@code null})
|
* @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 response the response to be used for locale modification
|
||||||
* @param locale the new locale, or {@code null} to clear the locale
|
* @param locale the new locale, or {@code null} to clear the locale
|
||||||
* @throws UnsupportedOperationException if the LocaleResolver implementation
|
* @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);
|
void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale);
|
||||||
|
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.
|
* request and response.
|
||||||
*
|
*
|
||||||
* <p>This interface allows for implementations based on session,
|
* <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.
|
* simply using a configured default theme.
|
||||||
*
|
*
|
||||||
* <p>Note that this resolver is only responsible for determining the
|
* <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,
|
* gets looked up by DispatcherServlet via the respective ThemeSource,
|
||||||
* i.e. the current WebApplicationContext.
|
* i.e. the current WebApplicationContext.
|
||||||
*
|
*
|
||||||
* <p>Use RequestContext.getTheme() to retrieve the current theme in
|
* <p>Use {@link org.springframework.web.servlet.support.RequestContext#getTheme()}
|
||||||
* controllers or views, independent of the actual resolution strategy.
|
* to retrieve the current theme in controllers or views, independent
|
||||||
|
* of the actual resolution strategy.
|
||||||
*
|
*
|
||||||
* @author Jean-Pierre Pawlak
|
* @author Jean-Pierre Pawlak
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 17.06.2003
|
* @since 17.06.2003
|
||||||
* @see org.springframework.web.servlet.theme.FixedThemeResolver
|
|
||||||
* @see org.springframework.ui.context.Theme
|
* @see org.springframework.ui.context.Theme
|
||||||
* @see org.springframework.ui.context.ThemeSource
|
* @see org.springframework.ui.context.ThemeSource
|
||||||
* @see org.springframework.web.servlet.support.RequestContext#getTheme
|
|
||||||
*/
|
*/
|
||||||
public interface ThemeResolver {
|
public interface ThemeResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the current theme name via the given request.
|
* Resolve the current theme name via the given request.
|
||||||
* Should return a default theme as fallback in any case.
|
* Should return a default theme as fallback in any case.
|
||||||
* @param request request to be used for resolution
|
* @param request request to be used for resolution
|
||||||
* @return the current theme name
|
* @return the current theme name
|
||||||
*/
|
*/
|
||||||
String resolveThemeName(HttpServletRequest request);
|
String resolveThemeName(HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current theme name to the given one.
|
* Set the current theme name to the given one.
|
||||||
* @param request request to be used for theme name modification
|
* @param request request to be used for theme name modification
|
||||||
* @param response response to be used for theme name modification
|
* @param response response to be used for theme name modification
|
||||||
* @param themeName the new theme name
|
* @param themeName the new theme name
|
||||||
* @throws UnsupportedOperationException if the ThemeResolver implementation
|
* @throws UnsupportedOperationException if the ThemeResolver implementation
|
||||||
* does not support dynamic changing of the theme
|
* does not support dynamic changing of the theme
|
||||||
*/
|
*/
|
||||||
void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName);
|
void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue