|
73 | 73 | * media type. The default name of the parameter is <code>format</code> and it can be configured using the |
74 | 74 | * {@link #setParameterName(String) parameterName} property.</li> |
75 | 75 | * <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, |
77 | 77 | * {@link FileTypeMap#getContentType(String)} is used instead.</li> |
78 | 78 | * <li>If the previous steps did not result in a media type, and |
79 | 79 | * {@link #setIgnoreAcceptHeader ignoreAcceptHeader} is {@code false}, the request {@code Accept} header is |
80 | 80 | * used.</li> |
81 | 81 | * </ol> |
82 | 82 | * |
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 |
84 | 84 | * {@link View} and determines if the requested media type is {@linkplain MediaType#includes(MediaType) compatible} |
85 | 85 | * with the view's {@linkplain View#getContentType() content type}). The most compatible view is returned. |
86 | 86 | * |
@@ -358,7 +358,7 @@ protected List<MediaType> getMediaTypes(HttpServletRequest request) { |
358 | 358 | * <p>The default implementation will check the {@linkplain #setMediaTypes(Map) media types} |
359 | 359 | * property first for a defined mapping. If not present, and if the Java Activation Framework |
360 | 360 | * 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. |
362 | 362 | * @param filename the current request file name (i.e. {@code hotels.html}) |
363 | 363 | * @return the media type, if any |
364 | 364 | */ |
@@ -454,6 +454,18 @@ private View getBestView(List<View> candidateViews, List<MediaType> requestedMed |
454 | 454 | } |
455 | 455 |
|
456 | 456 |
|
| 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 | + |
457 | 469 | /** |
458 | 470 | * Inner class to avoid hard-coded JAF dependency. |
459 | 471 | */ |
@@ -497,22 +509,10 @@ private static FileTypeMap loadFileTypeMapFromContextSupportModule() { |
497 | 509 | return FileTypeMap.getDefaultFileTypeMap(); |
498 | 510 | } |
499 | 511 |
|
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); |
502 | 514 | return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null); |
503 | 515 | } |
504 | 516 | } |
505 | 517 |
|
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 | | - |
518 | 518 | } |
0 commit comments