public void loadApplication(cfComponentData applicationCfc, cfSession session)
      throws cfmRunTimeException {
    cfData appName = applicationCfc.getData("NAME");
    cfApplicationData appData =
        getAppData(session, appName == null ? cfAPPLICATION.UNNAMED_APPNAME : appName.toString());

    String scriptProtect = null;
    if (applicationCfc.containsKey(cfAPPLICATION.SCRIPTPROTECT)) {
      scriptProtect = applicationCfc.getData(cfAPPLICATION.SCRIPTPROTECT).getString();
    }

    // Set up the specific application mappings
    if (applicationCfc.containsKey(cfAPPLICATION.MAPPINGS)) {
      cfData mappingsData = (cfData) applicationCfc.getData(cfAPPLICATION.MAPPINGS);
      if (mappingsData.getDataType() == cfData.CFSTRUCTDATA) {
        session.setDataBin(cfAPPLICATION.MAPPINGS, mappingsData);
      }
    }

    // Set up the specific application customtagpaths
    if (applicationCfc.containsKey(cfAPPLICATION.CUSTOMTAGPATHS)) {
      cfData mappingsData = (cfData) applicationCfc.getData(cfAPPLICATION.CUSTOMTAGPATHS);
      if (mappingsData.getDataType() == cfData.CFSTRINGDATA) {
        session.setDataBin(cfAPPLICATION.CUSTOMTAGPATHS, mappingsData.getString());
      }
    }

    String datasource = null;
    if (applicationCfc.containsKey(cfAPPLICATION.DATASOURCE))
      datasource = applicationCfc.getData(cfAPPLICATION.DATASOURCE).getString();

    String sessionstorage = null;
    if (applicationCfc.containsKey(cfAPPLICATION.SESSIONSTORAGE))
      sessionstorage = applicationCfc.getData(cfAPPLICATION.SESSIONSTORAGE).getString();

    appData.onRequestStart(
        session,
        bJ2EESessionManagement,
        (long)
            (applicationCfc.getData(cfAPPLICATION.APPLICATIONTIMEOUT).getDouble()
                * DateUtils.MILLIS_PER_DAY),
        (long)
            (applicationCfc.getData(cfAPPLICATION.SESSIONTIMEOUT).getDouble()
                * DateUtils.MILLIS_PER_DAY),
        applicationCfc.getData(cfAPPLICATION.SETCLIENTCOOKIES).getBoolean(),
        applicationCfc.getData(cfAPPLICATION.SETDOMAINCOOKIES).getBoolean(),
        applicationCfc.getData(cfAPPLICATION.SESSIONMANAGEMENT).getBoolean(),
        applicationCfc.getData(cfAPPLICATION.CLIENTMANAGEMENT).getBoolean(),
        applicationCfc.getData(cfAPPLICATION.CLIENTSTORAGE).getString(),
        applicationCfc.getData(cfAPPLICATION.LOGINSTORAGE).getString(),
        applicationCfc.getComponentPath(),
        scriptProtect,
        applicationCfc.getData(cfAPPLICATION.SECUREJSON).getBoolean(),
        applicationCfc.getData(cfAPPLICATION.SECUREJSONPREFIX).getString(),
        datasource,
        sessionstorage,
        applicationCfc);
  }
  public CFStatementResult Exec(CFContext context) throws cfmRunTimeException {
    setLineCol(context);

    String templatePath = template.EvalFully(context).getString();

    cfSession session = context.getSession();
    cfFile templateFile = cfINCLUDE.loadTemplate(session, templatePath);
    session.write(templateFile.renderToString(session).getOutput());

    return null;
  }
Exemple #3
0
  private void fixQueryParam(cfSession _Session, cfArgStructData functionArgs)
      throws dataNotSupportedException {
    cfData queryData = functionArgs.getData("QUERY");

    if (queryData == null || queryData.getDataType() == cfData.CFQUERYRESULTDATA) return;

    cfData queryObj = _Session.getData(queryData.getString());
    functionArgs.setData("QUERY", queryObj);
  }
Exemple #4
0
  private cfTagReturnType renderOptimzedSwitch(String expr, cfSession _Session)
      throws cfmRunTimeException {
    cfCASE thisCase = (cfCASE) caseMap.get(expr);
    cfTagReturnType rt = null;

    if (thisCase != null) {
      _Session.pushTag(thisCase);
      rt = thisCase.render(_Session);
    } else if (defaultCase != null) {
      _Session.pushTag(defaultCase);
      rt = defaultCase.render(_Session);
    } else {
      // we didn't do anything, so don't invoke _Session.popTag() or return rt
      return cfTagReturnType.NORMAL;
    }

    _Session.popTag();
    return rt;
  }
  public static void onApplicationEnd(cfApplicationData appData) {
    String applicationCfcPath = appData.getApplicationCfcPath();
    if (applicationCfcPath == null) return;

    cfSession session =
        new cfSession(
            new dummyServletRequest(appData.getWebroot()),
            new dummyServletResponse(),
            cfEngine.thisServletContext);
    cfComponentData applicationCfc = null;

    try {
      cfFile applicationFile = session.getRealFile(applicationCfcPath);
      applicationFile.setComponentName("Application");

      applicationCfc =
          new cfComponentData(session, applicationFile, false); // false = don't allow abstract

      List<cfApplicationData> args = new ArrayList<cfApplicationData>();
      args.add(appData); // ApplicationScope

      cfcMethodData methodData = new cfcMethodData(session, ON_APPLICATION_END, args);
      applicationCfc.invokeApplicationFunction(session, methodData);

    } catch (cfmAbortException ignore) {
      // do nothing, we're finished anyway (catch here so it's not caught as Throwable below)
    } catch (cfmRunTimeException e) {
      try {
        session.invokeOnError(applicationCfc, e, ON_APPLICATION_END);
      } catch (cfmRunTimeException ie) {
        cfEngine.log("RunTimeError in onApplicationEnd: " + applicationCfcPath);
        ie.handleException(session);
      }
    } catch (Throwable t) {
      com.nary.Debug.printStackTrace(t);
      new cfmRunTimeException(session, t).handleException(session);
    } finally {
      // Make sure per request connections are closed (bug #3174)
      session.sessionEnd();
    }
  }
  public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    String number = parameters.get(0).getString();
    Number returnNum;
    NumberFormat numFormat = DecimalFormat.getInstance(_session.getLocale());

    // try none, local, international
    try {
      returnNum = numFormat.parse(number);
      return cfNumberData.getNumber(returnNum);
    } catch (java.text.ParseException ignored) {
    }

    try {
      numFormat = DecimalFormat.getCurrencyInstance(_session.getLocale());
      returnNum = numFormat.parse(number);
      return cfNumberData.getNumber(returnNum);

    } catch (java.text.ParseException ignored) {
    }

    // international: can't find a nicer way to do this
    try {
      // we substitute the international currency with the regular currency symbol first
      String intCurrSymbol =
          new DecimalFormatSymbols(_session.getLocale()).getInternationalCurrencySymbol();
      String currSymbol = new DecimalFormatSymbols(_session.getLocale()).getCurrencySymbol();
      number = string.replaceString(number, intCurrSymbol, currSymbol);
      numFormat = DecimalFormat.getCurrencyInstance(_session.getLocale());
      returnNum = numFormat.parse(number);
      return cfNumberData.getNumber(returnNum);
    } catch (java.text.ParseException ignored) {
    }

    throwException(
        _session, "The value '" + number + "' is not a valid currency in the current locale.");

    // keep the compiler happy
    return new cfStringData("");
  }
  public void loadApplication(cfTag parentTag, cfSession _Session) throws cfmRunTimeException {
    // This method is invoked from the CFAPPLICATION tag and will initialise and setup all the
    // application data storage
    String appName = parentTag.getDynamic(_Session, "NAME").getString();

    // Get the application data instance
    cfApplicationData appData = getAppData(_Session, appName);

    String scriptProtect = null;
    if (parentTag.containsAttribute(cfAPPLICATION.SCRIPTPROTECT)) {
      scriptProtect = parentTag.getDynamic(_Session, cfAPPLICATION.SCRIPTPROTECT).getString();
    }

    String datasource = null;
    if (parentTag.containsAttribute(cfAPPLICATION.DATASOURCE))
      datasource = parentTag.getDynamic(_Session, cfAPPLICATION.DATASOURCE).getString();

    String sessionstorage = null;
    if (parentTag.containsAttribute(cfAPPLICATION.SESSIONSTORAGE))
      sessionstorage = parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONSTORAGE).getString();

    if (parentTag.containsAttribute(cfAPPLICATION.CUSTOMTAGPATHS))
      _Session.setDataBin(
          cfAPPLICATION.CUSTOMTAGPATHS,
          parentTag.getDynamic(_Session, cfAPPLICATION.CUSTOMTAGPATHS).getString());

    // Setup the properties of this application
    appData.onRequestStart(
        _Session,
        bJ2EESessionManagement,
        (long)
            (parentTag.getDynamic(_Session, cfAPPLICATION.APPLICATIONTIMEOUT).getDouble()
                * DateUtils.MILLIS_PER_DAY),
        (long)
            (parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONTIMEOUT).getDouble()
                * DateUtils.MILLIS_PER_DAY),
        parentTag.getDynamic(_Session, cfAPPLICATION.SETCLIENTCOOKIES).getBoolean(),
        parentTag.getDynamic(_Session, cfAPPLICATION.SETDOMAINCOOKIES).getBoolean(),
        parentTag.getDynamic(_Session, cfAPPLICATION.SESSIONMANAGEMENT).getBoolean(),
        parentTag.getDynamic(_Session, cfAPPLICATION.CLIENTMANAGEMENT).getBoolean(),
        parentTag.getDynamic(_Session, cfAPPLICATION.CLIENTSTORAGE).getString(),
        parentTag.getDynamic(_Session, cfAPPLICATION.LOGINSTORAGE).getString(),
        null,
        scriptProtect,
        parentTag.getDynamic(_Session, cfAPPLICATION.SECUREJSON).getBoolean(),
        parentTag.getDynamic(_Session, cfAPPLICATION.SECUREJSONPREFIX).getString(),
        datasource,
        sessionstorage,
        null);
  }
Exemple #8
0
  private cfTagReturnType renderDropThruSwitch(String expr, cfSession _Session)
      throws cfmRunTimeException {

    cfTagReturnType rt = cfTagReturnType.NORMAL;
    boolean dropThruExec = false;

    cfTag tagList[] = getTagList();

    for (int i = 0; i < tagList.length; i++) {
      cfTag tag = tagList[i];
      if (tag instanceof cfCASE) {

        if (dropThruExec) {

          _Session.pushTag(tag);
          rt = tag.render(_Session);
          _Session.popTag();
          if (rt.isBreak()) return cfTagReturnType.NORMAL;

        } else {

          String[] values = ((cfCASE) tag).getValues();
          for (int j = 0; j < values.length; j++) {
            if (expr.equals(values[j])) {
              _Session.pushTag(tag);
              rt = tag.render(_Session);
              _Session.popTag();
              if (rt.isBreak()) return cfTagReturnType.NORMAL;
              else dropThruExec = true;
            }
          }
        }
      }
    }

    // Got here, but no CASE was matched
    if (defaultCase != null) {
      _Session.pushTag(defaultCase);
      rt = defaultCase.render(_Session);
      _Session.popTag();
    }

    return rt;
  }
 public static void closeClient(cfSession _Session) throws cfmRunTimeException {
   cfApplicationData application = _Session.getApplicationData();
   if (application != null) application.onRequestEnd(_Session);
 }
Exemple #10
0
  public cfTagReturnType render(cfSession _Session) throws cfmRunTimeException {
    cfStructData attributes = setAttributeCollection(_Session);

    if (!containsAttribute(attributes, "ACTION"))
      throw newRunTimeException("Missing ACTION attribute; valid: update, delete, purge, refresh");

    String action = getDynamic(attributes, _Session, "ACTION").getString().toLowerCase();

    if (action.equals("delete")) {

      functionBase func = new CustomDeleteFunction();
      cfArgStructData functionArgs =
          getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
      func.execute(_Session, functionArgs);
      return cfTagReturnType.NORMAL;

    } else if (action.equals("purge")) {

      functionBase func = new PurgeFunction();
      cfArgStructData functionArgs =
          getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
      func.execute(_Session, functionArgs);
      return cfTagReturnType.NORMAL;

    } else if (action.equals("refresh")) {

      functionBase func = new PurgeFunction();
      cfArgStructData functionArgs =
          getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
      func.execute(_Session, functionArgs);
      action = "update"; // set this to drop into the next IF
    }

    if (action.equals("update")) {

      String type = "custom";
      if (containsAttribute(attributes, "TYPE"))
        type = getDynamic(_Session, "TYPE").getString().toLowerCase();

      String status = null;
      if (containsAttribute(attributes, "STATUS"))
        status = getDynamic(_Session, "STATUS").getString().toLowerCase();

      attributes = provideSupportForCustom1234(_Session, attributes);

      cfData returnStatus = null;

      if (type.equals("custom")) {

        functionBase func = new CustomFunction();
        cfArgStructData functionArgs =
            getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
        fixQueryParam(_Session, functionArgs);
        returnStatus = func.execute(_Session, functionArgs);

      } else if (type.equals("file")) {

        functionBase func = new FileFunction();
        cfArgStructData functionArgs =
            getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
        fixQueryParam(_Session, functionArgs);
        returnStatus = func.execute(_Session, functionArgs);

      } else if (type.equals("path")) {

        functionBase func = new PathFunction();
        cfArgStructData functionArgs =
            getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
        fixQueryParam(_Session, functionArgs);
        returnStatus = func.execute(_Session, functionArgs);

      } else if (type.equals("website")) {

        functionBase func = new WebFunction();
        cfArgStructData functionArgs =
            getFunctionArgsFromAttributes(_Session, func.getFormals(), attributes);
        returnStatus = func.execute(_Session, functionArgs);

      } else
        throw newRunTimeException("invalid TYPE attribute; valid: custom, file, path, website");

      // Set the status
      if (returnStatus != null && status != null) _Session.setData(status, returnStatus);

    } else
      throw newRunTimeException("invalid ACTION attribute; valid: update, delete, purge, refresh");

    return cfTagReturnType.NORMAL;
  }
  public void retrieveOutVariables(int ColIndex, cfSession _Session, CallableStatement _stmt)
      throws SQLException, cfmRunTimeException {
    boolean b;
    byte[] bin;
    int i;
    long l;
    double dbl;
    float flt;
    java.sql.Date dt;
    java.sql.Time t;
    Timestamp ts;
    ResultSet rs;
    String str;
    cfData outData = null;

    if (!isOUT()) return;

    switch (cfSqlType) {
      case CF_SQL_BIT:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          b = _stmt.getBoolean(paramName);
        } else {
          b = _stmt.getBoolean(ColIndex);
        }
        if (!_stmt.wasNull()) outData = cfBooleanData.getcfBooleanData(b);
        break;

      case CF_SQL_BINARY:
      case CF_SQL_VARBINARY:
      case CF_SQL_BLOB:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          bin = _stmt.getBytes(paramName);
        } else {
          bin = _stmt.getBytes(ColIndex);
        }

        if ((!_stmt.wasNull()) && (bin != null)) {
          outData = new cfBinaryData(bin);
        }
        break;

      case CF_SQL_SMALLINT:
      case CF_SQL_INTEGER:
      case CF_SQL_TINYINT:
        try {
          // With the Oracle JDBC driver, if we set the parameters using named parameters then
          // we must retrieve them using named parameters too.
          if (useNamedParameters) {
            i = _stmt.getInt(paramName);
          } else {
            i = _stmt.getInt(ColIndex);
          }

          if (!_stmt.wasNull()) outData = new cfNumberData(i);
        } catch (NumberFormatException e) {
          // With JDK 1.3 and the JDBC-ODBC bridge, the getInt() method will
          // throw a number format exception for in/out params so just ignore it.
          // Ignoring it allows us to retrieve the out param values.
        }
        break;

      case CF_SQL_BIGINT:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          l = _stmt.getLong(paramName);
        } else {
          l = _stmt.getLong(ColIndex);
        }

        if (!_stmt.wasNull()) outData = new cfNumberData(l);
        break;

      case CF_SQL_DECIMAL:
      case CF_SQL_NUMERIC:
        dbl = getBigDecimalAsDouble(_stmt, useNamedParameters, paramName, ColIndex);
        if (!_stmt.wasNull()) outData = new cfNumberData(dbl);
        break;

      case CF_SQL_DOUBLE:
      case CF_SQL_FLOAT:
      case CF_SQL_MONEY:
      case CF_SQL_MONEY4:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          dbl = _stmt.getDouble(paramName);
        } else {
          dbl = _stmt.getDouble(ColIndex);
        }

        if (!_stmt.wasNull()) outData = new cfNumberData(dbl);
        break;

      case CF_SQL_REAL:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          flt = _stmt.getFloat(paramName);
        } else {
          flt = _stmt.getFloat(ColIndex);
        }

        // For some reason casting a float to a double doesn't return a double
        // that exactly matches the original float so we'll use the less efficient
        // algorithm of converting the float to a string and the string to a double.
        // If for some reason this fails then we'll revert to casting the float to
        // a double.
        if (!_stmt.wasNull()) {
          try {
            dbl = Double.valueOf(Float.toString(flt)).doubleValue();
          } catch (Exception e) {
            dbl = (double) flt;
          }
          outData = new cfNumberData(dbl);
        }
        break;

      case CF_SQL_DATE:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          dt = _stmt.getDate(paramName);
        } else {
          dt = _stmt.getDate(ColIndex);
        }

        if ((!_stmt.wasNull()) && (dt != null)) {
          outData = new cfDateData(dt);
        }
        break;

      case CF_SQL_TIME:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          t = _stmt.getTime(paramName);
        } else {
          t = _stmt.getTime(ColIndex);
        }

        if ((!_stmt.wasNull()) && (t != null)) {
          outData = new cfDateData(t);
        }
        break;

      case CF_SQL_TIMESTAMP:
        try {
          // With the Oracle JDBC driver, if we set the parameters using named parameters then
          // we must retrieve them using named parameters too.
          if (useNamedParameters) {
            ts = _stmt.getTimestamp(paramName);
          } else {
            ts = _stmt.getTimestamp(ColIndex);
          }

          if ((!_stmt.wasNull()) && (ts != null)) {
            outData = new cfDateData(ts);
          }
        } catch (NullPointerException e) {
          // With JDK 1.3 and the JDBC-ODBC bridge, the getTimestamp() method will
          // throw a null ptr exception when the underlying value is null so just ignore it.
        }
        break;

      case CF_SQL_REFCURSOR:
        // This CF SQL Type is only used with Oracle for result sets returned by a
        // stored procedure.

        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          rs = (ResultSet) _stmt.getObject(paramName);
        } else {
          rs = (ResultSet) _stmt.getObject(ColIndex);
        }

        if ((!_stmt.wasNull()) && (rs != null)) {
          outData = new cfQueryResultData(rs, "Stored Procedure", maxLength);
        }
        break;

      default:
        // With the Oracle JDBC driver, if we set the parameters using named parameters then
        // we must retrieve them using named parameters too.
        if (useNamedParameters) {
          str = _stmt.getString(paramName);
        } else {
          str = _stmt.getString(ColIndex);
        }

        if ((!_stmt.wasNull()) && (str != null)) {
          outData = new cfStringData(str);
        }
        break;
    }

    _Session.setData(outVariable, (outData == null ? cfNullData.NULL : outData));
  }