Search in sources :

Example 36 with IReporter

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

the class HTMLValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    IReporter reporter = result.getReporter(monitor);
    validateFile(null, reporter, (IFile) resource, result);
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 37 with IReporter

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

the class JSPHTMLValidatorTest method testJSPinAttributes.

/**
 * Tests jsp expression in html attributes in jsp file
 *
 * @throws Exception
 */
public void testJSPinAttributes() throws Exception {
    JSPContentValidator validator = new JSPContentValidator();
    IReporter reporter = new ReporterForTest();
    ValidationContextForTest helper = new ValidationContextForTest();
    String filePath = "/" + PROJECT_NAME + "/WebContent/usejspinattribute.jsp";
    helper.setURI(filePath);
    validator.validate(helper, reporter);
    assertTrue("jsp in attributes are errors when they should not be (in .jsp)", reporter.getMessages().isEmpty());
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) JSPContentValidator(org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)

Example 38 with IReporter

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

the class JSPJavaTranslatorCustomTagTest method test_310085.

/**
 * Tests jsp translation when custom tag used
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=310085
 *
 * @throws Exception
 */
public void test_310085() throws Exception {
    // $NON-NLS-1$
    String projectName = "bug_310085";
    // Create new project
    IProject project = BundleResourceUtil.createJavaWebProject(projectName);
    assertTrue(project.exists());
    // $NON-NLS-1$ //$NON-NLS-2$
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
    // $NON-NLS-1$
    IFile file = project.getFile("WebContent/test310085.jsp");
    assertTrue(file.exists());
    JSPValidator validator = new JSPJavaValidator();
    IReporter reporter = new ReporterForTest();
    ValidationContextForTest helper = new ValidationContextForTest();
    helper.setURI(file.getFullPath().toString());
    validator.validate(helper, reporter);
    String strings = "";
    for (int i = 0; i < reporter.getMessages().size(); i++) {
        strings = strings + ((IMessage) reporter.getMessages().get(i)).getText() + "\n";
    }
    assertTrue("Found JSP Java problem(s) for custom tag: " + strings, reporter.getMessages().isEmpty());
}
Also used : IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) JSPValidator(org.eclipse.jst.jsp.core.internal.validation.JSPValidator) ValidationContextForTest(org.eclipse.jst.jsp.core.tests.validation.ValidationContextForTest) ReporterForTest(org.eclipse.jst.jsp.core.tests.validation.ReporterForTest) IProject(org.eclipse.core.resources.IProject) JSPJavaValidator(org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator)

Example 39 with IReporter

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

the class JSPActionValidatorTest method testAttributesCorrect.

/**
 * Tests if missing required attributes are detected
 *
 * @throws Exception
 */
public void testAttributesCorrect() throws Exception {
    JSPActionValidator validator = new JSPActionValidator();
    IReporter reporter = new ReporterForTest();
    ValidationContextForTest helper = new ValidationContextForTest();
    String filePath = "/" + PROJECT_NAME + "/WebContent/worksfine.jsp";
    assertTrue("unable to find file: " + filePath, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath)).exists());
    helper.setURI(filePath);
    validator.validate(helper, reporter);
    StringBuffer error = new StringBuffer("jsp action validator found errors when it should not have");
    List messages = reporter.getMessages();
    for (int i = 0; i < messages.size(); i++) {
        error.append('\n');
        error.append(((IMessage) messages.get(i)).getText());
    }
    assertTrue(error.toString(), reporter.getMessages().isEmpty());
}
Also used : Path(org.eclipse.core.runtime.Path) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) JSPActionValidator(org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator)

Example 40 with IReporter

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

the class JSPActionValidatorTest method testMissingRequiredAttribute.

/**
 * Tests if missing required attributes are detected
 *
 * @throws Exception
 */
public void testMissingRequiredAttribute() throws Exception {
    JSPActionValidator validator = new JSPActionValidator();
    IReporter reporter = new ReporterForTest();
    ValidationContextForTest helper = new ValidationContextForTest();
    String filePath = "/" + PROJECT_NAME + "/WebContent/norequiredattribute.jsp";
    assertTrue("unable to find file: " + filePath, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath)).exists());
    helper.setURI(filePath);
    validator.validate(helper, reporter);
    boolean foundError = errorMessageFound(reporter, NLS.bind(JSPCoreMessages.JSPDirectiveValidator_5, REQUIRED_ATTR_NAME), 11);
    if (foundError)
        foundError = errorMessageFound(reporter, NLS.bind(JSPCoreMessages.JSPDirectiveValidator_5, REQUIRED_ATTR_NAME), 12);
    assertTrue("jsp action validator did not detect missing required attributes", foundError);
}
Also used : Path(org.eclipse.core.runtime.Path) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) JSPActionValidator(org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator)

Aggregations

IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)43 IFile (org.eclipse.core.resources.IFile)17 Path (org.eclipse.core.runtime.Path)15 List (java.util.List)11 JSPJavaValidator (org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator)10 ValidationResult (org.eclipse.wst.validation.ValidationResult)9 Test (org.junit.Test)8 IProject (org.eclipse.core.resources.IProject)7 IPath (org.eclipse.core.runtime.IPath)7 JSPValidator (org.eclipse.jst.jsp.core.internal.validation.JSPValidator)7 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)6 CoreException (org.eclipse.core.runtime.CoreException)5 ReporterForTest (org.eclipse.jst.jsp.core.tests.validation.ReporterForTest)5 ValidationContextForTest (org.eclipse.jst.jsp.core.tests.validation.ValidationContextForTest)5 IOException (java.io.IOException)4 JSPActionValidator (org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator)4 JSPDirectiveValidator (org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)4 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)4 Iterator (java.util.Iterator)3 JSPContentValidator (org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)3