From 54c82a53cd5e153b023888baa9e6c9fbf7d8fce8 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 22 Jun 2011 19:29:35 +0000 Subject: [PATCH] SPR-8452 Provide getter for statusCodes property of SimpleMappingExceptionResolver --- .../handler/SimpleMappingExceptionResolver.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java index 4ca0e0cf37..e9dcd7ea83 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.handler; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -89,13 +90,21 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @see #setDefaultStatusCode(int) */ public void setStatusCodes(Properties statusCodes) { - for (Enumeration enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) { + for (Enumeration enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) { String viewName = (String) enumeration.nextElement(); Integer statusCode = new Integer(statusCodes.getProperty(viewName)); 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 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 * is no status code mapping defined. @@ -189,7 +198,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso String viewName = null; String dominantMapping = null; int deepest = Integer.MAX_VALUE; - for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) { + for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) { String exceptionMapping = (String) names.nextElement(); int depth = getDepth(exceptionMapping, ex); if (depth >= 0 && depth < deepest) { @@ -214,7 +223,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso 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)) { // Found it! return depth;