示例#1
0
 public void set_variable(String s, Object o) {
   try {
     main_interpreter.set(s, o);
   } catch (EvalError evalError) {
     evalError.printStackTrace();
   }
 }
示例#2
0
  public static void main(String[] args) throws EvalError {
    String cf = "\"sdfsdfsdf【\"+@UUID()+\"】SDFSDFSDF\"";
    CFormExp exp = new CFormExp("3", new HashMap());
    String ret = exp.eval_UUID(cf);
    System.out.println(ret);
    Interpreter i = new Interpreter();
    try {
      cf = i.eval(ret) + "";
    } catch (EvalError e) {
      e.printStackTrace();
    }

    System.out.println("计算结果:" + cf);
    //
    //

    //
    //		Interpreter i = new Interpreter();
    //		i.set("DEPTNAME", new String("SSS"));
    //		Object x = i.eval("DEPTNAME.eq(\"SSS\")");
    //		System.out.println(x);

    //		Interpreter i = new Interpreter();
    //		i.set("A", 100);
    //		i.set("B", 200);
    //		i.set("C", 150);
    //		System.out.println(i.eval("(A<B) && (A>C)"));
    //		String v = exp.eval_SYSDT("@SYSDT(\"\")+@SYSDT(\"\")");
    //		System.out.println(v);

  }
示例#3
0
  /**
   * 计算公式
   *
   * @param cf
   * @return
   * @throws Exception
   */
  public String eval(String cf) {
    if (StringUtil.isNotEmpty(cf)) {
      cf = StringUtil.decodeChars(cf, "@,>,<,+,-,?,(,), ,.,:,\",'");
    }

    cf = eval_VALUE(cf); // 1.匹配@VALUE公式
    cf = eval_CONTEXT(cf); // 1.匹配@CONTEXT公式
    cf = eval_PARSENUMBER(cf); // 2.匹配@PARSENUMBER();公式
    cf = eval_SYSDT(cf); // 3.匹配@SYSDT公式
    cf = eval_GROUPNAME(cf); // 4.匹配@GROUPNAME公式
    cf = eval_GROUPSHORTNAME(cf); // 5.匹配@GROUPSHORTNAME公式
    cf = eval_HTTPSESSION(cf); // 6.匹配@HTTPSESSION公式
    cf = eval_USERLOGINNAME(cf); // 7.匹配@USERLOGINNAME公式
    cf = eval_USERLOGINID(cf); // 8.匹配@USERLOGINID公式
    cf = eval_USERCNAME(cf); // 9.匹配@USERCNAME公式
    cf = eval_SQL(cf); // 10.匹配@SQL公式
    cf = eval_UUID(cf); // 11.匹配@UUID公式
    cf = eval_INVOKE(cf); // 11.匹配@UUID公式
    cf = eval_IF(cf); // 12.匹配@IF公式

    Interpreter i = new Interpreter();
    try {
      cf = i.eval(cf) + "";
    } catch (EvalError e) {
      e.printStackTrace();
      String msg = e.getMessage();
      msg = StringUtil.formatHTML(msg);
      return "%ERROR%";
    }
    return cf;
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String formula = request.getParameter("formula");

    if (formula == null) return;

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

    try {
      Object resultado = getNegocio().executarFormula(formula);
      out.println("<b><font color='blue'>Fórmula:</font></b>" + "<b>" + formula + "</b>" + "<br>");
      out.println(
          "<b><font color='blue'>Resultado:</font></b>" + "<b>" + resultado + "</b>" + "<br>");
      out.println(
          "<b><font color='black'>Execução:</font></b>"
              + "<b>"
              + sdf.format(new Date())
              + "</b>"
              + "<br>");
    } catch (EvalError e) {
      out.println(
          "<b><font color='red'>Erro ao executar fórmula:</font></b>"
              + "<b>"
              + e.getMessage()
              + "</b>"
              + "<br>");
      e.printStackTrace();
    }
  }
示例#5
0
 public Object get(String s) {
   try {
     return main_interpreter.get(s);
   } catch (EvalError evalError) {
     evalError.printStackTrace();
   }
   return null;
 }
示例#6
0
 public Object evaluate(String s) {
   System.out.println(s);
   evaluations += s;
   try {
     return main_interpreter.eval(s);
   } catch (EvalError evalError) {
     evalError.printStackTrace();
   }
   return null;
 }
示例#7
0
 /**
  * 初始化变量环境
  *
  * @param i
  * @throws EvalError
  */
 private void initEvalContext(Interpreter i) throws EvalError {
   Set vars = this.context.getVars();
   Iterator iterator = vars.iterator();
   while (iterator.hasNext()) {
     String var = iterator.next() + "";
     Object obj = context.getVar(var);
     try {
       i.set(var, obj);
     } catch (EvalError e) {
       e.printStackTrace();
     }
   }
 }