@Test public void testRealJavaScriptExampleSimple() throws ScriptException { JavaScriptEnv jsEnv = new JavaScriptEnv(); Map<String, String> record = new HashMap<>(); assertTrue(jsEnv.evalFilter("true === true", record)); assertFalse(jsEnv.evalFilter("true === false", record)); }
public boolean evalFilter(String s, Map<String, String> record) throws ScriptException { Gson gson = new Gson(); ScriptEngine engine = this.factory.getEngineByName("JavaScript"); String recordJson = gson.toJson(record); engine.put("record_json", recordJson); try { s = "var record = new Object(JSON.parse(record_json));" + s; return (boolean) engine.eval(s); } catch (NullPointerException e) { throw new NullPointerException("The record filter should return either true or false! -- " + e.toString()); } }
JavaScriptEnv { public boolean evalFilter(String s, Map<String, String> record) throws ScriptException { Gson gson = new Gson(); ScriptEngine engine = this.factory.getEngineByName("JavaScript"); String recordJson = gson.toJson(record); engine.put("record_json", recordJson); try { s = "var record = new Object(JSON.parse(record_json));" + s; return (boolean) engine.eval(s); } catch (NullPointerException e) { throw new NullPointerException("The record filter should return either true or false! -- " + e.toString()); } } }
JavaScriptEnv { public boolean evalFilter(String s, Map<String, String> record) throws ScriptException { Gson gson = new Gson(); ScriptEngine engine = this.factory.getEngineByName("JavaScript"); String recordJson = gson.toJson(record); engine.put("record_json", recordJson); try { s = "var record = new Object(JSON.parse(record_json));" + s; return (boolean) engine.eval(s); } catch (NullPointerException e) { throw new NullPointerException("The record filter should return either true or false! -- " + e.toString()); } } JavaScriptEnv(); }
JavaScriptEnv { public boolean evalFilter(String s, Map<String, String> record) throws ScriptException { Gson gson = new Gson(); ScriptEngine engine = this.factory.getEngineByName("JavaScript"); String recordJson = gson.toJson(record); engine.put("record_json", recordJson); try { s = "var record = new Object(JSON.parse(record_json));" + s; return (boolean) engine.eval(s); } catch (NullPointerException e) { throw new NullPointerException("The record filter should return either true or false! -- " + e.toString()); } } JavaScriptEnv(); boolean evalFilter(String s, Map<String, String> record); }
JavaScriptEnv { public boolean evalFilter(String s, Map<String, String> record) throws ScriptException { Gson gson = new Gson(); ScriptEngine engine = this.factory.getEngineByName("JavaScript"); String recordJson = gson.toJson(record); engine.put("record_json", recordJson); try { s = "var record = new Object(JSON.parse(record_json));" + s; return (boolean) engine.eval(s); } catch (NullPointerException e) { throw new NullPointerException("The record filter should return either true or false! -- " + e.toString()); } } JavaScriptEnv(); boolean evalFilter(String s, Map<String, String> record);  }