Search in sources :

Example 1 with ValidatorMessage

use of org.eclipse.wst.validation.ValidatorMessage in project liferay-ide by liferay.

the class WorkflowDefinitionValidator method validate.

@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE) {
        return null;
    }
    ValidationResult result = new ValidationResult();
    IFile workflowDefinitionXml = (IFile) resource;
    if (workflowDefinitionXml.isAccessible() && CoreUtil.isLiferayProject(resource.getProject())) {
        IScopeContext[] scopes = { new InstanceScope(), new DefaultScope() };
        ProjectScope projectScope = new ProjectScope(workflowDefinitionXml.getProject());
        boolean useProjectSettings = projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(ProjectCore.USE_PROJECT_SETTINGS, false);
        if (useProjectSettings) {
            scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
        }
        try {
            Map<String, Object>[] problems = detectProblems(workflowDefinitionXml, scopes);
            for (int i = 0; i < problems.length; i++) {
                Object messageValue = problems[i].get(IMarker.MESSAGE);
                ValidatorMessage message = ValidatorMessage.create(messageValue.toString(), resource);
                message.setType(MARKER_TYPE);
                message.setAttributes(problems[i]);
                result.add(message);
            }
            if (ListUtil.isNotEmpty(problems)) {
                IResource[] resources = { workflowDefinitionXml };
                result.setDependsOn(resources);
            }
        } catch (Exception e) {
            KaleoCore.logError(e);
        }
    }
    return result;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IFile(org.eclipse.core.resources.IFile) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) ValidationResult(org.eclipse.wst.validation.ValidationResult) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) CoreException(org.eclipse.core.runtime.CoreException) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 2 with ValidatorMessage

use of org.eclipse.wst.validation.ValidatorMessage in project sling by apache.

the class AbstractValidator method addValidatorMessage.

protected void addValidatorMessage(ValidationResult res, IResource resource, String msg) {
    ValidatorMessage message = ValidatorMessage.create(msg, resource);
    message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
    // ID is not taken over from the extension point (that only works for the IReporter (which is for validation V1)
    // reported at https://bugs.eclipse.org/bugs/show_bug.cgi?id=307093)
    message.setType(VALIDATION_MARKER_TYPE);
    res.add(message);
}
Also used : ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage)

Example 3 with ValidatorMessage

use of org.eclipse.wst.validation.ValidatorMessage in project webtools.sourceediting by eclipse.

the class TLDValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    IFile file = (IFile) resource;
    if (file.isAccessible()) {
        // TAGX
        if (fTagXexts.contains(file.getFileExtension()) || fTagXnames.contains(file.getName())) {
            monitor.beginTask("", 4);
            org.eclipse.wst.xml.core.internal.validation.eclipse.Validator xmlValidator = new org.eclipse.wst.xml.core.internal.validation.eclipse.Validator();
            ValidationResult result3 = new MarkupValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result2 = xmlValidator.validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result1 = new JSPActionValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            List messages = new ArrayList(result1.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result2.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result3.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(new JSPDirectiveValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1)).getReporter(new NullProgressMonitor()).getMessages());
            for (int i = 0; i < messages.size(); i++) {
                IMessage message = (IMessage) messages.get(i);
                if (message.getText() != null && message.getText().length() > 0) {
                    ValidatorMessage vmessage = ValidatorMessage.create(message.getText(), resource);
                    if (message.getAttributes() != null) {
                        Map attrs = message.getAttributes();
                        Iterator it = attrs.entrySet().iterator();
                        while (it.hasNext()) {
                            Map.Entry entry = (Map.Entry) it.next();
                            if (!(entry.getValue() instanceof String || entry.getValue() instanceof Integer || entry.getValue() instanceof Boolean)) {
                                it.remove();
                            }
                        }
                        vmessage.setAttributes(attrs);
                    }
                    vmessage.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
                    vmessage.setAttribute(IMarker.MESSAGE, message.getText());
                    if (message.getOffset() > -1) {
                        vmessage.setAttribute(IMarker.CHAR_START, message.getOffset());
                        vmessage.setAttribute(IMarker.CHAR_END, message.getOffset() + message.getLength());
                    }
                    int severity = 0;
                    switch(message.getSeverity()) {
                        case IMessage.HIGH_SEVERITY:
                            severity = IMarker.SEVERITY_ERROR;
                            break;
                        case IMessage.NORMAL_SEVERITY:
                            severity = IMarker.SEVERITY_WARNING;
                            break;
                        case IMessage.LOW_SEVERITY:
                            severity = IMarker.SEVERITY_INFO;
                            break;
                    }
                    vmessage.setAttribute(IMarker.SEVERITY, severity);
                    vmessage.setType(MARKER_TYPE);
                    result.add(vmessage);
                }
            }
            monitor.done();
        } else // TLD
        {
            try {
                final IJavaProject javaProject = JavaCore.create(file.getProject());
                if (javaProject.exists()) {
                    IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
                    ProjectScope projectScope = new ProjectScope(file.getProject());
                    if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
                        scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
                    }
                    Map[] problems = detectProblems(javaProject, file, scopes);
                    for (int i = 0; i < problems.length; i++) {
                        ValidatorMessage message = ValidatorMessage.create(problems[i].get(IMarker.MESSAGE).toString(), resource);
                        message.setType(MARKER_TYPE);
                        message.setAttributes(problems[i]);
                        result.add(message);
                    }
                }
            } catch (Exception e) {
                Logger.logException(e);
            }
        }
    }
    return result;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ValidationResult(org.eclipse.wst.validation.ValidationResult) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) Map(java.util.Map) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator) AbstractValidator(org.eclipse.wst.validation.AbstractValidator) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator)

Example 4 with ValidatorMessage

use of org.eclipse.wst.validation.ValidatorMessage 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 5 with ValidatorMessage

use of org.eclipse.wst.validation.ValidatorMessage in project liferay-ide by liferay.

the class KaleoUtil method checkWorkflowDefinitionForErrors.

public static String checkWorkflowDefinitionForErrors(IFile workspaceFile) {
    String retval = null;
    try {
        StringBuilder errorMsgs = new StringBuilder();
        ValOperation result = ValidationRunner.validate(workspaceFile, ValType.Manual, null, true);
        ValidationResultSummary validationResult = result.getResult();
        if (validationResult.getSeverityError() == 1) {
            ValidationResults results = result.getResults();
            for (ValidatorMessage message : results.getMessages()) {
                if (message.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) {
                    errorMsgs.append(message.getAttribute(IMarker.MESSAGE)).append('\n');
                }
            }
        }
        retval = errorMsgs.toString();
    } catch (Exception e) {
    }
    return retval;
}
Also used : ValidationResultSummary(org.eclipse.wst.validation.internal.ValidationResultSummary) ValidationResults(org.eclipse.wst.validation.ValidationResults) ValOperation(org.eclipse.wst.validation.internal.ValOperation) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) JSONException(org.json.JSONException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Aggregations

ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)5 IFile (org.eclipse.core.resources.IFile)3 ValidationResult (org.eclipse.wst.validation.ValidationResult)3 Map (java.util.Map)2 ProjectScope (org.eclipse.core.resources.ProjectScope)2 CoreException (org.eclipse.core.runtime.CoreException)2 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)2 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 AbstractValidator (org.eclipse.wst.validation.AbstractValidator)1