Search in sources :

Example 6 with ValidationMessage

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

the class BaseTestCase method createLog.

/**
 * Create a log file for an XSD test.
 *
 * @param filename The name of the log file to create.
 * @param valreport The validation report for this file.
 * @return The file contents as a string if successful or null if not successful.
 */
private String createLog(String filename, ValidationReport valreport) {
    ValidationMessage[] valmessages = valreport.getValidationMessages();
    // validator.getErrors().size() + validator.getWarnings().size();
    int nummessages = valmessages.length;
    StringBuffer errorsString = new StringBuffer();
    StringBuffer warningsString = new StringBuffer();
    int numerrors = 0;
    int numwarnings = 0;
    for (int i = 0; i < nummessages; i++) {
        ValidationMessage valmes = valmessages[i];
        if (valmes.getSeverity() == ValidationMessage.SEV_LOW) {
            numwarnings++;
            String message = valmes.getMessage();
            message = message.replaceAll("'[^']*" + getPluginName() + "[^'/]*/", "'");
            message = message.replaceAll("[(][^(]*" + getPluginName() + "[^'/]*/", "(");
            warningsString.append(message + " [" + valmes.getLineNumber() + ", " + valmes.getColumnNumber() + "]\n");
            warningsString.append(createNestedMessageString(valmes.getNestedMessages()));
        } else {
            numerrors++;
            String message = valmes.getMessage();
            message = message.replaceAll("'[^']*" + getPluginName() + "[^'/]*/", "'");
            message = message.replaceAll("[(][^(]*" + getPluginName() + "[^'/]*/", "(");
            errorsString.append(message + " [" + valmes.getLineNumber() + ", " + valmes.getColumnNumber() + "]\n");
            errorsString.append(createNestedMessageString(valmes.getNestedMessages()));
        }
    }
    StringBuffer log = new StringBuffer();
    log.append("number of errors      : " + numerrors + "\n");
    if (numwarnings > 0) {
        log.append("number of warnings    : " + numwarnings + "\n");
    }
    log.append("\n------------error list-------------------------------------------\n");
    if (numerrors == 0) {
        log.append("(none)\n");
    } else {
        log.append(errorsString.toString());
    }
    if (numwarnings > 0) {
        log.append("------------warning list-----------------------------------------\n");
        log.append(errorsString.toString());
    }
    log.append(warningsString.toString());
    log.append("-----------------------------------------------------------------\n");
    DataOutputStream outStream = null;
    try {
        File logfile = new File(filename);
        File parent = logfile.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        if (logfile.exists()) {
            logfile.delete();
        }
        logfile.createNewFile();
        outStream = new DataOutputStream(new FileOutputStream(filename, true));
        outStream.writeBytes(log.toString());
        outStream.close();
    } catch (IOException e) {
        // If we can't write the log then clear the log.
        log.delete(0, log.length());
    }
    return log.toString();
}
Also used : ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 7 with ValidationMessage

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

the class LineNumberAdjustmentsTest method runTest.

/**
 * Run a validator test. The test will run the validator, and compare the validation result with
 * the information specified.
 *
 * @param testfile
 * 			The file to run the validator test on.
 * @param key
 * 			The message key.
 * @param numErrors
 * 			The number of expected errors.
 * @param numWarnings
 * 			The number of expected warnings.
 * @param lineno
 * 			The line number the message should be located on.
 * @param columnno
 * 			The column number the message should be located on.
 */
public void runTest(String testfile, String key, int numErrors, int numWarnings, int lineno, int columnno) {
    ValidationReport valreport = validator.validate(testfile, null, configuration);
    ValidationMessage[] valmessages = valreport.getValidationMessages();
    int nummessages = valmessages.length;
    int errorCount = 0;
    int warningCount = 0;
    for (int i = 0; i < nummessages; i++) {
        ValidationMessage valmes = valmessages[i];
        String messkey = valmes.getKey();
        assertTrue("The message key " + key + " is not correct.", key.equals(messkey));
        assertEquals("The line number is incorrect.", lineno, valmes.getLineNumber());
        assertEquals("The column number is incorrect.", columnno, valmes.getColumnNumber());
        if (valmes.getSeverity() == ValidationMessage.SEV_LOW) {
            warningCount++;
        } else {
            errorCount++;
        }
    }
    assertEquals(errorCount + " errors were reported but " + numErrors + " errors were expected.", numErrors, errorCount);
    assertEquals(warningCount + " warnings were reported but " + numWarnings + " warnings were expected.", numWarnings, warningCount);
}
Also used : ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) ValidationReport(org.eclipse.wst.xml.core.internal.validation.core.ValidationReport)

Example 8 with ValidationMessage

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

the class ReferencedFileErrorsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final IMarker[] selectedMarkers = getSelectedMarkers(event);
    IMarker selectedMarker = selectedMarkers[0];
    if (selectedMarker != null) {
        try {
            IResource resource = selectedMarker.getResource();
            Map map = (Map) resource.getSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME);
            if (map == null) {
                String infoUnavailable = XMLValidationUIMessages._UI_DETAILS_INFORMATION_UNAVAILABLE;
                String revalidateToRegenerateErrors = XMLValidationUIMessages._UI_DETAILS_INFO_REVALIDATE_TO_REGENERATE;
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), infoUnavailable, revalidateToRegenerateErrors);
            } else {
                String uri = null;
                // $NON-NLS-1$
                String groupName = (String) selectedMarker.getAttribute("groupName");
                if (// $NON-NLS-1$
                groupName.startsWith("referencedFileError")) {
                    // $NON-NLS-1$
                    int index1 = groupName.indexOf("(");
                    // $NON-NLS-1$
                    int index2 = groupName.lastIndexOf(")");
                    if ((index1 != -1) && (index2 > index1)) {
                        uri = groupName.substring(index1 + 1, index2);
                    }
                }
                if (uri != null) {
                    List list = Collections.EMPTY_LIST;
                    ValidationMessage message = (ValidationMessage) map.get(uri);
                    if (message != null) {
                        list = message.getNestedMessages();
                    }
                    IPath resourceLocation = resource.getLocation();
                    if (resourceLocation != null) {
                        String validatedFileURI = resourceLocation.toOSString();
                        // $NON-NLS-1$
                        validatedFileURI = "file:/" + validatedFileURI;
                        ReferencedFileErrorDialog dialog = new ReferencedFileErrorDialog(HandlerUtil.getActiveShell(event), list, validatedFileURI, uri);
                        dialog.createAndOpen();
                    }
                }
            }
        } catch (CoreException e) {
        // Do nothing.
        }
    }
    return this;
}
Also used : ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 9 with ValidationMessage

use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage 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 10 with ValidationMessage

use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage 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)

Aggregations

ValidationMessage (org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage)12 Map (java.util.Map)3 ValidationReport (org.eclipse.wst.xml.core.internal.validation.core.ValidationReport)3 XSLValidationMessage (org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage)3 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 Message (org.eclipse.wst.validation.internal.core.Message)2 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ValidationResult (org.eclipse.wst.validation.ValidationResult)1 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)1 ErrorMessageInformation (org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationManager.ErrorMessageInformation)1