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();
}
}
}
}