001    package railo.runtime.listener;
002    
003    import java.io.IOException;
004    
005    import railo.runtime.CFMLFactory;
006    import railo.runtime.PageContext;
007    import railo.runtime.PageSource;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.op.Caster;
010    
011    public final class ClassicAppListener extends AppListenerSupport {
012    
013            private int mode=MODE_CURRENT2ROOT;
014            private String type;
015    
016    
017            /**
018             *
019             * @see railo.runtime.listener.ApplicationListener#onRequest(railo.runtime.PageContext, railo.runtime.PageSource)
020             */
021            public void onRequest(PageContext pc,PageSource requestedPage) throws PageException {
022                    
023                    PageSource application=//pc.isCFCRequest()?null:
024                            AppListenerUtil.getApplicationPageSource(pc,requestedPage,"Application.cfm",mode);
025                    
026                    _onRequest(pc, requestedPage, application);
027            }
028            
029            static void _onRequest(PageContext pc,PageSource requestedPage,PageSource application) throws PageException {
030                    
031                    // on requestStart
032                    if(application!=null)pc.doInclude(application);
033                    
034                    // request
035                    pc.doInclude(requestedPage);
036                    
037                    // on Request End
038                    if(application!=null){
039                            PageSource onReqEnd = application.getRealPage("OnRequestEnd.cfm");
040                    if(onReqEnd.exists())pc.doInclude(onReqEnd);
041                    }
042            }
043    
044            /**
045             * @see railo.runtime.listener.ApplicationListener#onApplicationStart(railo.runtime.PageContext)
046             */
047            public boolean onApplicationStart(PageContext pc) throws PageException {
048                    // do nothing
049                    return true;
050            }
051    
052            /**
053             *
054             * @see railo.runtime.listener.ApplicationListener#onSessionStart(railo.runtime.PageContext)
055             */
056            public void onSessionStart(PageContext pc) throws PageException {
057                    // do nothing
058            }
059    
060            /**
061             *
062             * @see railo.runtime.listener.ApplicationListener#onApplicationEnd(railo.runtime.CFMLFactory, java.lang.String)
063             */
064            public void onApplicationEnd(CFMLFactory factory, String applicationName) throws PageException {
065                    // do nothing   
066            }
067    
068            /**
069             *
070             * @see railo.runtime.listener.ApplicationListener#onSessionEnd(railo.runtime.CFMLFactory, java.lang.String, java.lang.String)
071             */
072            public void onSessionEnd(CFMLFactory cfmlFactory, String applicationName, String cfid) throws PageException {
073                    // do nothing
074            }
075    
076            /**
077             * @see railo.runtime.listener.ApplicationListener#onDebug(railo.runtime.PageContext)
078             */
079            public void onDebug(PageContext pc) throws PageException {
080                    try {
081                            pc.getDebugger().writeOut(pc);
082                    } 
083                    catch (IOException e) {
084                            throw Caster.toPageException(e);
085                    }
086            }
087    
088            /**
089             *
090             * @see railo.runtime.listener.ApplicationListener#onError(railo.runtime.PageContext, railo.runtime.exp.PageException)
091             */
092            public void onError(PageContext pc,PageException pe) {
093                    pc.handlePageException(pe);
094            }
095    
096    
097            /**
098             *
099             * @see railo.runtime.listener.ApplicationListener#setMode(int)
100             */
101            public void setMode(int mode) {
102                    this.mode=mode;
103            }
104    
105            /**
106             *
107             * @see railo.runtime.listener.ApplicationListener#getMode()
108             */
109            public int getMode() {
110                    return mode;
111            }
112    
113            /**
114             * @return the type
115             */
116            public String getType() {
117                    return type;
118            }
119    
120            /**
121             * @param type the type to set
122             */
123            public void setType(String type) {
124                    this.type = type;
125            }
126    }