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 /** 024 * @see javax.servlet.jsp.tagext.Tag#release() 025 */ 026 public void release() { 027 super.release(); 028 errorPage=new ErrorPageImpl(); 029 //exception="any"; 030 //template=null; 031 //mailto=""; 032 033 } 034 035 /** set the value exception 036 * Type of exception. Required if type = "exception" or "monitor". 037 * @param exception value to set 038 **/ 039 public void setException(String exception) { 040 errorPage.setTypeAsString(exception.toLowerCase().trim()); 041 //this.exception=exception.toLowerCase().trim(); 042 } 043 044 /** set the value type 045 * The type of error that the custom error page handles. 046 * @param type value to set 047 * @throws ExpressionException 048 **/ 049 public void setType(String type) throws ExpressionException { 050 type=type.toLowerCase().trim(); 051 if(type.equals("exception")) { 052 errorPage.setType(ErrorPageImpl.TYPE_EXCEPTION); 053 } 054 else if(type.equals("request")) { 055 errorPage.setType(ErrorPageImpl.TYPE_REQUEST); 056 } 057 //else if(type.equals("validation")) this.type=VALIDATION; 058 else throw new ExpressionException("invalid type ["+type+"] for tag error, use one of the following types [exception,request]"); 059 } 060 061 /** set the value template 062 * The relative path to the custom error page. 063 * @param template value to set 064 * @throws MissingIncludeException 065 **/ 066 public void setTemplate(String template) throws MissingIncludeException { 067 PageSource sf=pageContext.getCurrentPageSource().getRealPage(template); 068 //new PageSource(pageContext.getCurrentTemplateSourceFile(),template); 069 if(!sf.exists()) 070 throw new MissingIncludeException(sf); 071 errorPage.setTemplate(sf); 072 } 073 074 /** set the value mailto 075 * The e-mail address of the administrator to notify of the error. The value 076 * is available to your custom error page in the MailTo property of the error object. 077 * @param mailto value to set 078 **/ 079 public void setMailto(String mailto) { 080 errorPage.setMailto(mailto); 081 } 082 083 084 /** 085 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 086 */ 087 public int doStartTag() { 088 if(errorPage.getType()==ErrorPageImpl.TYPE_REQUEST) errorPage.setException("any"); 089 pageContext.setErrorPage(errorPage); 090 return SKIP_BODY; 091 } 092 093 /** 094 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 095 */ 096 public int doEndTag() { 097 return EVAL_PAGE; 098 } 099 }