2017-08-11 68 views
1

如何獲取未知變量的所有警告消息?JEXL - 如何獲取未知變量的所有警告消息?

我有一個表達式,我想評估和知道所有缺少的變量。

實施例:

jexl.setStrict(false); 
Expression e = (Expression) jexl.createExpression("(pqr||abc)&&xyx&&!(rsw||ruy)&&!sss"); 

JexlContext context = new MapContext(); 
context.set("rsw",false); 
context.set("xyx",true); 
Object obj=e.evaluate(context); 
System.out.println(obj); 

輸出:

Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable 
WARNING: [email protected]![1,4]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable pqr 
false 
Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable 
WARNING: [email protected]![8,11]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable abc 

我想捕捉兩個未定義變量。如果我設置jexl.setStrict(true)並添加try和catch塊,我只能捕獲一個變量。

catch(JexlException.Variable xjexl)  { 
      System.out.println("Exception:" +xjexl.getVariable());   
      xjexl.printStackTrace(); 
     } 

我很樂意使用其他技術。

回答

0

我能夠解決以下getVariables()方法。

樣品:

jexl.createScript( 「!(PQR || ABC)& & XYX & &(RSW ||魯伊)& & SSS」)getVariables();