Exemplo n.º 1
0
  static void _onRequest(
      PageContext pc, PageSource requestedPage, PageSource application, RequestListener rl)
      throws PageException {
    ((PageContextImpl) pc).setAppListenerType(AppListenerUtil.TYPE_CLASSIC);

    // on requestStart
    if (application != null) pc.doInclude(new PageSource[] {application}, false);

    if (rl != null) {
      requestedPage = rl.execute(pc, requestedPage);
      if (requestedPage == null) return;
    }

    // request
    try {
      pc.doInclude(new PageSource[] {requestedPage}, false);
    } catch (MissingIncludeException mie) {
      ApplicationContext ac = pc.getApplicationContext();
      boolean rethrow = true;
      if (ac instanceof ClassicApplicationContext) {
        ClassicApplicationContext cfc = (ClassicApplicationContext) ac;
        UDF udf = cfc.getOnMissingTemplate();
        if (udf != null) {
          String targetPage = requestedPage.getFullRealpath();
          rethrow = (!Caster.toBooleanValue(udf.call(pc, new Object[] {targetPage}, true), true));
        }
      }
      if (rethrow) throw mie;
    }

    // on Request End
    if (application != null) {
      PageSource onReqEnd = application.getRealPage("OnRequestEnd.cfm");
      if (onReqEnd.exists()) pc.doInclude(new PageSource[] {onReqEnd}, false);
    }
  }