Polishing

This commit is contained in:
Juergen Hoeller
2016-06-02 17:02:44 +02:00
parent ae11387b4a
commit 521c41d75e
13 changed files with 58 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -43,11 +43,9 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.2
*/
public abstract class AbstractMappingContentNegotiationStrategy
extends MappingMediaTypeFileExtensionResolver
public abstract class AbstractMappingContentNegotiationStrategy extends MappingMediaTypeFileExtensionResolver
implements ContentNegotiationStrategy {
/**
* Create an instance with the given map of file extensions and media types.
*/
@@ -86,6 +84,7 @@ public abstract class AbstractMappingContentNegotiationStrategy
return Collections.emptyList();
}
/**
* Extract a key from the request to use to look up media types.
* @return the lookup key or {@code null}.

View File

@@ -41,18 +41,14 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.2
*/
public class ContentNegotiationManager implements ContentNegotiationStrategy,
MediaTypeFileExtensionResolver {
public class ContentNegotiationManager implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver {
private static final List<MediaType> MEDIA_TYPE_ALL =
Collections.<MediaType>singletonList(MediaType.ALL);
private static final List<MediaType> MEDIA_TYPE_ALL = Collections.<MediaType>singletonList(MediaType.ALL);
private final List<ContentNegotiationStrategy> strategies =
new ArrayList<ContentNegotiationStrategy>();
private final List<ContentNegotiationStrategy> strategies = new ArrayList<ContentNegotiationStrategy>();
private final Set<MediaTypeFileExtensionResolver> resolvers =
new LinkedHashSet<MediaTypeFileExtensionResolver>();
private final Set<MediaTypeFileExtensionResolver> resolvers = new LinkedHashSet<MediaTypeFileExtensionResolver>();
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -40,34 +40,34 @@ import org.springframework.web.context.ServletContextAware;
*
* <table>
* <tr>
* <th>Property Setter</th>
* <th>Underlying Strategy</th>
* <th>Default Setting</th>
* <th>Property Setter</th>
* <th>Underlying Strategy</th>
* <th>Default Setting</th>
* </tr>
* <tr>
* <td>{@link #setFavorPathExtension}</td>
* <td>{@link PathExtensionContentNegotiationStrategy Path Extension strategy}</td>
* <td>On</td>
* <td>{@link #setFavorPathExtension}</td>
* <td>{@link PathExtensionContentNegotiationStrategy Path Extension strategy}</td>
* <td>On</td>
* </tr>
* <tr>
* <td>{@link #setFavorParameter favorParameter}</td>
* <td>{@link ParameterContentNegotiationStrategy Parameter strategy}</td>
* <td>Off</td>
* <td>{@link #setFavorParameter favorParameter}</td>
* <td>{@link ParameterContentNegotiationStrategy Parameter strategy}</td>
* <td>Off</td>
* </tr>
* <tr>
* <td>{@link #setIgnoreAcceptHeader ignoreAcceptHeader}</td>
* <td>{@link HeaderContentNegotiationStrategy Header strategy}</td>
* <td>On</td>
* <td>{@link #setIgnoreAcceptHeader ignoreAcceptHeader}</td>
* <td>{@link HeaderContentNegotiationStrategy Header strategy}</td>
* <td>On</td>
* </tr>
* <tr>
* <td>{@link #setDefaultContentType defaultContentType}</td>
* <td>{@link FixedContentNegotiationStrategy Fixed content strategy}</td>
* <td>Not set</td>
* <td>{@link #setDefaultContentType defaultContentType}</td>
* <td>{@link FixedContentNegotiationStrategy Fixed content strategy}</td>
* <td>Not set</td>
* </tr>
* <tr>
* <td>{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}</td>
* <td>{@link ContentNegotiationStrategy}</td>
* <td>Not set</td>
* <td>{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}</td>
* <td>{@link ContentNegotiationStrategy}</td>
* <td>Not set</td>
* </tr>
* </table>
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -33,10 +33,8 @@ public interface ContentNegotiationStrategy {
/**
* Resolve the given request to a list of media types. The returned list is
* ordered by specificity first and by quality parameter second.
*
* @param webRequest the current request
* @return the requested media types or an empty list, never {@code null}
*
* @return the requested media types or an empty list (never {@code null})
* @throws HttpMediaTypeNotAcceptableException if the requested media
* types cannot be parsed
*/

View File

@@ -33,8 +33,7 @@ import org.springframework.web.context.request.NativeWebRequest;
*/
public class FixedContentNegotiationStrategy implements ContentNegotiationStrategy {
private static final Log logger = LogFactory.getLog(
FixedContentNegotiationStrategy.class);
private static final Log logger = LogFactory.getLog(FixedContentNegotiationStrategy.class);
private final List<MediaType> contentType;
@@ -50,7 +49,7 @@ public class FixedContentNegotiationStrategy implements ContentNegotiationStrate
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("Requested media types is " + this.contentType + ".");
logger.debug("Requested media types: " + this.contentType);
}
return this.contentType;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -34,11 +34,9 @@ import org.springframework.web.context.request.NativeWebRequest;
*/
public class HeaderContentNegotiationStrategy implements ContentNegotiationStrategy {
/**
* {@inheritDoc}
* @throws HttpMediaTypeNotAcceptableException if the 'Accept' header
* cannot be parsed.
* @throws HttpMediaTypeNotAcceptableException if the 'Accept' header cannot be parsed
*/
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest request)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -35,7 +35,7 @@ import org.springframework.util.MultiValueMap;
* lookups between file extensions and MediaTypes in both directions.
*
* <p>Initially created with a map of file extensions and media types.
* Subsequently sub-classes can use {@link #addMapping} to add more mappings.
* Subsequently subclasses can use {@link #addMapping} to add more mappings.
*
* @author Rossen Stoyanchev
* @since 3.2

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -31,15 +31,14 @@ public interface MediaTypeFileExtensionResolver {
/**
* Resolve the given media type to a list of path extensions.
*
* @param mediaType the media type to resolve
* @return a list of extensions or an empty list, never {@code null}
* @return a list of extensions or an empty list (never {@code null})
*/
List<String> resolveFileExtensions(MediaType mediaType);
/**
* Return all registered file extensions.
* @return a list of extensions or an empty list, never {@code null}
* @return a list of extensions or an empty list (never {@code null})
*/
List<String> getAllFileExtensions();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -27,18 +27,15 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.context.request.NativeWebRequest;
/**
* A {@code ContentNegotiationStrategy} that resolves a query parameter to a
* key to be used to look up a media type. The default parameter name is
* {@code format}.
*s
* A {@code ContentNegotiationStrategy} that resolves a query parameter to a key
* to be used to look up a media type. The default parameter name is {@code format}.
*
* @author Rossen Stoyanchev
* @since 3.2
*/
public class ParameterContentNegotiationStrategy
extends AbstractMappingContentNegotiationStrategy {
public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy {
private static final Log logger = LogFactory.getLog(
ParameterContentNegotiationStrategy.class);
private static final Log logger = LogFactory.getLog(ParameterContentNegotiationStrategy.class);
private String parameterName = "format";
@@ -56,7 +53,7 @@ public class ParameterContentNegotiationStrategy
* <p>By default this is set to {@code "format"}.
*/
public void setParameterName(String parameterName) {
Assert.notNull(parameterName, "parameterName is required");
Assert.notNull(parameterName, "'parameterName' is required");
this.parameterName = parameterName;
}
@@ -64,6 +61,7 @@ public class ParameterContentNegotiationStrategy
return this.parameterName;
}
@Override
protected String getMediaTypeKey(NativeWebRequest request) {
return request.getParameter(getParameterName());
@@ -72,8 +70,8 @@ public class ParameterContentNegotiationStrategy
@Override
protected void handleMatch(String mediaTypeKey, MediaType mediaType) {
if (logger.isDebugEnabled()) {
logger.debug("Requested media type is '" + mediaType +
"' based on '" + getParameterName() + "'='" + mediaTypeKey + "'.");
logger.debug("Requested media type: '" + mediaType + "' based on '" +
getParameterName() + "'='" + mediaTypeKey + "'");
}
}

View File

@@ -57,8 +57,7 @@ public class PathExtensionContentNegotiationStrategy
private static final Log logger = LogFactory.getLog(PathExtensionContentNegotiationStrategy.class);
private static final boolean JAF_PRESENT = ClassUtils.isPresent(
"javax.activation.FileTypeMap",
private static final boolean JAF_PRESENT = ClassUtils.isPresent("javax.activation.FileTypeMap",
PathExtensionContentNegotiationStrategy.class.getClassLoader());
private static final UrlPathHelper PATH_HELPER = new UrlPathHelper();

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.accept;
import java.util.Map;
@@ -32,8 +33,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.2
*/
public class ServletPathExtensionContentNegotiationStrategy
extends PathExtensionContentNegotiationStrategy {
public class ServletPathExtensionContentNegotiationStrategy extends PathExtensionContentNegotiationStrategy {
private final ServletContext servletContext;
@@ -41,12 +41,12 @@ public class ServletPathExtensionContentNegotiationStrategy
/**
* Create an instance with the given extension-to-MediaType lookup.
*/
public ServletPathExtensionContentNegotiationStrategy(ServletContext context,
Map<String, MediaType> mediaTypes) {
public ServletPathExtensionContentNegotiationStrategy(
ServletContext servletContext, Map<String, MediaType> mediaTypes) {
super(mediaTypes);
Assert.notNull(context, "ServletContext is required!");
this.servletContext = context;
Assert.notNull(servletContext, "ServletContext is required");
this.servletContext = servletContext;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -288,7 +288,7 @@ public abstract class WebApplicationContextUtils {
public static void initServletPropertySources(
MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) {
Assert.notNull(propertySources, "propertySources must not be null");
Assert.notNull(propertySources, "'propertySources' must not be null");
if (servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) &&
propertySources.get(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) {
propertySources.replace(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -211,7 +211,7 @@ public abstract class PortletApplicationContextUtils {
public static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext,
PortletContext portletContext, PortletConfig portletConfig) {
Assert.notNull(propertySources, "propertySources must not be null");
Assert.notNull(propertySources, "'propertySources' must not be null");
WebApplicationContextUtils.initServletPropertySources(propertySources, servletContext);
if (portletContext != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME)) {