use of org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext in project sling by apache.
the class IgnoreMissingGrammarXmlValidator method validateInJob.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core
* .IValidationContext, org.eclipse.wst.validation.internal.provisional.core.IReporter)
*
* Copied from {@link AbstractNestedValidator#validateInJob(IValidationContext context, IReporter reporter). Cannot use original one as
* that skips resources starting with "."
*/
@Override
public IStatus validateInJob(IValidationContext context, IReporter reporter) throws ValidationException {
NestedValidatorContext nestedcontext = new NestedValidatorContext();
setupValidation(nestedcontext);
String[] fileURIs = context.getURIs();
if (fileURIs != null && fileURIs.length > 0) {
int numFiles = fileURIs.length;
for (int i = 0; i < numFiles && !reporter.isCancelled(); i++) {
String fileName = fileURIs[i];
if (fileName != null) {
Object[] parms = { fileName };
IFile file = (IFile) context.loadModel(GET_FILE, parms);
if (file != null && shouldValidate(file)) {
nestedcontext.setProject(file.getProject());
// called from a source other than the validation framework such as an editor.
if (context.loadModel(GET_INPUTSTREAM) instanceof InputStream) {
// do we need
doValidate(file, (InputStream) context.loadModel(GET_INPUTSTREAM), null, reporter, nestedcontext);
// the
// fileName?
// what is int
// ruleGroup?
} else {
doValidate(file, null, null, reporter, nestedcontext);
}
}
}
}
} else // TODO: Is this needed? Shouldn't the framework pass the complete list?
// Should I know that I'm validating a project as opposed to files?
{
Object[] parms = { getValidatorID() };
Collection files = (Collection) context.loadModel(GET_PROJECT_FILES, parms);
// files can be null if they're outside of the workspace
if (files != null) {
Iterator iter = files.iterator();
while (iter.hasNext() && !reporter.isCancelled()) {
IFile file = (IFile) iter.next();
if (shouldValidate(file)) {
doValidate(file, null, null, reporter, nestedcontext);
}
}
}
}
teardownValidation(nestedcontext);
if (reporter.isCancelled())
return Status.CANCEL_STATUS;
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext in project webtools.sourceediting by eclipse.
the class Validator method getNestedContext.
/**
* Get the nested validation context.
*
* @param state
* the validation state.
* @param create
* when true, a new context will be created if one is not found
* @return the nested validation context.
*/
protected NestedValidatorContext getNestedContext(ValidationState state, boolean create) {
NestedValidatorContext context = null;
Object o = state.get(XML_VALIDATOR_CONTEXT);
if (o instanceof XMLNestedValidatorContext)
context = (XMLNestedValidatorContext) o;
else if (create) {
context = new XMLNestedValidatorContext();
}
return context;
}
use of org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext in project webtools.sourceediting by eclipse.
the class Validator method validationStarting.
public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor) {
if (project != null) {
NestedValidatorContext context = getNestedContext(state, false);
if (context == null) {
context = getNestedContext(state, true);
if (context != null)
context.setProject(project);
setupValidation(context);
state.put(XML_VALIDATOR_CONTEXT, context);
}
super.validationStarting(project, state, monitor);
}
}
use of org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext in project webtools.sourceediting by eclipse.
the class Validator method validationFinishing.
public void validationFinishing(IProject project, ValidationState state, IProgressMonitor monitor) {
if (project != null) {
super.validationFinishing(project, state, monitor);
NestedValidatorContext context = getNestedContext(state, false);
if (context != null) {
teardownValidation(context);
state.put(XML_VALIDATOR_CONTEXT, null);
}
}
}
use of org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext 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 = XSDValidationTestsPlugin.getInstallURL();
String uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/Paths/Dash-InPath/DashInPathValid.xsd";
ValidationReport report1 = validator.validate(uri, null, new NestedValidatorContext());
ValidationReport report2 = null;
InputStream is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, new NestedValidatorContext());
} 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.xsd";
report1 = validator.validate(uri, null, new NestedValidatorContext());
report2 = null;
is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, new NestedValidatorContext());
} 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);
}
}
Aggregations