1 12 13 package com.openedit.error; 14 15 import java.io.IOException ; 16 import java.io.Writer ; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import com.openedit.OpenEditException; 22 import com.openedit.WebPageRequest; 23 import com.openedit.generators.Output; 24 import com.openedit.page.Page; 25 import com.openedit.page.PageRequestKeys; 26 import com.openedit.page.PageStreamer; 27 28 29 34 public class HtmlErrorHandler implements ErrorHandler 35 { 36 protected String fieldPathToErrorFile; 37 private static final Log log = LogFactory.getLog(HtmlErrorHandler.class); 38 39 40 43 public boolean handleError(Exception error, WebPageRequest context ) 44 { 45 if (context != null) 46 { 47 try 48 { 49 if ( !(error instanceof OpenEditException)) 50 { 51 error = new OpenEditException(error); } 53 if( !context.hasRedirected() && context.getResponse() != null) 54 { 55 try 56 { 57 context.getResponse().setStatus(500); 58 } 59 catch( Exception ex) 60 { 61 log.info("Ignored:" + ex); 63 } 64 } 65 if( log.isDebugEnabled()) 66 { 67 error.printStackTrace(); 68 } 69 70 context.putPageValue("oe-exception", error); PageStreamer pages = (PageStreamer)context.getPageValue(PageRequestKeys.PAGES); 72 Page errorPage = pages.getPage("/openedit/errorpage.html"); 73 if ( !errorPage.exists() ) 74 { 75 log.error("No error page found" + errorPage.getPath()); 77 return false; 78 } 79 else 80 { 81 Writer out = context.getWriter(); 82 errorPage.generate(context,new Output(out, null)); 83 out.flush(); 84 } 85 } catch ( Exception ex) 86 { 87 log.error( ex); 89 ex.printStackTrace(); 90 try 91 { 92 context.getWriter().write("Check error logs: " + ex); 93 } 95 catch (Throwable ex1) 96 { 97 log.error( ex1 ); 98 } 99 } 100 return true; 101 } 102 return false; 103 } 104 105 106 } 107
| Popular Tags
|