| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.util; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.Map; |
| 21 | |
|
| 22 | |
import javax.faces.context.ExternalContext; |
| 23 | |
import javax.faces.context.FacesContext; |
| 24 | |
import javax.servlet.ServletRequest; |
| 25 | |
|
| 26 | |
import org.seasar.framework.log.Logger; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 5 | public class ServletErrorPageManagerImpl implements ErrorPageManager { |
| 33 | |
|
| 34 | 1 | private static final Logger logger = Logger |
| 35 | 2 | .getLogger(ServletErrorPageManagerImpl.class); |
| 36 | |
|
| 37 | 5 | protected Map locations = new HashMap(); |
| 38 | |
|
| 39 | |
public void addErrorPage(Class exceptionType, String location) { |
| 40 | 3 | locations.put(exceptionType, location); |
| 41 | 3 | } |
| 42 | |
|
| 43 | |
public boolean handleException(Throwable exception, FacesContext context, |
| 44 | |
ExternalContext extContext) throws IOException { |
| 45 | 2 | if (logger.isDebugEnabled()) { |
| 46 | 0 | logger.log("ETDA0001", new Object[0], exception); |
| 47 | |
} |
| 48 | 2 | String location = getLocation(exception.getClass()); |
| 49 | 2 | if (location == null) { |
| 50 | 1 | return false; |
| 51 | |
} |
| 52 | 1 | ServletRequest request = ServletExternalContextUtil |
| 53 | |
.getRequest(extContext); |
| 54 | 1 | ServletExternalContextUtil |
| 55 | |
.storeErrorInfoToAttribute(request, exception); |
| 56 | 1 | extContext.dispatch(location); |
| 57 | 1 | return true; |
| 58 | |
} |
| 59 | |
|
| 60 | |
protected String getLocation(Class exceptionType) { |
| 61 | 5 | Class clazz = exceptionType; |
| 62 | 5 | String location = (String) locations.get(clazz); |
| 63 | 10 | while (location == null && !clazz.equals(Throwable.class)) { |
| 64 | 5 | clazz = clazz.getSuperclass(); |
| 65 | 5 | location = (String) locations.get(clazz); |
| 66 | |
} |
| 67 | 5 | return location; |
| 68 | |
} |
| 69 | |
} |