Search in sources :

Example 21 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class XMLValidator method executeMarkupValidator.

private IReporter executeMarkupValidator(String uri) {
    Path path = new Path(uri);
    // $NON-NLS-1$
    String fileProtocol = "file://";
    int index = uri.indexOf(fileProtocol);
    IFile resource = null;
    if (index == 0) {
        String transformedUri = uri.substring(fileProtocol.length());
        Path transformedPath = new Path(transformedUri);
        resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(transformedPath);
    } else {
        resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    }
    IReporter reporter = null;
    if (resource != null) {
        reporter = val.validate(resource, 0, new ValOperation().getState());
    }
    return reporter;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValOperation(org.eclipse.wst.validation.internal.ValOperation)

Example 22 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project sling by apache.

the class IgnoreMissingGrammarXmlValidator method validate.

/** Perform the validation using version 2 of the validation framework. Copied from {@link AbstractNestedValidator#validate(IResource,
     * int, ValidationState, IProgressMonitor). Cannot use original one as that skips resources starting with "." */
@Override
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());
        }
        doValidate(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) NestedValidatorContext(org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 23 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSPContentValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate(resource))
        return null;
    ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    if (fragmentCheck((IFile) resource)) {
        IStructuredModel model = null;
        try {
            model = StructuredModelManager.getModelManager().getModelForRead((IFile) resource);
            if (!reporter.isCancelled() && model instanceof IDOMModel) {
                reporter.removeAllMessages(this, resource);
                validate((IFile) resource, kind, state, monitor, (IDOMModel) model, reporter);
            }
        } catch (IOException e) {
            Logger.logException(e);
        } catch (CoreException e) {
            Logger.logException(e);
        } finally {
            if (model != null)
                model.releaseFromRead();
        }
    }
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 24 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSPValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    validateFile((IFile) resource, reporter);
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 25 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSPBatchValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate((IFile) resource))
        return null;
    final ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    if (result.getDependsOn() != null) {
        fDependsOn = new HashSet(Arrays.asList(result.getDependsOn()));
    } else {
        fDependsOn = new HashSet();
    }
    // add web.xml as a dependency
    addDependsOn(DeploymentDescriptorPropertyCache.getInstance().getWebXML(resource.getFullPath()));
    // List relevant JSP 2.0 preludes/codas as dependencies
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(resource.getFullPath());
    for (int j = 0; j < propertyGroups.length; j++) {
        IPath[] preludes = propertyGroups[j].getIncludePrelude();
        for (int i = 0; i < preludes.length; i++) {
            addDependsOn(workspaceRoot.getFile(preludes[i]));
        }
        IPath[] codas = propertyGroups[j].getIncludeCoda();
        for (int i = 0; i < codas.length; i++) {
            addDependsOn(workspaceRoot.getFile(codas[i]));
        }
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            if (fragmentCheck((IFile) resource)) {
                validateFile((IFile) resource, reporter);
            }
            IResource[] resources = (IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]);
            result.setDependsOn(resources);
            fDependsOn.clear();
        }
    };
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) PropertyGroup(org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup) IPath(org.eclipse.core.runtime.IPath) ValidationResult(org.eclipse.wst.validation.ValidationResult) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IValidatorJob(org.eclipse.wst.validation.internal.provisional.core.IValidatorJob) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

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