use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSPBatchValidator method doValidate.
void doValidate(IValidationContext helper, IReporter reporter) throws ValidationException {
String[] uris = helper.getURIs();
if (uris.length > 0) {
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile currentFile = null;
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = wsRoot.getFile(new Path(uris[i]));
if (currentFile != null && currentFile.exists()) {
if (shouldValidate(currentFile) && fragmentCheck(currentFile)) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, currentFile.getFullPath().toString().substring(1));
reporter.displaySubtask(this, message);
validateFile(currentFile, reporter);
}
if (DEBUG)
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("validating: [" + uris[i] + "]");
}
}
} else {
// if uris[] length 0 -> validate() gets called for each project
if (helper instanceof IWorkbenchContext) {
IProject project = ((IWorkbenchContext) helper).getProject();
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, NLS.bind(JSPCoreMessages.JSPBatchValidator_0, project.getFullPath()));
reporter.displaySubtask(this, message);
JSPFileVisitor visitor = new JSPFileVisitor(reporter);
try {
// collect all jsp files for the project
project.accept(visitor, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
if (DEBUG)
e.printStackTrace();
}
IFile[] files = visitor.getFiles();
for (int i = 0; i < files.length && !reporter.isCancelled(); i++) {
if (shouldValidate(files[i]) && fragmentCheck(files[i])) {
message = new LocalizedMessage(IMessage.LOW_SEVERITY, files[i].getFullPath().toString().substring(1));
reporter.displaySubtask(this, message);
validateFile(files[i], reporter);
}
if (DEBUG)
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("validating: [" + files[i] + "]");
}
}
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class StreamingMarkupValidator method validateFile.
/**
* Validates the given file. It will stream the contents of the file without creating a model for the file; it will only
* use existing
* @param file the file to validate
* @param reporter the reporter
*/
private void validateFile(IFile file, IReporter reporter) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
reporter.displaySubtask(StreamingMarkupValidator.this, message);
XMLLineTokenizer tokenizer = null;
try {
tagStack = new Stack();
model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
try {
if (model == null) {
tokenizer = new XMLLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
} else {
tokenizer = new XMLLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
}
checkTokens(tokenizer, reporter);
} finally {
if (model != null) {
model.releaseFromRead();
model = null;
}
}
} catch (UnsupportedEncodingException e) {
} catch (CoreException e) {
} catch (IOException e) {
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class AbstractNestedValidator method validate.
/**
* Validate the given file and use the reporter for the validation messages.
* This method does not perform the validation logic but rather delegates
* to the validate method in subclasses to validate. This method is responsible
* for reporting the messages that result from validation.
*
* @param file
* An IFile to validate.
* @param inputstream
* An InputStream that represents the file. The InputStream may be null
* in which case the files should be validated from the IFile.
* @param result - The validation result
* @param reporter
* The reporter with which to report validation messages.
* @param context
* The context of the current validation.
*/
private void validate(IFile file, InputStream inputstream, ValidationResult result, IReporter reporter, NestedValidatorContext context) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString());
reporter.displaySubtask(this, message);
String locationString = null;
if (file.getLocation() != null) {
locationString = file.getLocation().toString();
}
if (locationString == null && file.getLocationURI() != null) {
locationString = file.getLocationURI().toString();
}
if (locationString == null) {
locationString = file.getFullPath().toString();
}
String uri = createURIForFilePath(locationString);
clearMarkers(file, this, reporter);
ValidationReport valreport = null;
if (result == null)
valreport = validate(uri, inputstream, context);
else
valreport = validate(uri, inputstream, context, result);
createMarkers(file, valreport.getValidationMessages(), reporter);
try {
file.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages());
} catch (CoreException e) {
// $NON-NLS-1$
System.out.println("Unable to set nested messages property.");
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSDTSourceValidator method validateDelta.
/**
*/
private void validateDelta(IValidationContext helper, IReporter reporter) {
String[] deltaArray = helper.getURIs();
for (int i = 0; i < deltaArray.length; i++) {
String delta = deltaArray[i];
if (delta == null)
continue;
if (reporter != null) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1));
reporter.displaySubtask(this, message);
}
IResource resource = getResource(delta);
if (resource == null || !(resource instanceof IFile))
continue;
validateFile(helper, reporter, (IFile) resource, null);
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSONSyntaxValidator method validateFile.
/**
* Validates the given file. It will stream the contents of the file without
* creating a model for the file; it will only use existing
*
* @param file
* the file to validate
* @param reporter
* the reporter
*/
private void validateFile(IFile file, IReporter reporter) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
reporter.displaySubtask(JSONSyntaxValidator.this, message);
JSONLineTokenizer tokenizer = null;
try {
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
try {
if (model == null) {
tokenizer = new JSONLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
} else {
tokenizer = new JSONLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
}
JSONSyntaxValidatorHelper.validate(tokenizer, reporter, this, this);
} finally {
if (model != null) {
model.releaseFromRead();
model = null;
}
}
} catch (UnsupportedEncodingException e) {
} catch (CoreException e) {
} catch (IOException e) {
}
}
Aggregations