use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.
the class JSPHTMLValidatorTest method testJSPinAttributesHTML.
/**
* Tests jsp expression in html attributes in html file
*
* @throws Exception
*/
public void testJSPinAttributesHTML() throws Exception {
JSPContentValidator validator = new JSPContentValidator();
IReporter reporter = new ReporterForTest();
ValidationContextForTest helper = new ValidationContextForTest();
String filePath = "/" + PROJECT_NAME + "/WebContent/usejspinattribute.html";
helper.setURI(filePath);
validator.validate(helper, reporter);
assertTrue("jsp in attributes are not errors when they should be (in .html)", !reporter.getMessages().isEmpty());
}
use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.
the class JSPHTMLValidatorTest method testBadAttributeName.
/**
* Tests bad attribute names in jsp file false
*
* @throws Exception
*/
public void testBadAttributeName() throws Exception {
JSPContentValidator validator = new JSPContentValidator();
IReporter reporter = new ReporterForTest();
ValidationContextForTest helper = new ValidationContextForTest();
String filePath = "/" + PROJECT_NAME + "/WebContent/badattributenames.jsp";
helper.setURI(filePath);
validator.validate(helper, reporter);
assertTrue("bad attribute name is not error when it should be", !reporter.getMessages().isEmpty());
}
use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.
the class MarkupValidator method validate.
/* (non-Javadoc)
* @see org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core.resources.IResource, int, org.eclipse.wst.validation.ValidationState, org.eclipse.core.runtime.IProgressMonitor)
*/
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
if (resource.getType() != IResource.FILE)
return null;
ValidationResult result = new ValidationResult();
IReporter reporter = result.getReporter(monitor);
validateV1File((IFile) resource, reporter);
return result;
}
use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.
the class AbstractNestedValidator method validate.
/**
* Perform the validation using version 2 of the validation framework.
*/
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
ValidationResult result = new ValidationResult();
IFile file = null;
if (resource instanceof IFile)
file = (IFile) resource;
if (file != null && shouldValidate(file)) {
IReporter reporter = result.getReporter(monitor);
NestedValidatorContext nestedcontext = getNestedContext(state, false);
boolean teardownRequired = false;
if (nestedcontext == null) {
// validationstart was not called, so manually setup and tear down
nestedcontext = getNestedContext(state, true);
nestedcontext.setProject(file.getProject());
setupValidation(nestedcontext);
teardownRequired = true;
} else {
nestedcontext.setProject(file.getProject());
}
validate(file, null, result, reporter, nestedcontext);
if (teardownRequired)
teardownValidation(nestedcontext);
}
return result;
}
use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.
the class XMLValidator method validate.
/**
* Validate the inputStream
*
* @param uri
* The URI of the file to validate.
* @param inputstream
* The inputStream of the file to validate
* @param configuration
* A configuration for this validation session.
* @param result
* The validation result
* @param context
* The validation context
* @return
* Returns an XML validation report.
*/
public XMLValidationReport validate(String uri, InputStream inputStream, XMLValidationConfiguration configuration, ValidationResult result, NestedValidatorContext context) {
// $NON-NLS-1$
String grammarFile = "";
// Used for the preparse.
Reader reader1 = null;
// Used for validation parse.
Reader reader2 = null;
if (inputStream != null) {
String string = createStringForInputStream(inputStream);
reader1 = new StringReader(string);
reader2 = new StringReader(string);
}
XMLValidationInfo valinfo = new XMLValidationInfo(uri);
MyEntityResolver entityResolver = new MyEntityResolver(uriResolver, context);
ValidatorHelper helper = new ValidatorHelper();
try {
helper.computeValidationInformation(uri, reader1, uriResolver);
valinfo.setDTDEncountered(helper.isDTDEncountered);
valinfo.setElementDeclarationCount(helper.numDTDElements);
valinfo.setNamespaceEncountered(helper.isNamespaceEncountered);
valinfo.setGrammarEncountered(helper.isGrammarEncountered);
XMLReader reader = createXMLReader(valinfo, entityResolver);
// Set the configuration option
if (configuration.getFeature(XMLValidationConfiguration.HONOUR_ALL_SCHEMA_LOCATIONS)) {
// $NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/honour-all-schemaLocations", true);
}
if (configuration.getFeature(XMLValidationConfiguration.USE_XINCLUDE)) {
// $NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/xinclude", true);
}
// Support external schema locations
boolean isGrammarEncountered = helper.isGrammarEncountered;
if (!isGrammarEncountered) {
isGrammarEncountered = checkExternalSchemas(reader, valinfo.getFileURI());
}
// $NON-NLS-1$
reader.setFeature("http://xml.org/sax/features/validation", isGrammarEncountered);
// $NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/validation/schema", isGrammarEncountered);
XMLErrorHandler errorhandler = new XMLErrorHandler(valinfo);
reader.setErrorHandler(errorhandler);
InputSource inputSource = new InputSource(uri);
inputSource.setCharacterStream(reader2);
ClassLoader originalClzLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
reader.parse(inputSource);
} finally {
Thread.currentThread().setContextClassLoader(originalClzLoader);
}
if (configuration.getIntFeature(XMLValidationConfiguration.INDICATE_NO_GRAMMAR) > 0 && valinfo.isValid() && !isGrammarEncountered) {
if (configuration.getIntFeature(XMLValidationConfiguration.INDICATE_NO_GRAMMAR) == 1)
valinfo.addWarning(XMLValidationMessages._WARN_NO_GRAMMAR, 1, 0, uri, NO_GRAMMAR_FOUND, null);
else
// 2
valinfo.addError(XMLValidationMessages._WARN_NO_GRAMMAR, 1, 0, uri, NO_GRAMMAR_FOUND, null);
}
if (configuration.getIntFeature(XMLValidationConfiguration.INDICATE_NO_DOCUMENT_ELEMENT) > 0 && valinfo.isValid() && !helper.isDocumentElementEncountered) {
if (configuration.getIntFeature(XMLValidationConfiguration.INDICATE_NO_DOCUMENT_ELEMENT) == 1)
valinfo.addWarning(XMLValidationMessages._NO_DOCUMENT_ELEMENT, 1, 0, uri, NO_DOCUMENT_ELEMENT_FOUND, null);
else
// 2
valinfo.addError(XMLValidationMessages._NO_DOCUMENT_ELEMENT, 1, 0, uri, NO_DOCUMENT_ELEMENT_FOUND, null);
}
if (helper.isDTDEncountered)
grammarFile = entityResolver.getLocation();
else
grammarFile = helper.schemaLocationString;
} catch (SAXParseException saxParseException) {
// These errors are caught by the error handler.
// addValidationMessage(valinfo, saxParseException);
} catch (IOException ioException) {
addValidationMessage(valinfo, ioException);
} catch (Exception exception) {
Logger.logException(exception.getLocalizedMessage(), exception);
}
// still proceed as before
if (result != null) {
try {
IResource resource = getWorkspaceFileFromLocation(grammarFile);
ArrayList resources = new ArrayList();
if (resource != null)
resources.add(resource);
result.setDependsOn((IResource[]) resources.toArray(new IResource[0]));
} catch (Exception e) {
Logger.logException(e.getLocalizedMessage(), e);
}
}
if (XMLCorePlugin.getDefault().getPluginPreferences().getBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION)) {
IReporter reporter = executeMarkupValidator(uri);
if (reporter != null) {
List msgList = reporter.getMessages();
for (int i = 0; i < msgList.size(); i++) {
LocalizedMessage msg = (LocalizedMessage) msgList.get(i);
if (msg.getSeverity() == 2)
// $NON-NLS-1$
valinfo.addError(msg.getLocalizedMessage(), msg.getLineNumber(), msg.getOffset(), valinfo.getFileURI(), "null", getMsgArguments(msg));
else if (msg.getSeverity() == 1)
// $NON-NLS-1$
valinfo.addWarning(msg.getLocalizedMessage(), msg.getLineNumber(), msg.getOffset(), valinfo.getFileURI(), "null", getMsgArguments(msg));
}
}
}
return valinfo;
}
Aggregations