Search in sources :

Example 6 with ValidationReport

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

Example 7 with ValidationReport

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);
    }
}
Also used : ValidationReport(org.eclipse.wst.xml.core.internal.validation.core.ValidationReport) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException)

Example 8 with ValidationReport

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;
}
Also used : XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) IFile(org.eclipse.core.resources.IFile) XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) ValidationReport(org.eclipse.wst.xml.core.internal.validation.core.ValidationReport) ValidationResult(org.eclipse.wst.validation.ValidationResult) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage)

Example 9 with ValidationReport

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ValidationReport(org.eclipse.wst.xml.core.internal.validation.core.ValidationReport) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

ValidationReport (org.eclipse.wst.xml.core.internal.validation.core.ValidationReport)9 IOException (java.io.IOException)3 ValidationMessage (org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ValidationResult (org.eclipse.wst.validation.ValidationResult)1 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)1 NestedValidatorContext (org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext)1 XSDValidationConfiguration (org.eclipse.wst.xsd.core.internal.validation.XSDValidationConfiguration)1 XSLValidationMessage (org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage)1 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)1