@Test void testConvertedValidationErrorWithErrorPosition() throws RedPenException { String sampleText = "This is a good day。\n"; Configuration conf = Configuration.builder().build(); Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("InvalidSymbol")) .build(); List<cc.redpen.model.Document> documents = new ArrayList<>(); DocumentParser parser = DocumentParser.MARKDOWN; documents.add(parser.parse(sampleText, new SentenceExtractor(conf.getSymbolTable()), conf.getTokenizer())); RedPen redPen = new RedPen(configuration); List<ValidationError> errors = redPen.validate(documents).get(documents.get(0)); XMLFormatter formatter = new XMLFormatter(); String resultString = formatter.format(new cc.redpen.model.Document.DocumentBuilder( new WhiteSpaceTokenizer()).build(), errors); Document document = extractDocument(resultString); assertEquals(1, document.getElementsByTagName("error").getLength()); assertEquals(1, document.getElementsByTagName("message").getLength()); assertEquals(0, document.getElementsByTagName("file").getLength()); assertEquals(1, document.getElementsByTagName("lineNum").getLength()); assertEquals(1, document.getElementsByTagName("validator").getLength()); assertEquals("1", document.getElementsByTagName("lineNum").item(0).getTextContent()); assertEquals("InvalidSymbol", document.getElementsByTagName("validator").item(0).getTextContent()); assertEquals("1,18", document.getElementsByTagName("errorStartPosition").item(0).getTextContent()); assertEquals("1,19", document.getElementsByTagName("errorEndPosition").item(0).getTextContent()); }
@Override public void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); writer.write("<validation-result>\n"); for (cc.redpen.model.Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } writer.write("</validation-result>"); writer.flush(); }
XMLFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); writer.write("<validation-result>\n"); for (cc.redpen.model.Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } writer.write("</validation-result>"); writer.flush(); } }
XMLFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); writer.write("<validation-result>\n"); for (cc.redpen.model.Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } writer.write("</validation-result>"); writer.flush(); } XMLFormatter(); }
XMLFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); writer.write("<validation-result>\n"); for (cc.redpen.model.Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } writer.write("</validation-result>"); writer.flush(); } XMLFormatter(); @Override void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap); @Override String formatError(cc.redpen.model.Document document, ValidationError error); }
XMLFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); writer.write("<validation-result>\n"); for (cc.redpen.model.Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } writer.write("</validation-result>"); writer.flush(); } XMLFormatter(); @Override void format(PrintWriter pw, Map<cc.redpen.model.Document, List<ValidationError>> docErrorsMap); @Override String formatError(cc.redpen.model.Document document, ValidationError error);  }