1 17 package org.alfresco.web.bean; 18 19 import java.io.PrintWriter ; 20 import java.io.StringWriter ; 21 22 import javax.servlet.ServletException ; 23 24 29 public class ErrorBean 30 { 31 public static final String ERROR_BEAN_NAME = "alfresco.ErrorBean"; 32 33 private String returnPage; 34 private Throwable lastError; 35 36 39 public String getReturnPage() 40 { 41 return returnPage; 42 } 43 44 47 public void setReturnPage(String returnPage) 48 { 49 this.returnPage = returnPage; 50 } 51 52 55 public Throwable getLastError() 56 { 57 return lastError; 58 } 59 60 63 public void setLastError(Throwable lastError) 64 { 65 this.lastError = lastError; 66 } 67 68 71 public String getLastErrorMessage() 72 { 73 String message = "No error currently stored"; 74 75 if (this.lastError != null) 76 { 77 StringBuilder builder = null; 78 Throwable cause = null; 79 if (this.lastError instanceof ServletException && 80 ((ServletException )this.lastError).getRootCause() != null) 81 { 82 Throwable actualError = ((ServletException )this.lastError).getRootCause(); 84 builder = new StringBuilder (actualError.toString()); 85 cause = actualError.getCause(); 86 } 87 else 88 { 89 builder = new StringBuilder (this.lastError.toString()); 90 cause = this.lastError.getCause(); 91 } 92 93 while (cause != null) 94 { 95 builder.append("<br/><br/>caused by:<br/>"); 96 builder.append(cause.toString()); 97 98 if (cause instanceof ServletException && 99 ((ServletException )cause).getRootCause() != null) 100 { 101 cause = ((ServletException )cause).getRootCause(); 102 } 103 else 104 { 105 cause = cause.getCause(); 106 } 107 } 108 109 message = builder.toString(); 110 } 111 112 return message; 113 } 114 115 118 public String getStackTrace() 119 { 120 StringWriter stringWriter = new StringWriter (); 121 PrintWriter writer = new PrintWriter (stringWriter); 122 123 if (this.lastError instanceof ServletException && 124 ((ServletException )this.lastError).getRootCause() != null) 125 { 126 Throwable actualError = ((ServletException )this.lastError).getRootCause(); 127 actualError.printStackTrace(writer); 128 } 129 else 130 { 131 this.lastError.printStackTrace(writer); 132 } 133 134 return stringWriter.toString().replaceAll("\r\n", "<br/>"); 135 } 136 } 137 | Popular Tags |