Skip to content

Commit df7bdfa

Browse files
committed
polishing
1 parent f8402e9 commit df7bdfa

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
* media type. The default name of the parameter is <code>format</code> and it can be configured using the
7474
* {@link #setParameterName(String) parameterName} property.</li>
7575
* <li>If there is no match in the {@link #setMediaTypes(Map) mediaTypes} property and if the Java Activation
76-
* Framework (JAF) is both {@linkplain #setUseJaf enabled} and present on the class path,
76+
* Framework (JAF) is both {@linkplain #setUseJaf enabled} and present on the classpath,
7777
* {@link FileTypeMap#getContentType(String)} is used instead.</li>
7878
* <li>If the previous steps did not result in a media type, and
7979
* {@link #setIgnoreAcceptHeader ignoreAcceptHeader} is {@code false}, the request {@code Accept} header is
8080
* used.</li>
8181
* </ol>
8282
*
83-
* Once the requested media type has been determined, this resolver queries each delegate view resolver for a
83+
* <p>Once the requested media type has been determined, this resolver queries each delegate view resolver for a
8484
* {@link View} and determines if the requested media type is {@linkplain MediaType#includes(MediaType) compatible}
8585
* with the view's {@linkplain View#getContentType() content type}). The most compatible view is returned.
8686
*
@@ -358,7 +358,7 @@ protected List<MediaType> getMediaTypes(HttpServletRequest request) {
358358
* <p>The default implementation will check the {@linkplain #setMediaTypes(Map) media types}
359359
* property first for a defined mapping. If not present, and if the Java Activation Framework
360360
* can be found on the classpath, it will call {@link FileTypeMap#getContentType(String)}
361-
* <p>This method can be overriden to provide a different algorithm.
361+
* <p>This method can be overridden to provide a different algorithm.
362362
* @param filename the current request file name (i.e. {@code hotels.html})
363363
* @return the media type, if any
364364
*/
@@ -454,6 +454,18 @@ private View getBestView(List<View> candidateViews, List<MediaType> requestedMed
454454
}
455455

456456

457+
private static final View NOT_ACCEPTABLE_VIEW = new View() {
458+
459+
public String getContentType() {
460+
return null;
461+
}
462+
463+
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
464+
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
465+
}
466+
};
467+
468+
457469
/**
458470
* Inner class to avoid hard-coded JAF dependency.
459471
*/
@@ -497,22 +509,10 @@ private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
497509
return FileTypeMap.getDefaultFileTypeMap();
498510
}
499511

500-
public static MediaType getMediaType(String fileName) {
501-
String mediaType = fileTypeMap.getContentType(fileName);
512+
public static MediaType getMediaType(String filename) {
513+
String mediaType = fileTypeMap.getContentType(filename);
502514
return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
503515
}
504516
}
505517

506-
507-
private static final View NOT_ACCEPTABLE_VIEW = new View() {
508-
509-
public String getContentType() {
510-
return null;
511-
}
512-
513-
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
514-
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
515-
}
516-
};
517-
518518
}

org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,9 +37,9 @@
3737
/**
3838
* Implementation of {@link HttpMessageConverter} that can read and write {@link Resource Resources}.
3939
*
40-
* <p>By default, this converter can read all media types. The Java Activation Framework (JAF) - if available - is used
41-
* to determine the {@code Content-Type} of written resources. If JAF is not available, {@code application/octet-stream}
42-
* is used.
40+
* <p>By default, this converter can read all media types. The Java Activation Framework (JAF) -
41+
* if available - is used to determine the {@code Content-Type} of written resources.
42+
* If JAF is not available, {@code application/octet-stream} is used.
4343
*
4444
* @author Arjen Poutsma
4545
* @since 3.0.2
@@ -49,6 +49,7 @@ public class ResourceHttpMessageConverter implements HttpMessageConverter<Resour
4949
private static final boolean jafPresent =
5050
ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader());
5151

52+
5253
public boolean canRead(Class<?> clazz, MediaType mediaType) {
5354
return Resource.class.isAssignableFrom(clazz);
5455
}

0 commit comments

Comments
 (0)