polishing

This commit is contained in:
Juergen Hoeller
2011-12-06 22:50:48 +00:00
parent f8402e9f82
commit df7bdfa7c6
2 changed files with 22 additions and 21 deletions

View File

@@ -73,14 +73,14 @@ import org.springframework.web.util.WebUtils;
* media type. The default name of the parameter is <code>format</code> and it can be configured using the
* {@link #setParameterName(String) parameterName} property.</li>
* <li>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.</li>
* <li>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.</li>
* </ol>
*
* Once the requested media type has been determined, this resolver queries each delegate view resolver for a
* <p>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
* <p>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)}
* <p>This method can be overriden to provide a different algorithm.
* <p>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<String, ?> 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<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
}
};
}