Coverage Report - org.seasar.teeda.core.util.ServletErrorPageManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ServletErrorPageManagerImpl
95%
20/21
90%
9/10
2.333
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 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  
  * @author higa
 30  
  * @author shot
 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  
 }