use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class Validator method validate.
/* (non-Javadoc)
* @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#validate(java.lang.String, java.io.InputStream, org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext)
*/
public ValidationReport validate(String uri, InputStream inputstream, NestedValidatorContext context) {
DTDValidator validator = DTDValidator.getInstance();
ValidationReport valreport = null;
valreport = validator.validate(uri);
return valreport;
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class ValidatorTest method testValidate.
/**
* Test the validate method. Tests to be performed:<br/>
* 1. Test that validating a valid file from a URI or an input stream produces the same result.<br/>
* 2. Test that validating an invalid file from a URI or an input stream produces the same result.
*/
public void testValidate() {
try {
// Test that validating a valid file from a URI and an input stream produces the same result.
String PLUGIN_ABSOLUTE_PATH = XMLValidatorTestsPlugin.getPluginLocation().toString() + "/";
String uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/XMLExamples/PublicationCatalogue/Catalogue.xml";
ValidationReport report1 = validator.validate(uri, null, null);
ValidationReport report2 = null;
InputStream is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, null);
} catch (Exception e) {
fail("A problem occurred while validating a valid file with an inputstream: " + e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Do nothing.
}
}
}
assertTrue("Validation using a URI did not product a valid validation result.", report1.isValid());
assertEquals("Validation using URI and using inputstream of the same file produces different numbers of errors.", report1.getValidationMessages().length, report2.getValidationMessages().length);
// Test that validating an invalid file from a URI and an input stream produces the same result.
uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/Paths/Dash-InPath/DashInPathInvalid.xml";
report1 = validator.validate(uri, null, null);
report2 = null;
is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, null);
} catch (Exception e) {
fail("A problem occurred while validating an invalid file with an inputstream: " + e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Do nothing.
}
}
}
assertFalse("Validation using a URI did not product an invalid validation result.", report1.isValid());
assertEquals("Validation using URI and using inputstream of the same file produces different numbers of errors.", report1.getValidationMessages().length, report2.getValidationMessages().length);
} catch (Exception e) {
fail("Unable to locate plug-in location: " + e);
}
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class Validator2 method validate.
@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
/*
* String s; switch(kind) { case IResourceDelta.ADDED: s = "added"; break; case IResourceDelta.CHANGED: s = "CHANGED"; break; case IResourceDelta.CONTENT: s = "CONTENT"; break; case
* IResourceDelta.REMOVED: s = "REMOVED"; break; default: s = "other"; } System.out.println(s);
*/
ValidationResult result = new ValidationResult();
if (resource.getType() == IResource.FILE) {
IFile file = (IFile) resource;
ValidationReport report = doValidation(file, kind, state, monitor);
StylesheetModel stylesheet = XSLCore.getInstance().getStylesheet(file);
IFile[] dependencies = stylesheet.getFileDependencies().toArray(new IFile[0]);
result.setDependsOn(dependencies);
for (ValidationMessage message : report.getValidationMessages()) {
XSLValidationMessage xslMsg = (XSLValidationMessage) message;
ValidatorMessage msg = ValidatorMessage.create(message.getMessage(), resource);
// $NON-NLS-1$
msg.setAttribute("lineNumber", xslMsg.getLineNumber());
// $NON-NLS-1$
msg.setAttribute("severity", xslMsg.getSeverity());
result.add(msg);
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class Validator method validate.
// ////////////////////////////////////////////////////////////////////////////////////////////////
// COMMON METHODS
// ////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public ValidationReport validate(final String uri, InputStream inputstream, NestedValidatorContext context) {
ValidationReport valreport = new XSLValidationReport(uri);
try {
String encUri = URIEncoder.encode(uri);
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI(encUri));
if (files.length > 0) {
IFile xslFile = files[0];
valreport = XSLValidator.getInstance().validate(xslFile, asYouTypeValidation);
}
} catch (URISyntaxException e) {
XSLCorePlugin.log(e);
} catch (CoreException e) {
XSLCorePlugin.log(e);
}
return valreport;
}
Aggregations