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.listener;
020
021import lucee.commons.lang.types.RefBoolean;
022import lucee.commons.lang.types.RefBooleanImpl;
023import lucee.runtime.PageContext;
024import lucee.runtime.PageContextImpl;
025import lucee.runtime.PageSource;
026import lucee.runtime.engine.ThreadLocalPageContext;
027import lucee.runtime.exp.PageException;
028
029public final class MixedAppListener extends ModernAppListener {
030
031        @Override
032        public void onRequest(PageContext pc, PageSource requestedPage, RequestListener rl) throws PageException {
033                RefBoolean isCFC=new RefBooleanImpl(false);
034                PageSource appPS=//pc.isCFCRequest()?null:
035                        AppListenerUtil.getApplicationPageSource(pc, requestedPage, mode,AppListenerUtil.TYPE_ALL, isCFC);
036                
037                if(isCFC.toBooleanValue())_onRequest(pc, requestedPage,appPS,rl);
038                else ClassicAppListener._onRequest(pc, requestedPage,appPS,rl);
039        }
040        
041        @Override
042        public final String getType() {
043                return "mixed";
044        }
045
046        @Override
047        public void onDebug(PageContext pc) throws PageException {
048                if(((PageContextImpl)pc).getAppListenerType()==AppListenerUtil.TYPE_CLASSIC) 
049                        ClassicAppListener._onDebug(pc);
050                else super.onDebug(pc);
051        }
052
053        @Override
054        public void onError(PageContext pc, PageException pe) {
055                if(((PageContextImpl)pc).getAppListenerType()==AppListenerUtil.TYPE_CLASSIC) 
056                        ClassicAppListener._onError(pc,pe);
057                else super.onError(pc, pe);
058        }
059
060        @Override
061        public boolean hasOnSessionStart(PageContext pc) {
062                if(((PageContextImpl)pc).getAppListenerType()==AppListenerUtil.TYPE_CLASSIC) 
063                        return ClassicAppListener._hasOnSessionStart(pc);
064                return super.hasOnSessionStart(pc);
065        }
066
067        @Override
068        public boolean hasOnApplicationStart() {
069                PageContext pc = ThreadLocalPageContext.get();
070                if(pc!=null && ((PageContextImpl)pc).getAppListenerType()==AppListenerUtil.TYPE_CLASSIC) 
071                        return ClassicAppListener._hasOnApplicationStart();
072                return super.hasOnApplicationStart();
073        }
074
075        @Override
076        public void onTimeout(PageContext pc) {
077                if(((PageContextImpl)pc).getAppListenerType()==AppListenerUtil.TYPE_CLASSIC) 
078                        ClassicAppListener._onTimeout(pc);
079                else super.onTimeout(pc);
080        }
081}