@Test void testFormatDocumentsAndErrorsWithPosition() throws RedPenException, JSONException { String sampleText = "This is a good day。"; Configuration conf = Configuration.builder().build(); Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("InvalidSymbol")) .build(); List<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)); JSONFormatter formatter = new JSONFormatter(); String resultString = formatter.format(new cc.redpen.model.Document.DocumentBuilder( new WhiteSpaceTokenizer()).build(), errors); JSONObject jsonObject = new JSONObject(resultString); JSONArray jsonErrors = jsonObject.getJSONArray("errors"); assertEquals(1, jsonErrors.length()); assertEquals(sampleText, jsonErrors.getJSONObject(0).getString("sentence")); assertEquals("0", jsonErrors.getJSONObject(0).getString("sentenceStartColumnNum")); assertEquals("1", jsonErrors.getJSONObject(0).getJSONObject("startPosition").getString("lineNum")); assertEquals("18", jsonErrors.getJSONObject(0).getJSONObject("startPosition").getString("offset")); assertEquals("1", jsonErrors.getJSONObject(0).getJSONObject("endPosition").getString("lineNum")); assertEquals("19", jsonErrors.getJSONObject(0).getJSONObject("endPosition").getString("offset")); }
@Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); } }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  @Override void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap); @Override String format(Document document, List<ValidationError> errors); @Override String formatError(Document document, ValidationError error); }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  @Override void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap); @Override String format(Document document, List<ValidationError> errors); @Override String formatError(Document document, ValidationError error);  }