Search in sources :

Example 16 with IReporter

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());
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) JSPContentValidator(org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)

Example 17 with IReporter

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());
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) JSPContentValidator(org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)

Example 18 with IReporter

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;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 19 with IReporter

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 20 with IReporter

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;
}
Also used : XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) InputSource(org.xml.sax.InputSource) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ArrayList(java.util.ArrayList) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) XNIException(org.apache.xerces.xni.XNIException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SAXParseException(org.xml.sax.SAXParseException) SAXParseException(org.xml.sax.SAXParseException) StringReader(java.io.StringReader) List(java.util.List) ArrayList(java.util.ArrayList) XMLReader(org.xml.sax.XMLReader) IResource(org.eclipse.core.resources.IResource) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Aggregations

IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)43 IFile (org.eclipse.core.resources.IFile)17 Path (org.eclipse.core.runtime.Path)15 List (java.util.List)11 JSPJavaValidator (org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator)10 ValidationResult (org.eclipse.wst.validation.ValidationResult)9 Test (org.junit.Test)8 IProject (org.eclipse.core.resources.IProject)7 IPath (org.eclipse.core.runtime.IPath)7 JSPValidator (org.eclipse.jst.jsp.core.internal.validation.JSPValidator)7 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)6 CoreException (org.eclipse.core.runtime.CoreException)5 ReporterForTest (org.eclipse.jst.jsp.core.tests.validation.ReporterForTest)5 ValidationContextForTest (org.eclipse.jst.jsp.core.tests.validation.ValidationContextForTest)5 IOException (java.io.IOException)4 JSPActionValidator (org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator)4 JSPDirectiveValidator (org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)4 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)4 Iterator (java.util.Iterator)3 JSPContentValidator (org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)3