001 package railo.runtime.tag; 002 003 import railo.runtime.PageSource; 004 import railo.runtime.err.ErrorPageImpl; 005 import railo.runtime.exp.ExpressionException; 006 import railo.runtime.exp.MissingIncludeException; 007 import railo.runtime.ext.tag.TagImpl; 008 009 /** 010 * Enables the display of customized HTML pages when errors occur. This lets you maintain a 011 * consistent look and feel within your application, even when errors occur. 012 * 013 * 014 * 015 **/ 016 public final class Error extends TagImpl { 017 018 019 private ErrorPageImpl errorPage=new ErrorPageImpl(); 020 021 022 023 @Override 024 public void release() { 025 super.release(); 026 errorPage=new ErrorPageImpl(); 027 //exception="any"; 028 //template=null; 029 //mailto=""; 030 031 } 032 033 /** set the value exception 034 * Type of exception. Required if type = "exception" or "monitor". 035 * @param exception value to set 036 **/ 037 public void setException(String exception) { 038 errorPage.setTypeAsString(exception.toLowerCase().trim()); 039 //this.exception=exception.toLowerCase().trim(); 040 } 041 042 /** set the value type 043 * The type of error that the custom error page handles. 044 * @param type value to set 045 * @throws ExpressionException 046 **/ 047 public void setType(String type) throws ExpressionException { 048 type=type.toLowerCase().trim(); 049 if(type.equals("exception")) { 050 errorPage.setType(ErrorPageImpl.TYPE_EXCEPTION); 051 } 052 else if(type.equals("request")) { 053 errorPage.setType(ErrorPageImpl.TYPE_REQUEST); 054 } 055 //else if(type.equals("validation")) this.type=VALIDATION; 056 else throw new ExpressionException("invalid type ["+type+"] for tag error, use one of the following types [exception,request]"); 057 } 058 059 /** set the value template 060 * The relative path to the custom error page. 061 * @param template value to set 062 * @throws MissingIncludeException 063 **/ 064 public void setTemplate(String template) throws MissingIncludeException { 065 PageSource sf=pageContext.getCurrentPageSource().getRealPage(template); 066 //new PageSource(pageContext.getCurrentTemplateSourceFile(),template); 067 if(!sf.exists()) 068 throw new MissingIncludeException(sf); 069 errorPage.setTemplate(sf); 070 } 071 072 /** set the value mailto 073 * The e-mail address of the administrator to notify of the error. The value 074 * is available to your custom error page in the MailTo property of the error object. 075 * @param mailto value to set 076 **/ 077 public void setMailto(String mailto) { 078 errorPage.setMailto(mailto); 079 } 080 081 082 @Override 083 public int doStartTag() { 084 if(errorPage.getType()==ErrorPageImpl.TYPE_REQUEST) errorPage.setException("any"); 085 pageContext.setErrorPage(errorPage); 086 return SKIP_BODY; 087 } 088 089 @Override 090 public int doEndTag() { 091 return EVAL_PAGE; 092 } 093 }