use of org.eclipse.wst.validation.internal.provisional.core.IValidatorJob in project webtools.sourceediting by eclipse.
the class DelegatingSourceValidator method validate.
/**
* Calls a delegate validator getting and updates it's list of
* ValidationMessages with a good squiggle offset and length.
*
* @param helper
* loads an object.
* @param reporter
* Is an instance of an IReporter interface, which is used for
* interaction with the user.
*/
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
String[] delta = helper.getURIs();
if (delta.length > 0) {
// get the file, model and document:
IFile file = getFile(delta[0]);
IDOMModel xmlModel = null;
if (file != null)
xmlModel = getModelForResource(file);
// some problem occurred, abort
if (xmlModel == null)
return;
try {
IDOMDocument document = xmlModel.getDocument();
// store the text in a byte array; make a full copy to ease
// any threading problems
byte[] byteArray;
try {
byteArray = xmlModel.getStructuredDocument().get().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// Not likely to happen
byteArray = xmlModel.getStructuredDocument().get().getBytes();
}
if (isDelegateValidatorEnabled(file)) {
IValidator validator = getDelegateValidator();
if (validator != null) {
// Validate the file:
IValidationContext vHelper = new MyHelper(new ByteArrayInputStream(byteArray), file);
MyReporter vReporter = new MyReporter();
if (validator instanceof IValidatorJob) {
((IValidatorJob) validator).validateInJob(vHelper, vReporter);
} else {
validator.validate(vHelper, vReporter);
}
List messages = vReporter.list;
// set the offset and length
updateValidationMessages(messages, document, reporter);
}
}
} finally {
if (xmlModel != null) {
xmlModel.releaseFromRead();
}
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IValidatorJob in project webtools.sourceediting by eclipse.
the class DelegatingSourceValidator method validate.
/**
* Calls a delegate validator getting and updates it's list of
* ValidationMessages with a good squiggle offset and length.
*
* @param helper
* loads an object.
* @param reporter
* Is an instance of an IReporter interface, which is used for
* interaction with the user.
*/
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
String[] delta = helper.getURIs();
if (delta.length > 0) {
// get the file, model and document:
IFile file = getFile(delta[0]);
IJSONModel jsonModel = null;
if (file != null)
jsonModel = getModelForResource(file);
// some problem occurred, abort
if (jsonModel == null)
return;
try {
IJSONDocument document = jsonModel.getDocument();
// store the text in a byte array; make a full copy to ease
// any threading problems
byte[] byteArray;
try {
byteArray = jsonModel.getStructuredDocument().get().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// Not likely to happen
byteArray = jsonModel.getStructuredDocument().get().getBytes();
}
if (isDelegateValidatorEnabled(file)) {
IValidator validator = getDelegateValidator();
if (validator != null) {
// Validate the file:
IValidationContext vHelper = new MyHelper(new ByteArrayInputStream(byteArray), file);
MyReporter vReporter = new MyReporter();
if (validator instanceof IValidatorJob) {
((IValidatorJob) validator).validateInJob(vHelper, vReporter);
} else {
validator.validate(vHelper, vReporter);
}
List messages = vReporter.list;
// set the offset and length
updateValidationMessages(messages, document, reporter);
}
}
} finally {
if (jsonModel != null) {
jsonModel.releaseFromRead();
}
}
}
}
Aggregations