001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import lucee.runtime.PageSource; 022import lucee.runtime.err.ErrorPageImpl; 023import lucee.runtime.exp.ExpressionException; 024import lucee.runtime.exp.MissingIncludeException; 025import lucee.runtime.ext.tag.TagImpl; 026 027/** 028* Enables the display of customized HTML pages when errors occur. This lets you maintain a 029* consistent look and feel within your application, even when errors occur. 030* 031* 032* 033**/ 034public final class Error extends TagImpl { 035 036 037 private ErrorPageImpl errorPage=new ErrorPageImpl(); 038 039 040 041 @Override 042 public void release() { 043 super.release(); 044 errorPage=new ErrorPageImpl(); 045 //exception="any"; 046 //template=null; 047 //mailto=""; 048 049 } 050 051 /** set the value exception 052 * Type of exception. Required if type = "exception" or "monitor". 053 * @param exception value to set 054 **/ 055 public void setException(String exception) { 056 errorPage.setTypeAsString(exception.toLowerCase().trim()); 057 //this.exception=exception.toLowerCase().trim(); 058 } 059 060 /** set the value type 061 * The type of error that the custom error page handles. 062 * @param type value to set 063 * @throws ExpressionException 064 **/ 065 public void setType(String type) throws ExpressionException { 066 type=type.toLowerCase().trim(); 067 if(type.equals("exception")) { 068 errorPage.setType(ErrorPageImpl.TYPE_EXCEPTION); 069 } 070 else if(type.equals("request")) { 071 errorPage.setType(ErrorPageImpl.TYPE_REQUEST); 072 } 073 //else if(type.equals("validation")) this.type=VALIDATION; 074 else throw new ExpressionException("invalid type ["+type+"] for tag error, use one of the following types [exception,request]"); 075 } 076 077 /** set the value template 078 * The relative path to the custom error page. 079 * @param template value to set 080 * @throws MissingIncludeException 081 **/ 082 public void setTemplate(String template) throws MissingIncludeException { 083 PageSource ps=pageContext.getCurrentPageSource().getRealPage(template); 084 if(!ps.exists()) 085 throw new MissingIncludeException(ps); 086 errorPage.setTemplate(ps); 087 } 088 089 /** set the value mailto 090 * The e-mail address of the administrator to notify of the error. The value 091 * is available to your custom error page in the MailTo property of the error object. 092 * @param mailto value to set 093 **/ 094 public void setMailto(String mailto) { 095 errorPage.setMailto(mailto); 096 } 097 098 099 @Override 100 public int doStartTag() { 101 if(errorPage.getType()==ErrorPageImpl.TYPE_REQUEST) errorPage.setException("any"); 102 pageContext.setErrorPage(errorPage); 103 return SKIP_BODY; 104 } 105 106 @Override 107 public int doEndTag() { 108 return EVAL_PAGE; 109 } 110}