@Test void testFileJSValidator() throws RedPenException, IOException { File javaScriptValidatorsDir = File.createTempFile("test", "js"); javaScriptValidatorsDir.delete(); javaScriptValidatorsDir.mkdirs(); System.setProperty("REDPEN_HOME", javaScriptValidatorsDir.getAbsolutePath()); File validatorJS = new File(javaScriptValidatorsDir.getAbsolutePath() + File.separator + "MyValidationScript.js"); String content2 = "function validateSentence(sentence) {\n" + "addLocalizedError(sentence, 'validation error in JavaScript Validator');}"; Files.write(Paths.get(validatorJS.getAbsolutePath()), content2.getBytes(UTF_8)); validatorJS.deleteOnExit(); Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("JavaScript").addProperty("script-path", javaScriptValidatorsDir.getAbsolutePath())) .build(); Document document = Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("the good item is a good example.", 1)) .build(); RedPen redPen = new RedPen(config); List<ValidationError> errors = redPen.validate(document); assertEquals(1, errors.size()); assertEquals("JavaScript validator validation error in JavaScript Validator", errors.get(0).getMessage()); assertEquals("MyValidationScript.js", errors.get(0).getValidatorName()); }
@Override public void validate(Document document) { for (JavaScriptLoader js : scripts) { js.setErrorList(errors); js.validate(document); } }
JavaScriptValidator extends Validator { @Override public void validate(Document document) { for (JavaScriptLoader js : scripts) { js.setErrorList(errors); js.validate(document); } } }
JavaScriptValidator extends Validator { @Override public void validate(Document document) { for (JavaScriptLoader js : scripts) { js.setErrorList(errors); js.validate(document); } } JavaScriptValidator(); }
JavaScriptValidator extends Validator { @Override public void validate(Document document) { for (JavaScriptLoader js : scripts) { js.setErrorList(errors); js.validate(document); } } JavaScriptValidator(); @Override void preInit(ValidatorConfiguration config, Configuration globalConfig); @Override void setErrorList(List<ValidationError> errors); @Override void preValidate(Sentence sentence); @Override void preValidate(Section section); @Override void validate(Document document); @Override void validate(Sentence sentence); @Override void validate(Section section); }
JavaScriptValidator extends Validator { @Override public void validate(Document document) { for (JavaScriptLoader js : scripts) { js.setErrorList(errors); js.validate(document); } } JavaScriptValidator(); @Override void preInit(ValidatorConfiguration config, Configuration globalConfig); @Override void setErrorList(List<ValidationError> errors); @Override void preValidate(Sentence sentence); @Override void preValidate(Section section); @Override void validate(Document document); @Override void validate(Sentence sentence); @Override void validate(Section section);  }