public class JavaScriptValidator extends Validator
A Validator implementation load JavaScript dynamically.
files which name end with ".js" and located in "js" (can be specified with "script-path" property) directory will be treated as JavaScript validator implementation. Functions with the following signature will be called upon validation time:
function preValidateSentence(sentence) { } function preValidateSection(section) { } function validateDocument(document) { // your validation logic for document here } function validateSentence(sentence) { // if(your validation logic for sentence here) { // addError('validation error message', sentence); // } } function validateSection(section) { // your validation logic for section here }
Modifier and Type | Field and Description |
---|---|
String |
DEFAULT_JS_VALIDATORS_PATH |
KEY_VALUE, RULE, WORD_LIST, WORD_LIST_LOWERCASED
Constructor and Description |
---|
JavaScriptValidator() |
Modifier and Type | Method and Description |
---|---|
void |
addError(String message,
Sentence sentenceWithError)
create a ValidationError for the specified position with specified message
|
void |
addErrorWithPosition(String message,
Sentence sentenceWithError,
int start,
int end)
create a ValidationError for the specified position with specified message
|
void |
addLocalizedError(Sentence sentenceWithError,
Object... args)
create a ValidationError for the specified position with localized default error message
|
void |
addLocalizedError(String messageKey,
Sentence sentenceWithError,
Object... args)
create a ValidationError for the specified position with localized message with specified message key
|
void |
addLocalizedErrorFromToken(Sentence sentenceWithError,
TokenElement token)
create a ValidationError using the details within the given token & localized message
|
void |
addLocalizedErrorWithPosition(Sentence sentenceWithError,
int start,
int end,
Object... args)
create a ValidationError for the specified position with default localized error message
|
protected String |
getLocalizedErrorMessage(String key,
Object... args)
returns localized error message for the given key formatted with argument
|
protected void |
init()
Validation initialization, called after the configuration and symbol tables have been assigned
|
void |
preValidate(Section section)
Process input blocks before run validation.
|
void |
preValidate(Sentence sentence)
Process input blocks before run validation.
|
void |
validate(Document document)
validate the input document and returns the invalid points.
|
void |
validate(Section section)
validate the input document and returns the invalid points.
|
void |
validate(Sentence sentence)
validate the input document and returns the invalid points.
|
addLocalizedErrorWithPosition, addValidationError, addValidationError, addValidationErrorFromToken, addValidationErrorWithPosition, addValidationErrorWithPosition, getConfigAttribute, getConfigAttribute, getConfigAttributeAsBoolean, getConfigAttributeAsDouble, getConfigAttributeAsInt, getConfigAttributes, getSupportedLanguages, getSymbolTable, setErrorList
public final String DEFAULT_JS_VALIDATORS_PATH
protected void init() throws RedPenException
Validator
init
in class Validator
RedPenException
public void preValidate(Sentence sentence)
Validator
preValidate
in class Validator
sentence
- input sentencepublic void preValidate(Section section)
Validator
preValidate
in class Validator
section
- input sectionpublic void validate(Document document)
Validator
Validator
provides empty implementation. Validator implementation validates documents can override this method.public void validate(Sentence sentence)
Validator
Validator
provides empty implementation. Validator implementation validates sentences can override this method.public void validate(Section section)
Validator
Validator
provides empty implementation. Validator implementation validates sections can override this method.public void addError(String message, Sentence sentenceWithError)
Validator
public void addErrorWithPosition(String message, Sentence sentenceWithError, int start, int end)
Validator
addErrorWithPosition
in class Validator
message
- messagesentenceWithError
- sentencestart
- start positionend
- end positionpublic void addLocalizedError(Sentence sentenceWithError, Object... args)
Validator
addLocalizedError
in class Validator
sentenceWithError
- sentenceargs
- objects to formatpublic void addLocalizedError(String messageKey, Sentence sentenceWithError, Object... args)
Validator
addLocalizedError
in class Validator
messageKey
- messageKeysentenceWithError
- sentenceargs
- objects to formatpublic void addLocalizedErrorFromToken(Sentence sentenceWithError, TokenElement token)
Validator
addLocalizedErrorFromToken
in class Validator
sentenceWithError
- sentencetoken
- the TokenElement that has the errorpublic void addLocalizedErrorWithPosition(Sentence sentenceWithError, int start, int end, Object... args)
Validator
addLocalizedErrorWithPosition
in class Validator
sentenceWithError
- sentencestart
- start position in parsed sentenceend
- end position in parsed sentenceargs
- objects to formatprotected String getLocalizedErrorMessage(String key, Object... args)
Validator
getLocalizedErrorMessage
in class Validator
key
- message keyargs
- objects to formatCopyright © 2015. All rights reserved.