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.err; 020 021import java.util.ArrayList; 022 023import lucee.runtime.exp.PageException; 024 025/** 026 * Handle Page Errors 027 */ 028public final class ErrorPagePool { 029 030 private ArrayList<ErrorPage> pages=new ArrayList<ErrorPage>(); 031 private boolean hasChanged=false; 032 033 /** 034 * sets the page error 035 * @param errorPage 036 */ 037 public void setErrorPage(ErrorPage errorPage) { 038 pages.add(errorPage); 039 hasChanged=true; 040 } 041 042 /** 043 * returns the error page 044 * @param pe Page Exception 045 * @return 046 */ 047 public ErrorPage getErrorPage(PageException pe, short type) { 048 for(int i=pages.size()-1;i>=0;i--) { 049 ErrorPageImpl ep=(ErrorPageImpl) pages.get(i); 050 if(ep.getType()==type) { 051 if(type==ErrorPageImpl.TYPE_EXCEPTION){ 052 if(pe.typeEqual(ep.getTypeAsString()))return ep; 053 } 054 else return ep; 055 056 } 057 } 058 return null; 059 } 060 061 062 063 /** 064 * clear the error page pool 065 */ 066 public void clear() { 067 if(hasChanged) { 068 pages.clear(); 069 } 070 hasChanged=false; 071 } 072 073 /** 074 * remove this error page 075 * @param type 076 */ 077 public void removeErrorPage(PageException pe) { 078 // exception 079 ErrorPage ep = getErrorPage(pe,ErrorPageImpl.TYPE_EXCEPTION); 080 if(ep!=null){ 081 pages.remove(ep); 082 hasChanged=true; 083 } 084 // request 085 ep = getErrorPage(pe,ErrorPageImpl.TYPE_REQUEST); 086 if(ep!=null){ 087 pages.remove(ep); 088 hasChanged=true; 089 } 090 // validation 091 ep = getErrorPage(pe,ErrorPageImpl.TYPE_VALIDATION); 092 if(ep!=null){ 093 pages.remove(ep); 094 hasChanged=true; 095 } 096 097 } 098 099}