From 521c41d75ee2a5b53c3223c672a5609335a78e00 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 2 Jun 2016 17:02:44 +0200 Subject: [PATCH] Polishing --- ...ractMappingContentNegotiationStrategy.java | 7 ++-- .../web/accept/ContentNegotiationManager.java | 12 ++---- .../ContentNegotiationManagerFactoryBean.java | 38 +++++++++---------- .../accept/ContentNegotiationStrategy.java | 6 +-- .../FixedContentNegotiationStrategy.java | 5 +-- .../HeaderContentNegotiationStrategy.java | 6 +-- ...MappingMediaTypeFileExtensionResolver.java | 4 +- .../MediaTypeFileExtensionResolver.java | 7 ++-- .../ParameterContentNegotiationStrategy.java | 22 +++++------ ...thExtensionContentNegotiationStrategy.java | 3 +- ...thExtensionContentNegotiationStrategy.java | 12 +++--- .../support/WebApplicationContextUtils.java | 4 +- .../PortletApplicationContextUtils.java | 4 +- 13 files changed, 58 insertions(+), 72 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java index 0568b90465d..ee83d31f77f 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java @@ -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}. diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java index 09c7f6abc36..81553b81d0a 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java @@ -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 MEDIA_TYPE_ALL = - Collections.singletonList(MediaType.ALL); + private static final List MEDIA_TYPE_ALL = Collections.singletonList(MediaType.ALL); - private final List strategies = - new ArrayList(); + private final List strategies = new ArrayList(); - private final Set resolvers = - new LinkedHashSet(); + private final Set resolvers = new LinkedHashSet(); /** diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index b035b079acf..dfcd84990e8 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -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; * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * *
Property SetterUnderlying StrategyDefault SettingProperty SetterUnderlying StrategyDefault Setting
{@link #setFavorPathExtension}{@link PathExtensionContentNegotiationStrategy Path Extension strategy}On{@link #setFavorPathExtension}{@link PathExtensionContentNegotiationStrategy Path Extension strategy}On
{@link #setFavorParameter favorParameter}{@link ParameterContentNegotiationStrategy Parameter strategy}Off{@link #setFavorParameter favorParameter}{@link ParameterContentNegotiationStrategy Parameter strategy}Off
{@link #setIgnoreAcceptHeader ignoreAcceptHeader}{@link HeaderContentNegotiationStrategy Header strategy}On{@link #setIgnoreAcceptHeader ignoreAcceptHeader}{@link HeaderContentNegotiationStrategy Header strategy}On
{@link #setDefaultContentType defaultContentType}{@link FixedContentNegotiationStrategy Fixed content strategy}Not set{@link #setDefaultContentType defaultContentType}{@link FixedContentNegotiationStrategy Fixed content strategy}Not set
{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}{@link ContentNegotiationStrategy}Not set{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}{@link ContentNegotiationStrategy}Not set
* diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java index 127f90cef42..586485a72a2 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java @@ -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 */ diff --git a/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java index 547ccef791f..50478683b13 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java @@ -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 contentType; @@ -50,7 +49,7 @@ public class FixedContentNegotiationStrategy implements ContentNegotiationStrate @Override public List resolveMediaTypes(NativeWebRequest request) { if (logger.isDebugEnabled()) { - logger.debug("Requested media types is " + this.contentType + "."); + logger.debug("Requested media types: " + this.contentType); } return this.contentType; } diff --git a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java index bcefd7279e6..2642853d9dc 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java @@ -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 resolveMediaTypes(NativeWebRequest request) diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 6c2c8c7d6b5..49c38d6dd34 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -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. * *

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 diff --git a/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java index c063e5c50ba..49a7fcd9863 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java @@ -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 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 getAllFileExtensions(); diff --git a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java index a2520d27fd0..f6a9cb4eaa1 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java @@ -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 *

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 + "'"); } } diff --git a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java index f6173264880..ac4f3059c4a 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java @@ -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(); diff --git a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java index 931e03fb35f..931d6ebe977 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java @@ -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 mediaTypes) { + public ServletPathExtensionContentNegotiationStrategy( + ServletContext servletContext, Map mediaTypes) { super(mediaTypes); - Assert.notNull(context, "ServletContext is required!"); - this.servletContext = context; + Assert.notNull(servletContext, "ServletContext is required"); + this.servletContext = servletContext; } /** diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index ae75fbe4e83..26838d3907a 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -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, diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java index 4e27a129bf4..ce29022a04f 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java @@ -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)) {