Skip to content

Commit

Permalink
Merge 2832c97 into 5552ece
Browse files Browse the repository at this point in the history
  • Loading branch information
norm-ideal committed Oct 20, 2020
2 parents 5552ece + 2832c97 commit 75dc36b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions redpen-core/src/main/java/cc/redpen/RedPen.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,26 @@ public Map<Document, List<ValidationError>> validate(List<Document> documents, S
}

/**
* validate the input document collection. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
* validate the input document. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
*
* @param document document to be validated
* @return list of validation errors
*/
public List<ValidationError> validate(Document document) {
return validate(document, "error");
}

/**
* validate the input document. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
*
* @param document document to be validated
* @param threshold threshold of error level
* @return list of validation errors
*/
public List<ValidationError> validate(Document document, String threshold) {
List<Document> documents = new ArrayList<>();
documents.add(document);
Map<Document, List<ValidationError>> documentListMap = validate(documents);
Map<Document, List<ValidationError>> documentListMap = validate(documents, threshold);
return documentListMap.get(document);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RedPenResource {
private static final String DEFAULT_LANG = "en";
private static final String DEFAULT_CONFIGURATION = "en";
private static final String DEFAULT_FORMAT = "json";
private static final String DEFAULT_ERROR_LEVEL = "error";

/*package*/ static final String MIME_TYPE_XML = "application/xml; charset=utf-8";
/*package*/ static final String MIME_TYPE_JSON = "application/json; charset=utf-8";
Expand Down Expand Up @@ -99,6 +100,7 @@ public Response validateDocument(@FormParam("document") @DefaultValue("") String
@FormParam("documentParser") @DefaultValue(DEFAULT_DOCUMENT_PARSER) String documentParser,
@FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang,
@FormParam("format") @DefaultValue(DEFAULT_FORMAT) String format,
@FormParam("errorLevel") @DefaultValue(DEFAULT_ERROR_LEVEL) String errorLevel,
@FormParam("config") String config) throws RedPenException {

LOG.info("Validating document");
Expand All @@ -109,7 +111,7 @@ public Response validateDocument(@FormParam("document") @DefaultValue("") String
redPen = new RedPen(new ConfigurationLoader().secure().loadFromString(config));
}
Document parsedDocument = redPen.parse(DocumentParser.of(documentParser), document);
List<ValidationError> errors = redPen.validate(parsedDocument);
List<ValidationError> errors = redPen.validate(parsedDocument, errorLevel);

Formatter formatter = FormatterUtils.getFormatterByName(format);

Expand Down

0 comments on commit 75dc36b

Please sign in to comment.