SPR-8452 Provide getter for statusCodes property of SimpleMappingExceptionResolver

This commit is contained in:
Rossen Stoyanchev 2011-06-22 19:29:35 +00:00
parent 5797fe7f62
commit 54c82a53cd
1 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.web.servlet.handler; package org.springframework.web.servlet.handler;
import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -89,13 +90,21 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
* @see #setDefaultStatusCode(int) * @see #setDefaultStatusCode(int)
*/ */
public void setStatusCodes(Properties statusCodes) { public void setStatusCodes(Properties statusCodes) {
for (Enumeration enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) { for (Enumeration<?> enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) {
String viewName = (String) enumeration.nextElement(); String viewName = (String) enumeration.nextElement();
Integer statusCode = new Integer(statusCodes.getProperty(viewName)); Integer statusCode = new Integer(statusCodes.getProperty(viewName));
this.statusCodes.put(viewName, statusCode); this.statusCodes.put(viewName, statusCode);
} }
} }
/**
* Returns the HTTP status codes provided via {@link #setStatusCodes(Properties)}.
* Keys are view names; values are status codes.
*/
public Map<String, Integer> getStatusCodes() {
return Collections.unmodifiableMap(statusCodes);
}
/** /**
* Set the default HTTP status code that this exception resolver will apply if it resolves an error view and if there * Set the default HTTP status code that this exception resolver will apply if it resolves an error view and if there
* is no status code mapping defined. * is no status code mapping defined.
@ -189,7 +198,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
String viewName = null; String viewName = null;
String dominantMapping = null; String dominantMapping = null;
int deepest = Integer.MAX_VALUE; int deepest = Integer.MAX_VALUE;
for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) { for (Enumeration<?> names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
String exceptionMapping = (String) names.nextElement(); String exceptionMapping = (String) names.nextElement();
int depth = getDepth(exceptionMapping, ex); int depth = getDepth(exceptionMapping, ex);
if (depth >= 0 && depth < deepest) { if (depth >= 0 && depth < deepest) {
@ -214,7 +223,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
return getDepth(exceptionMapping, ex.getClass(), 0); return getDepth(exceptionMapping, ex.getClass(), 0);
} }
private int getDepth(String exceptionMapping, Class exceptionClass, int depth) { private int getDepth(String exceptionMapping, Class<?> exceptionClass, int depth) {
if (exceptionClass.getName().contains(exceptionMapping)) { if (exceptionClass.getName().contains(exceptionMapping)) {
// Found it! // Found it!
return depth; return depth;