@Test public void testRegisterScript() throws Exception { File file = Paths.get(getClass().getClassLoader().getResource("TestValidator.js").toURI()).normalize().toFile(); ScriptValidatorService service = new ScriptValidatorService(); service.registerScript(file); assertEquals(1, service.getRegexNames().size()); assertEquals("TEST", service.getRegexNames().get(0)); }
protected void registerScript(File file) { try { Invocable script = loadScript(manager, file); Bindings bindings = (Bindings) script.invokeFunction("getRegexNames"); List<String> regexNames = getStringArrayValues(bindings); for (String regexName : regexNames) { scripts.put(regexName, script); } } catch (NoSuchMethodException | IOException | ScriptException e) { throw new RuntimeException(e); } }
ScriptValidatorService implements RegexValidatorService { protected void registerScript(File file) { try { Invocable script = loadScript(manager, file); Bindings bindings = (Bindings) script.invokeFunction("getRegexNames"); List<String> regexNames = getStringArrayValues(bindings); for (String regexName : regexNames) { scripts.put(regexName, script); } } catch (NoSuchMethodException | IOException | ScriptException e) { throw new RuntimeException(e); } } }
ScriptValidatorService implements RegexValidatorService { protected void registerScript(File file) { try { Invocable script = loadScript(manager, file); Bindings bindings = (Bindings) script.invokeFunction("getRegexNames"); List<String> regexNames = getStringArrayValues(bindings); for (String regexName : regexNames) { scripts.put(regexName, script); } } catch (NoSuchMethodException | IOException | ScriptException e) { throw new RuntimeException(e); } } ScriptValidatorService(); }
ScriptValidatorService implements RegexValidatorService { protected void registerScript(File file) { try { Invocable script = loadScript(manager, file); Bindings bindings = (Bindings) script.invokeFunction("getRegexNames"); List<String> regexNames = getStringArrayValues(bindings); for (String regexName : regexNames) { scripts.put(regexName, script); } } catch (NoSuchMethodException | IOException | ScriptException e) { throw new RuntimeException(e); } } ScriptValidatorService(); @Override void init(File confDir); @Override List<String> getRegexNames(); @Override boolean validate(String regexName, String hit); @Override String format(String regexName, String hit); }
ScriptValidatorService implements RegexValidatorService { protected void registerScript(File file) { try { Invocable script = loadScript(manager, file); Bindings bindings = (Bindings) script.invokeFunction("getRegexNames"); List<String> regexNames = getStringArrayValues(bindings); for (String regexName : regexNames) { scripts.put(regexName, script); } } catch (NoSuchMethodException | IOException | ScriptException e) { throw new RuntimeException(e); } } ScriptValidatorService(); @Override void init(File confDir); @Override List<String> getRegexNames(); @Override boolean validate(String regexName, String hit); @Override String format(String regexName, String hit);  }