From df7bdfa7c6c817ff347f6af60739ccd9335f53fe Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 6 Dec 2011 22:50:48 +0000 Subject: [PATCH] polishing --- .../view/ContentNegotiatingViewResolver.java | 34 +++++++++---------- .../ResourceHttpMessageConverter.java | 9 ++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java index 5bc8f383fdf..412689a0e24 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java @@ -73,14 +73,14 @@ import org.springframework.web.util.WebUtils; * media type. The default name of the parameter is format and it can be configured using the * {@link #setParameterName(String) parameterName} property. *
  • If there is no match in the {@link #setMediaTypes(Map) mediaTypes} property and if the Java Activation - * Framework (JAF) is both {@linkplain #setUseJaf enabled} and present on the class path, + * Framework (JAF) is both {@linkplain #setUseJaf enabled} and present on the classpath, * {@link FileTypeMap#getContentType(String)} is used instead.
  • *
  • If the previous steps did not result in a media type, and * {@link #setIgnoreAcceptHeader ignoreAcceptHeader} is {@code false}, the request {@code Accept} header is * used.
  • * * - * Once the requested media type has been determined, this resolver queries each delegate view resolver for a + *

    Once the requested media type has been determined, this resolver queries each delegate view resolver for a * {@link View} and determines if the requested media type is {@linkplain MediaType#includes(MediaType) compatible} * with the view's {@linkplain View#getContentType() content type}). The most compatible view is returned. * @@ -358,7 +358,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport *

    The default implementation will check the {@linkplain #setMediaTypes(Map) media types} * property first for a defined mapping. If not present, and if the Java Activation Framework * can be found on the classpath, it will call {@link FileTypeMap#getContentType(String)} - *

    This method can be overriden to provide a different algorithm. + *

    This method can be overridden to provide a different algorithm. * @param filename the current request file name (i.e. {@code hotels.html}) * @return the media type, if any */ @@ -454,6 +454,18 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport } + private static final View NOT_ACCEPTABLE_VIEW = new View() { + + public String getContentType() { + return null; + } + + public void render(Map model, HttpServletRequest request, HttpServletResponse response) { + response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); + } + }; + + /** * Inner class to avoid hard-coded JAF dependency. */ @@ -497,22 +509,10 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport return FileTypeMap.getDefaultFileTypeMap(); } - public static MediaType getMediaType(String fileName) { - String mediaType = fileTypeMap.getContentType(fileName); + public static MediaType getMediaType(String filename) { + String mediaType = fileTypeMap.getContentType(filename); return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null); } } - - private static final View NOT_ACCEPTABLE_VIEW = new View() { - - public String getContentType() { - return null; - } - - public void render(Map model, HttpServletRequest request, HttpServletResponse response) { - response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); - } - }; - } diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java index a17233a5649..7b00576c0ed 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java +++ b/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -37,9 +37,9 @@ import org.springframework.util.StringUtils; /** * Implementation of {@link HttpMessageConverter} that can read and write {@link Resource Resources}. * - *

    By default, this converter can read all media types. The Java Activation Framework (JAF) - if available - is used - * to determine the {@code Content-Type} of written resources. If JAF is not available, {@code application/octet-stream} - * is used. + *

    By default, this converter can read all media types. The Java Activation Framework (JAF) - + * if available - is used to determine the {@code Content-Type} of written resources. + * If JAF is not available, {@code application/octet-stream} is used. * * @author Arjen Poutsma * @since 3.0.2 @@ -49,6 +49,7 @@ public class ResourceHttpMessageConverter implements HttpMessageConverter clazz, MediaType mediaType) { return Resource.class.isAssignableFrom(clazz); }