2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.examples.test.view.Error
 
Classes in this File Line Coverage Branch Coverage Complexity
Error
0%
0/52
0%
0/6
1.571
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.shale.examples.test.view;
 18  
 
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.faces.component.UIViewRoot;
 23  
 import javax.faces.context.FacesContext;
 24  
 
 25  
 import org.apache.shale.view.AbstractViewController;
 26  
 import org.apache.shale.view.faces.FacesConstants;
 27  
 
 28  0
 public class Error extends AbstractViewController {
 29  
 
 30  0
     private String httpErrorCode = null;
 31  
 
 32  0
     private String exceptionType = null;
 33  
 
 34  0
     private String message = null;
 35  
 
 36  0
     private String requestUri = null;
 37  
 
 38  0
     private String servletName = null;
 39  
     
 40  0
     private Recorder recorder = null;
 41  
 
 42  
     public void prerender() {
 43  0
         System.out.println("Error - Removing exceptions stack");
 44  
 
 45  0
         Map requestMap = getRequestMap();
 46  
         
 47  0
         Exception exception = (Exception) requestMap
 48  
                 .get("javax.servlet.error.exception");
 49  
 
 50  0
         FacesContext facesContext = getFacesContext();
 51  0
         if (facesContext == null) return;
 52  
         
 53  0
         UIViewRoot root = facesContext.getViewRoot();
 54  0
         if (root == null) return;
 55  
         
 56  0
         List exceptions = (List) requestMap.get(FacesConstants.EXCEPTIONS_LIST);
 57  0
         if (exception != null && exceptions != null) {
 58  
             // save on the view root
 59  0
             getFacesContext().getViewRoot().getAttributes().put("errors", exceptions);
 60  0
             requestMap.remove(FacesConstants.EXCEPTIONS_LIST);
 61  
 
 62  
             
 63  0
             Integer errorCode = (Integer) requestMap.get("javax.servlet.error.status_code");
 64  0
             if (errorCode != null) {
 65  0
             setHttpErrorCode(errorCode.toString());
 66  
             }
 67  
             
 68  0
             Object clazz = requestMap.get("javax.servlet.error.exception_type");
 69  0
             if (clazz != null) {
 70  0
                setExceptionType(clazz.toString());
 71  
             }
 72  0
             setMessage((String) requestMap.get("javax.servlet.error.message"));
 73  0
             setRequestUri((String) requestMap
 74  
                     .get("javax.servlet.error.request_uri"));
 75  0
             setServletName((String) requestMap
 76  
                     .get("javax.servlet.error.servlet_name"));
 77  
 
 78  0
             setRecorder((Recorder) getBean("recorder"));
 79  
         }
 80  
         
 81  0
     }
 82  
 
 83  
     public String getExceptionType() {
 84  0
         return exceptionType;
 85  
     }
 86  
 
 87  
     public void setExceptionType(String exceptionType) {
 88  0
         this.exceptionType = exceptionType;
 89  0
     }
 90  
 
 91  
     public String getHttpErrorCode() {
 92  0
         return httpErrorCode;
 93  
     }
 94  
 
 95  
     public void setHttpErrorCode(String httpErrorCode) {
 96  0
         this.httpErrorCode = httpErrorCode;
 97  0
     }
 98  
 
 99  
     public String getMessage() {
 100  0
         return message;
 101  
     }
 102  
 
 103  
     public void setMessage(String message) {
 104  0
         this.message = message;
 105  0
     }
 106  
 
 107  
     public String getRequestUri() {
 108  0
         return requestUri;
 109  
     }
 110  
 
 111  
     public void setRequestUri(String requestUri) {
 112  0
         this.requestUri = requestUri;
 113  0
     }
 114  
 
 115  
     public String getServletName() {
 116  0
         return servletName;
 117  
     }
 118  
 
 119  
     public void setServletName(String servletName) {
 120  0
         this.servletName = servletName;
 121  0
     }
 122  
 
 123  
     public Recorder getRecorder() {
 124  0
         return recorder;
 125  
     }
 126  
 
 127  
     public void setRecorder(Recorder recorder) {
 128  0
         this.recorder = recorder;
 129  0
     }
 130  
     
 131  
     public String getStackTrace() {
 132  0
        StringBuffer buff = new StringBuffer();
 133  0
        Exception e = (Exception) getBean("e");
 134  0
        for (int i = 0; i < e.getStackTrace().length; i++) {
 135  0
           buff.append(e.getStackTrace()[i].toString())
 136  
               .append("\n");
 137  
        }
 138  0
        return buff.toString();
 139  
     }
 140  
 }