polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -112,7 +112,7 @@ abstract class SelectedValueComparator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ClassCastException ex) {
|
catch (ClassCastException ex) {
|
||||||
// Probably from a - ignore.
|
// Probably from a TreeSet - ignore.
|
||||||
}
|
}
|
||||||
return exhaustiveCollectionCompare(boundCollection, candidateValue, bindStatus);
|
return exhaustiveCollectionCompare(boundCollection, candidateValue, bindStatus);
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ abstract class SelectedValueComparator {
|
|||||||
else if (editor != null && candidate instanceof String) {
|
else if (editor != null && candidate instanceof String) {
|
||||||
// Try PE-based comparison (PE should *not* be allowed to escape creating thread)
|
// Try PE-based comparison (PE should *not* be allowed to escape creating thread)
|
||||||
String candidateAsString = (String) candidate;
|
String candidateAsString = (String) candidate;
|
||||||
Object candidateAsValue = null;
|
Object candidateAsValue;
|
||||||
if (convertedValueCache != null && convertedValueCache.containsKey(editor)) {
|
if (convertedValueCache != null && convertedValueCache.containsKey(editor)) {
|
||||||
candidateAsValue = convertedValueCache.get(editor);
|
candidateAsValue = convertedValueCache.get(editor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ public class RedirectView extends AbstractUrlBasedView {
|
|||||||
boolean first = (getUrl().indexOf('?') < 0);
|
boolean first = (getUrl().indexOf('?') < 0);
|
||||||
for (Map.Entry<String, Object> entry : queryProperties(model).entrySet()) {
|
for (Map.Entry<String, Object> entry : queryProperties(model).entrySet()) {
|
||||||
Object rawValue = entry.getValue();
|
Object rawValue = entry.getValue();
|
||||||
Iterator valueIter = null;
|
Iterator valueIter;
|
||||||
if (rawValue != null && rawValue.getClass().isArray()) {
|
if (rawValue != null && rawValue.getClass().isArray()) {
|
||||||
valueIter = Arrays.asList(ObjectUtils.toObjectArray(rawValue)).iterator();
|
valueIter = Arrays.asList(ObjectUtils.toObjectArray(rawValue)).iterator();
|
||||||
}
|
}
|
||||||
@@ -398,14 +398,18 @@ public class RedirectView extends AbstractUrlBasedView {
|
|||||||
/**
|
/**
|
||||||
* Determines the status code to use for HTTP 1.1 compatible requests.
|
* Determines the status code to use for HTTP 1.1 compatible requests.
|
||||||
* <p>The default implemenetation returns the {@link #setStatusCode(HttpStatus) statusCode}
|
* <p>The default implemenetation returns the {@link #setStatusCode(HttpStatus) statusCode}
|
||||||
* property if set, or the value of the {@link #RESPONSE_STATUS_ATTRIBUTE} attribute. If neither are
|
* property if set, or the value of the {@link #RESPONSE_STATUS_ATTRIBUTE} attribute.
|
||||||
* set, it defaults to {@link HttpStatus#SEE_OTHER} (303).
|
* If neither are set, it defaults to {@link HttpStatus#SEE_OTHER} (303).
|
||||||
* @param request the request to inspect
|
* @param request the request to inspect
|
||||||
* @return the response
|
* @param response the servlet response
|
||||||
|
* @param targetUrl the target URL
|
||||||
|
* @return the response status
|
||||||
*/
|
*/
|
||||||
protected HttpStatus getHttp11StatusCode(HttpServletRequest request, HttpServletResponse response, String targetUrl) {
|
protected HttpStatus getHttp11StatusCode(
|
||||||
if (statusCode != null) {
|
HttpServletRequest request, HttpServletResponse response, String targetUrl) {
|
||||||
return statusCode;
|
|
||||||
|
if (this.statusCode != null) {
|
||||||
|
return this.statusCode;
|
||||||
}
|
}
|
||||||
HttpStatus attributeStatusCode = (HttpStatus) request.getAttribute(View.RESPONSE_STATUS_ATTRIBUTE);
|
HttpStatus attributeStatusCode = (HttpStatus) request.getAttribute(View.RESPONSE_STATUS_ATTRIBUTE);
|
||||||
if (attributeStatusCode != null) {
|
if (attributeStatusCode != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user