Package org.apache.sling.validation.api

Examples of org.apache.sling.validation.api.ValidationResult


            ValidationModel vm = validationService.getValidationModel("sling/validation/test", "/apps/validation/1/resource");
            HashMap<String, Object> hashMap = new HashMap<String, Object>() {{
                put("field1", "1");
            }};
            ValueMap map = new ValueMapDecorator(hashMap);
            ValidationResult vr = validationService.validate(map, vm);
        } finally {
            if (model1 != null) {
                rr.delete(model1);
            }
            if (rr != null) {
View Full Code Here


            HashMap<String, Object> hashMap = new HashMap<String, Object>() {{
                put("field1", "HelloWorld");
                put("field2", "HelloWorld");
            }};
            ValueMap map = new ValueMapDecorator(hashMap);
            ValidationResult vr = validationService.validate(map, vm);
            assertFalse(vr.isValid());
            // check for correct error message
            Map<String, List<String>> expectedFailureMessages = new HashMap<String, List<String>>();
            expectedFailureMessages.put("field2", Arrays.asList("Property does not match the pattern " + TEST_REGEX));
            Assert.assertThat(vr.getFailureMessages().entrySet(), Matchers.equalTo(expectedFailureMessages.entrySet()));
            if (model1 != null) {
                rr.delete(model1);
            }
        } finally {
            if (rr != null) {
View Full Code Here

                    put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
                }});
                rr.commit();
            }
            ValidationModel vm = validationService.getValidationModel("sling/validation/test", "/apps/validation/1/resource");
            ValidationResult vr = validationService.validate(testResource, vm);
            assertFalse(vr.isValid());
            assertTrue(vr.getFailureMessages().containsKey("child1/hello"));
        } finally {
            if (rr != null) {
                if (model1 != null) {
                    rr.delete(model1);
                }
View Full Code Here

            }
            if (resourceType != null && !"".equals(resourceType)) {
                String resourcePath = request.getRequestPathInfo().getResourcePath();
                ValidationModel vm = validationService.getValidationModel(resourceType, resourcePath);
                if (vm != null) {
                    ValidationResult vr = validationService.validate(requestParameters, vm);
                    vpr.setValidationResult(vr);
                } else {
                    LOG.error("No validation model for resourceType {} and resourcePath {} ", resourceType, resourcePath);
                }
            }
View Full Code Here

    @PostConstruct
    protected void validate() {
        ValidationModel model = validationService.getValidationModel(resource);
        if (model != null) {
            ValidationResult result = validationService.validate(resource, model);
            if (!result.isValid()) {
                errors = result.getFailureMessages();
            }
        }
    }
View Full Code Here

        }
        if (resourceType != null && !"".equals(resourceType)) {
            String resourcePath = request.getRequestPathInfo().getResourcePath();
            ValidationModel vm = validationService.getValidationModel(resourceType, resourcePath);
            if (vm != null) {
                ValidationResult vr = validationService.validate(requestParameters, vm);
                if (vr.isValid()) {
                    RequestDispatcherOptions options = new RequestDispatcherOptions();
                    options.setReplaceSelectors(" ");
                    request.getRequestDispatcher(request.getResource(), options).forward(request, response);
                } else {
                    response.setContentType("application/json");
                    JSONObject json = new JSONObject();
                    try {
                        json.put("success", false);
                        JSONObject messages = new JSONObject();
                        for (Map.Entry<String, List<String>> entry : vr.getFailureMessages().entrySet()) {
                            String key = entry.getKey();
                            JSONArray errors = new JSONArray();
                            for (String message : entry.getValue()) {
                                errors.put(message);
                            }
View Full Code Here

TOP

Related Classes of org.apache.sling.validation.api.ValidationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.