Search in sources :

Example 1 with XSLValidationMessage

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

the class AbstractValidationTest method validateErrors.

private void validateErrors(StylesheetModel model, XSLValidationReport report, Map<Integer, String> expectedErrors) {
    expectedErrors = new HashMap<Integer, String>(expectedErrors);
    for (ValidationMessage msg : report.getValidationMessages()) {
        XSLValidationMessage error = (XSLValidationMessage) msg;
        assertTrue("Error report must be for the current stylesheet only", error.getNode().getStylesheet() == model.getStylesheet());
        String comment = expectedErrors.remove(error.getLineNumber());
        assertNotNull("Unxpected error at line " + error.getLineNumber() + ": " + error, comment);
        assertFalse("Incorrect error level for error at line " + error.getLineNumber() + ": " + error, comment.startsWith("ERROR") && msg.getSeverity() != ValidationMessage.SEV_HIGH);
        assertFalse("Incorrect error level for error at line " + error.getLineNumber() + ": " + error, comment.startsWith("WARN") && msg.getSeverity() == ValidationMessage.SEV_HIGH);
    }
    for (Map.Entry<Integer, String> entry : expectedErrors.entrySet()) {
        assertTrue("Expected error " + entry.getValue() + " at line " + entry.getKey(), false);
    }
}
Also used : XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with XSLValidationMessage

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

the class AbstractModelTest method validateErrors.

private void validateErrors(StylesheetModel model, XSLValidationReport report, Map<Integer, String> expectedErrors) {
    expectedErrors = new HashMap<Integer, String>(expectedErrors);
    for (ValidationMessage msg : report.getValidationMessages()) {
        XSLValidationMessage error = (XSLValidationMessage) msg;
        assertTrue("Error report must be for the current stylesheet only", error.getNode().getStylesheet() == model.getStylesheet());
        String comment = expectedErrors.remove(error.getLineNumber());
        assertNotNull("Unxpected error at line " + error.getLineNumber() + ": " + error, comment);
        assertFalse("Incorrect error level for error at line " + error.getLineNumber() + ": " + error, comment.startsWith("ERROR") && msg.getSeverity() != ValidationMessage.SEV_HIGH);
        assertFalse("Incorrect error level for error at line " + error.getLineNumber() + ": " + error, comment.startsWith("WARN") && msg.getSeverity() == ValidationMessage.SEV_HIGH);
    }
    for (Map.Entry<Integer, String> entry : expectedErrors.entrySet()) {
        assertTrue("Expected error " + entry.getValue() + " at line " + entry.getKey(), false);
    }
}
Also used : XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with XSLValidationMessage

use of org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage 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 4 with XSLValidationMessage

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

the class Validator method addInfoToMessage.

@Override
protected void addInfoToMessage(ValidationMessage validationMessage, IMessage message) {
    XSLValidationMessage msg = (XSLValidationMessage) validationMessage;
    XSLNode node = msg.getNode();
    // set this here as it gets set to the wrong value by the superclass
    message.setSeverity(msg.getRealSeverity());
    // constants are defined in org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidator
    if (node.getNodeType() == XSLNode.ATTRIBUTE_NODE) {
        // $NON-NLS-1$//$NON-NLS-2$
        message.setAttribute("ERROR_SIDE", "ERROR_SIDE_RIGHT");
        message.setAttribute(COLUMN_NUMBER_ATTRIBUTE, Integer.valueOf(validationMessage.getColumnNumber()));
        // whether to squiggle the element, attribute or text //$NON-NLS-1$
        message.setAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE, "ATTRIBUTE_VALUE");
        message.setAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE, ((XSLAttribute) node).getName());
    } else if (node.getNodeType() == XSLNode.ELEMENT_NODE) {
        // $NON-NLS-1$//$NON-NLS-2$
        message.setAttribute("ERROR_SIDE", "ERROR_SIDE_RIGHT");
        message.setAttribute(COLUMN_NUMBER_ATTRIBUTE, Integer.valueOf(validationMessage.getColumnNumber()));
        // whether to squiggle the element, attribute or text //$NON-NLS-1$
        message.setAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE, "START_TAG");
    }
}
Also used : XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) XSLNode(org.eclipse.wst.xsl.core.model.XSLNode)

Aggregations

XSLValidationMessage (org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage)4 ValidationMessage (org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)1 ValidationResult (org.eclipse.wst.validation.ValidationResult)1 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)1 ValidationReport (org.eclipse.wst.xml.core.internal.validation.core.ValidationReport)1 StylesheetModel (org.eclipse.wst.xsl.core.model.StylesheetModel)1 XSLNode (org.eclipse.wst.xsl.core.model.XSLNode)1