|
|
@ -135,6 +135,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
private List<ViewResolver> viewResolvers; |
|
|
|
private List<ViewResolver> viewResolvers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setOrder(int order) { |
|
|
|
public void setOrder(int order) { |
|
|
|
this.order = order; |
|
|
|
this.order = order; |
|
|
|
} |
|
|
|
} |
|
|
@ -312,7 +313,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.defaultContentType != null) { |
|
|
|
if (this.defaultContentType != null) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Requested media types is " + defaultContentType + " (based on defaultContentType property)"); |
|
|
|
logger.debug("Requested media types is " + this.defaultContentType + |
|
|
|
|
|
|
|
" (based on defaultContentType property)"); |
|
|
|
} |
|
|
|
} |
|
|
|
return Collections.singletonList(this.defaultContentType); |
|
|
|
return Collections.singletonList(this.defaultContentType); |
|
|
|
} |
|
|
|
} |
|
|
@ -323,9 +325,9 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determines the {@link MediaType} for the given filename. |
|
|
|
* Determines the {@link MediaType} for the given filename. |
|
|
|
* <p>The default implementation will check the {@linkplain #setMediaTypes(Map) media types} property first for a |
|
|
|
* <p>The default implementation will check the {@linkplain #setMediaTypes(Map) media types} |
|
|
|
* defined mapping. If not present, and if the Java Activation Framework can be found on the class path, it will call |
|
|
|
* property first for a defined mapping. If not present, and if the Java Activation Framework |
|
|
|
* {@link FileTypeMap#getContentType(String)} |
|
|
|
* 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 overriden to provide a different algorithm. |
|
|
|
* @param filename the current request file name (i.e. {@code hotels.html}) |
|
|
|
* @param filename the current request file name (i.e. {@code hotels.html}) |
|
|
|
* @return the media type, if any |
|
|
|
* @return the media type, if any |
|
|
@ -337,7 +339,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
extension = extension.toLowerCase(Locale.ENGLISH); |
|
|
|
extension = extension.toLowerCase(Locale.ENGLISH); |
|
|
|
MediaType mediaType = this.mediaTypes.get(extension); |
|
|
|
MediaType mediaType = this.mediaTypes.get(extension); |
|
|
|
if (mediaType == null && useJaf && jafPresent) { |
|
|
|
if (mediaType == null && this.useJaf && jafPresent) { |
|
|
|
mediaType = ActivationMediaTypeFactory.getMediaType(filename); |
|
|
|
mediaType = ActivationMediaTypeFactory.getMediaType(filename); |
|
|
|
if (mediaType != null) { |
|
|
|
if (mediaType != null) { |
|
|
|
this.mediaTypes.putIfAbsent(extension, mediaType); |
|
|
|
this.mediaTypes.putIfAbsent(extension, mediaType); |
|
|
@ -361,18 +363,14 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
public View resolveViewName(String viewName, Locale locale) throws Exception { |
|
|
|
public View resolveViewName(String viewName, Locale locale) throws Exception { |
|
|
|
RequestAttributes attrs = RequestContextHolder.getRequestAttributes(); |
|
|
|
RequestAttributes attrs = RequestContextHolder.getRequestAttributes(); |
|
|
|
Assert.isInstanceOf(ServletRequestAttributes.class, attrs); |
|
|
|
Assert.isInstanceOf(ServletRequestAttributes.class, attrs); |
|
|
|
|
|
|
|
|
|
|
|
List<MediaType> requestedMediaTypes = getMediaTypes(((ServletRequestAttributes) attrs).getRequest()); |
|
|
|
List<MediaType> requestedMediaTypes = getMediaTypes(((ServletRequestAttributes) attrs).getRequest()); |
|
|
|
|
|
|
|
|
|
|
|
List<View> candidateViews = getCandidateViews(viewName, locale, requestedMediaTypes); |
|
|
|
List<View> candidateViews = getCandidateViews(viewName, locale, requestedMediaTypes); |
|
|
|
|
|
|
|
|
|
|
|
View bestView = getBestView(candidateViews, requestedMediaTypes); |
|
|
|
View bestView = getBestView(candidateViews, requestedMediaTypes); |
|
|
|
|
|
|
|
|
|
|
|
if (bestView != null) { |
|
|
|
if (bestView != null) { |
|
|
|
return bestView; |
|
|
|
return bestView; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (useNotAcceptableStatusCode) { |
|
|
|
if (this.useNotAcceptableStatusCode) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("No acceptable view found; returning 406 (Not Acceptable) status code"); |
|
|
|
logger.debug("No acceptable view found; returning 406 (Not Acceptable) status code"); |
|
|
|
} |
|
|
|
} |
|
|
@ -389,8 +387,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
private List<View> getCandidateViews(String viewName, Locale locale, List<MediaType> requestedMediaTypes) |
|
|
|
private List<View> getCandidateViews(String viewName, Locale locale, List<MediaType> requestedMediaTypes) |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
List<View> candidateViews = new ArrayList<View>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<View> candidateViews = new ArrayList<View>(); |
|
|
|
for (ViewResolver viewResolver : this.viewResolvers) { |
|
|
|
for (ViewResolver viewResolver : this.viewResolvers) { |
|
|
|
View view = viewResolver.resolveViewName(viewName, locale); |
|
|
|
View view = viewResolver.resolveViewName(viewName, locale); |
|
|
|
if (view != null) { |
|
|
|
if (view != null) { |
|
|
@ -408,7 +406,6 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(this.defaultViews)) { |
|
|
|
if (!CollectionUtils.isEmpty(this.defaultViews)) { |
|
|
|
candidateViews.addAll(this.defaultViews); |
|
|
|
candidateViews.addAll(this.defaultViews); |
|
|
|
} |
|
|
|
} |
|
|
@ -452,6 +449,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Inner class to avoid hard-coded JAF dependency. |
|
|
|
* Inner class to avoid hard-coded JAF dependency. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -501,6 +499,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final View NOT_ACCEPTABLE_VIEW = new View() { |
|
|
|
private static final View NOT_ACCEPTABLE_VIEW = new View() { |
|
|
|
|
|
|
|
|
|
|
|
public String getContentType() { |
|
|
|
public String getContentType() { |
|
|
@ -512,4 +511,5 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport |
|
|
|
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); |
|
|
|
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|