Search in sources :

Example 1 with IWorkbenchContext

use of org.eclipse.wst.validation.internal.operations.IWorkbenchContext in project webtools.sourceediting by eclipse.

the class HTMLValidator method validateFull.

/**
 */
private void validateFull(IValidationContext helper, IReporter reporter) {
    IProject project = null;
    String[] fileDelta = helper.getURIs();
    if (helper instanceof IWorkbenchContext) {
        IWorkbenchContext wbHelper = (IWorkbenchContext) helper;
        project = wbHelper.getProject();
    } else if (fileDelta.length > 0) {
        // won't work for project validation (b/c nothing in file delta)
        project = getResource(fileDelta[0]).getProject();
    }
    if (project == null)
        return;
    validateContainer(helper, reporter, project);
}
Also used : IWorkbenchContext(org.eclipse.wst.validation.internal.operations.IWorkbenchContext) IProject(org.eclipse.core.resources.IProject)

Example 2 with IWorkbenchContext

use of org.eclipse.wst.validation.internal.operations.IWorkbenchContext in project webtools.sourceediting by eclipse.

the class JsValidator method validate.

public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
    /* Added by BC ---- */
    // if(true) return;
    /* end Added by BC ---- */
    String[] uris = helper.getURIs();
    if (uris.length > 0) {
        IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
        IFile currentFile = null;
        for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
            currentFile = wsRoot.getFile(new Path(uris[i]));
            reporter.removeAllMessages(this, currentFile);
            if (currentFile != null && currentFile.exists()) {
                if (shouldValidate(currentFile)) {
                    // && fragmentCheck(currentFile)) {
                    int percent = (i * 100) / uris.length + 1;
                    // $NON-NLS-1$
                    IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + uris[i]);
                    reporter.displaySubtask(this, message);
                    validateFile(currentFile, reporter);
                }
                if (DEBUG) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + uris[i] + "]");
                }
            }
        }
    } else {
        // if uris[] length 0 -> validate() gets called for each project
        if (helper instanceof IWorkbenchContext) {
            IProject project = ((IWorkbenchContext) helper).getProject();
            JSFileVisitor visitor = new JSFileVisitor(reporter);
            try {
                // collect all jsp files for the project
                project.accept(visitor, IResource.DEPTH_INFINITE);
            } catch (CoreException e) {
                if (DEBUG) {
                    e.printStackTrace();
                }
            }
            IFile[] files = visitor.getFiles();
            for (int i = 0; i < files.length && !reporter.isCancelled(); i++) {
                int percent = (i * 100) / files.length + 1;
                // $NON-NLS-1$
                IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString());
                reporter.displaySubtask(this, message);
                validateFile(files[i], reporter);
                if (DEBUG) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + files[i] + "]");
                }
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkbenchContext(org.eclipse.wst.validation.internal.operations.IWorkbenchContext) IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with IWorkbenchContext

use of org.eclipse.wst.validation.internal.operations.IWorkbenchContext in project webtools.sourceediting by eclipse.

the class JSPValidator method validate.

public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
    String[] uris = helper.getURIs();
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
    if (uris.length > 0) {
        IFile currentFile = null;
        for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
            // might be called with just project path?
            currentFile = wsRoot.getFile(new Path(uris[i]));
            if (currentFile != null && currentFile.exists()) {
                if (shouldValidate(currentFile) && fragmentCheck(currentFile)) {
                    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, uris[i]);
                    reporter.displaySubtask(this, message);
                    validateFile(currentFile, reporter);
                }
                if (DEBUG)
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + uris[i] + "]");
            }
        }
    } else {
        // if uris[] length 0 -> validate() gets called for each project
        if (helper instanceof IWorkbenchContext) {
            IProject project = ((IWorkbenchContext) helper).getProject();
            JSPFileVisitor visitor = new JSPFileVisitor(reporter);
            try {
                // collect all jsp files for the project
                project.accept(visitor, IResource.DEPTH_INFINITE);
            } catch (CoreException e) {
                if (DEBUG)
                    e.printStackTrace();
            }
            IFile[] files = visitor.getFiles();
            for (int i = 0; i < files.length && !reporter.isCancelled(); i++) {
                if (shouldValidate(files[i]) && fragmentCheck(files[i])) {
                    int percent = (i * 100) / files.length + 1;
                    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString());
                    reporter.displaySubtask(this, message);
                    validateFile(files[i], reporter);
                }
                if (DEBUG)
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + files[i] + "]");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkbenchContext(org.eclipse.wst.validation.internal.operations.IWorkbenchContext) IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with IWorkbenchContext

use of org.eclipse.wst.validation.internal.operations.IWorkbenchContext in project webtools.sourceediting by eclipse.

the class JSPBatchValidator method doValidate.

void doValidate(IValidationContext helper, IReporter reporter) throws ValidationException {
    String[] uris = helper.getURIs();
    if (uris.length > 0) {
        IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
        IFile currentFile = null;
        for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
            currentFile = wsRoot.getFile(new Path(uris[i]));
            if (currentFile != null && currentFile.exists()) {
                if (shouldValidate(currentFile) && fragmentCheck(currentFile)) {
                    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, currentFile.getFullPath().toString().substring(1));
                    reporter.displaySubtask(this, message);
                    validateFile(currentFile, reporter);
                }
                if (DEBUG)
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + uris[i] + "]");
            }
        }
    } else {
        // if uris[] length 0 -> validate() gets called for each project
        if (helper instanceof IWorkbenchContext) {
            IProject project = ((IWorkbenchContext) helper).getProject();
            Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, NLS.bind(JSPCoreMessages.JSPBatchValidator_0, project.getFullPath()));
            reporter.displaySubtask(this, message);
            JSPFileVisitor visitor = new JSPFileVisitor(reporter);
            try {
                // collect all jsp files for the project
                project.accept(visitor, IResource.DEPTH_INFINITE);
            } catch (CoreException e) {
                if (DEBUG)
                    e.printStackTrace();
            }
            IFile[] files = visitor.getFiles();
            for (int i = 0; i < files.length && !reporter.isCancelled(); i++) {
                if (shouldValidate(files[i]) && fragmentCheck(files[i])) {
                    message = new LocalizedMessage(IMessage.LOW_SEVERITY, files[i].getFullPath().toString().substring(1));
                    reporter.displaySubtask(this, message);
                    validateFile(files[i], reporter);
                }
                if (DEBUG)
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("validating: [" + files[i] + "]");
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchContext(org.eclipse.wst.validation.internal.operations.IWorkbenchContext) IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException)

Example 5 with IWorkbenchContext

use of org.eclipse.wst.validation.internal.operations.IWorkbenchContext in project webtools.sourceediting by eclipse.

the class MarkupValidator method validateV1Project.

/**
 * @param helper
 * @param reporter
 */
private void validateV1Project(IValidationContext helper, final IReporter reporter) {
    // if uris[] length 0 -> validate() gets called for each project
    if (helper instanceof IWorkbenchContext) {
        IProject project = ((IWorkbenchContext) helper).getProject();
        IResourceProxyVisitor visitor = new IResourceProxyVisitor() {

            public boolean visit(IResourceProxy proxy) throws CoreException {
                if (shouldValidate(proxy)) {
                    validateV1File((IFile) proxy.requestResource(), reporter);
                }
                return true;
            }
        };
        try {
            // collect all jsp files for the project
            project.accept(visitor, IResource.DEPTH_INFINITE);
        } catch (CoreException e) {
            Logger.logException(e);
        }
    }
}
Also used : IWorkbenchContext(org.eclipse.wst.validation.internal.operations.IWorkbenchContext) IResourceProxyVisitor(org.eclipse.core.resources.IResourceProxyVisitor) CoreException(org.eclipse.core.runtime.CoreException) IResourceProxy(org.eclipse.core.resources.IResourceProxy) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProject (org.eclipse.core.resources.IProject)9 IWorkbenchContext (org.eclipse.wst.validation.internal.operations.IWorkbenchContext)9 CoreException (org.eclipse.core.runtime.CoreException)7 IResourceProxy (org.eclipse.core.resources.IResourceProxy)4 IResourceProxyVisitor (org.eclipse.core.resources.IResourceProxyVisitor)4 IFile (org.eclipse.core.resources.IFile)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 Path (org.eclipse.core.runtime.Path)3 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)3 Message (org.eclipse.wst.validation.internal.core.Message)2 IPath (org.eclipse.core.runtime.IPath)1