Search in sources :

Example 11 with Message

use of org.eclipse.wst.validation.internal.core.Message 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 12 with Message

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

the class StreamingMarkupValidator method validateFile.

/**
 * Validates the given file. It will stream the contents of the file without creating a model for the file; it will only
 * use existing
 * @param file the file to validate
 * @param reporter the reporter
 */
private void validateFile(IFile file, IReporter reporter) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
    reporter.displaySubtask(StreamingMarkupValidator.this, message);
    XMLLineTokenizer tokenizer = null;
    try {
        tagStack = new Stack();
        model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
        try {
            if (model == null) {
                tokenizer = new XMLLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
            } else {
                tokenizer = new XMLLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
            }
            checkTokens(tokenizer, reporter);
        } finally {
            if (model != null) {
                model.releaseFromRead();
                model = null;
            }
        }
    } catch (UnsupportedEncodingException e) {
    } catch (CoreException e) {
    } catch (IOException e) {
    }
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Message(org.eclipse.wst.validation.internal.core.Message) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XMLLineTokenizer(org.eclipse.wst.xml.core.internal.parser.XMLLineTokenizer) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IOException(java.io.IOException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Stack(java.util.Stack)

Example 13 with Message

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

the class AbstractNestedValidator method validate.

/**
 * Validate the given file and use the reporter for the validation messages.
 * This method does not perform the validation logic but rather delegates
 * to the validate method in subclasses to validate. This method is responsible
 * for reporting the messages that result from validation.
 *
 * @param file
 * 		An IFile to validate.
 * @param inputstream
 * 		An InputStream that represents the file. The InputStream may be null
 * 		in which case the files should be validated from the IFile.
 * @param result - The validation result
 * @param reporter
 * 		The reporter with which to report validation messages.
 * @param context
 * 		The context of the current validation.
 */
private void validate(IFile file, InputStream inputstream, ValidationResult result, IReporter reporter, NestedValidatorContext context) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString());
    reporter.displaySubtask(this, message);
    String locationString = null;
    if (file.getLocation() != null) {
        locationString = file.getLocation().toString();
    }
    if (locationString == null && file.getLocationURI() != null) {
        locationString = file.getLocationURI().toString();
    }
    if (locationString == null) {
        locationString = file.getFullPath().toString();
    }
    String uri = createURIForFilePath(locationString);
    clearMarkers(file, this, reporter);
    ValidationReport valreport = null;
    if (result == null)
        valreport = validate(uri, inputstream, context);
    else
        valreport = validate(uri, inputstream, context, result);
    createMarkers(file, valreport.getValidationMessages(), reporter);
    try {
        file.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages());
    } catch (CoreException e) {
        // $NON-NLS-1$
        System.out.println("Unable to set nested messages property.");
    }
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) CoreException(org.eclipse.core.runtime.CoreException)

Example 14 with Message

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

the class JSDTSourceValidator method validateDelta.

/**
 */
private void validateDelta(IValidationContext helper, IReporter reporter) {
    String[] deltaArray = helper.getURIs();
    for (int i = 0; i < deltaArray.length; i++) {
        String delta = deltaArray[i];
        if (delta == null)
            continue;
        if (reporter != null) {
            Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1));
            reporter.displaySubtask(this, message);
        }
        IResource resource = getResource(delta);
        if (resource == null || !(resource instanceof IFile))
            continue;
        validateFile(helper, reporter, (IFile) resource, null);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IResource(org.eclipse.core.resources.IResource)

Example 15 with Message

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

the class JSONSyntaxValidator method validateFile.

/**
 * Validates the given file. It will stream the contents of the file without
 * creating a model for the file; it will only use existing
 *
 * @param file
 *            the file to validate
 * @param reporter
 *            the reporter
 */
private void validateFile(IFile file, IReporter reporter) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
    reporter.displaySubtask(JSONSyntaxValidator.this, message);
    JSONLineTokenizer tokenizer = null;
    try {
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
        try {
            if (model == null) {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
            } else {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
            }
            JSONSyntaxValidatorHelper.validate(tokenizer, reporter, this, this);
        } finally {
            if (model != null) {
                model.releaseFromRead();
                model = null;
            }
        }
    } catch (UnsupportedEncodingException e) {
    } catch (CoreException e) {
    } catch (IOException e) {
    }
}
Also used : JSONLineTokenizer(org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Message(org.eclipse.wst.validation.internal.core.Message) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IOException(java.io.IOException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Aggregations

Message (org.eclipse.wst.validation.internal.core.Message)19 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)17 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 IResource (org.eclipse.core.resources.IResource)4 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 Path (org.eclipse.core.runtime.Path)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 JSPELParser (org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser)2