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.exp;
020
021import lucee.commons.lang.ExceptionUtil;
022
023
024/**
025 * This Exception will be Throwed, when page Excecution will be aborted (tag abort).
026 */
027public class Abort extends AbortException {
028
029    public final static int SCOPE_PAGE=0;
030    public final static int SCOPE_REQUEST=1;
031    private int scope;
032    
033        /**
034         * Constructor of the Class
035         */
036        public Abort(int scope) {
037                super("Page request is aborted");
038        this.scope=scope;
039        }
040        protected Abort(int scope, String msg) {
041                super(msg);
042        this.scope=scope;
043        }
044        public static Abort newInstance(int scope) {
045                return new Abort(scope);
046        }
047    
048    public int getScope() {
049        return scope;
050    }
051        
052        public static boolean isSilentAbort(Throwable t){
053                ExceptionUtil.rethrowIfNecessary(t);
054                if(t instanceof  PageExceptionBox) {
055                        return isSilentAbort(((PageExceptionBox)t).getPageException());
056                }
057                return t instanceof Abort && !(t instanceof RequestTimeoutException);
058        }
059        
060        public static boolean isAbort(Throwable t) {
061                ExceptionUtil.rethrowIfNecessary(t);
062                if(t instanceof Abort) return true;
063                if(t instanceof  PageExceptionBox) {
064                        return (((PageExceptionBox)t).getPageException() instanceof Abort);
065                }
066                return false;
067        }
068
069        public static boolean isAbort(Throwable t, int scope) {
070                ExceptionUtil.rethrowIfNecessary(t);
071                if(t instanceof  PageExceptionBox) {
072                        return isAbort(((PageExceptionBox)t).getPageException(),scope);
073                }
074                return t instanceof Abort && ((Abort) t).getScope()==scope;
075        }
076}