This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-validation-test-services.git
commit f68f70437d7827f419c8deeb428c5026514beb12 Author: Konrad Windszus <k...@apache.org> AuthorDate: Fri Jan 8 08:51:00 2016 +0000 SLING-4213 leverage sling-i18n for validation failure messages git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723664 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 6 ++++++ .../sling/validation/testservices/ValidationPostResponse.java | 11 ++++++++--- .../testservices/ValidationPostResponseCreator.java | 4 +++- .../SLING-CONTENT/apps/sling/validation/models/model1.json | 5 ++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 0081deb..1f50b5c 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + <version>3.0.0</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.api</artifactId> <version>2.4.2</version> diff --git a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java index 4b71762..8cd45d8 100644 --- a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java +++ b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponse.java @@ -20,9 +20,9 @@ package org.apache.sling.validation.testservices; import java.io.IOException; import java.io.PrintWriter; -import java.util.List; -import java.util.Map; +import java.util.ResourceBundle; +import javax.annotation.Nonnull; import javax.servlet.http.HttpServletResponse; import org.apache.sling.commons.json.JSONArray; @@ -37,8 +37,13 @@ import org.slf4j.LoggerFactory; public class ValidationPostResponse extends AbstractPostResponse { private ValidationResult validationResult; + private final ResourceBundle resourceBundle; private static final Logger LOG = LoggerFactory.getLogger(ValidationPostResponse.class); + public ValidationPostResponse(@Nonnull ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + } + public void setValidationResult(ValidationResult validationResult) { this.validationResult = validationResult; } @@ -55,7 +60,7 @@ public class ValidationPostResponse extends AbstractPostResponse { JSONArray failures = new JSONArray(); for (ValidationFailure failure : validationResult.getFailures()) { JSONObject failureJson = new JSONObject(); - failureJson.put("message", failure.getMessage()); + failureJson.put("message", failure.getMessage(resourceBundle)); failureJson.put("location", failure.getLocation()); failures.put(failureJson); } diff --git a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponseCreator.java b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponseCreator.java index d96c201..a884749 100644 --- a/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponseCreator.java +++ b/src/main/java/org/apache/sling/validation/testservices/ValidationPostResponseCreator.java @@ -18,6 +18,8 @@ */ package org.apache.sling.validation.testservices; +import java.util.Locale; + import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; import org.apache.sling.api.SlingHttpServletRequest; @@ -33,7 +35,7 @@ public class ValidationPostResponseCreator implements PostResponseCreator { public PostResponse createPostResponse(SlingHttpServletRequest request) { String operation = request.getParameter(SlingPostConstants.RP_OPERATION); if (operation != null && "validation".equals(operation)) { - return new ValidationPostResponse(); + return new ValidationPostResponse(request.getResourceBundle(Locale.US)); } return null; } diff --git a/src/main/resources/SLING-CONTENT/apps/sling/validation/models/model1.json b/src/main/resources/SLING-CONTENT/apps/sling/validation/models/model1.json index 8b59679..85ad3bc 100644 --- a/src/main/resources/SLING-CONTENT/apps/sling/validation/models/model1.json +++ b/src/main/resources/SLING-CONTENT/apps/sling/validation/models/model1.json @@ -13,13 +13,12 @@ "jcr:primaryType" : "nt:unstructured", "org.apache.sling.validation.impl.validators.RegexValidator": { "jcr:primaryType" : "nt:unstructured", - "validatorArguments" : ["regex=^\\p{L}+$"] + "validatorArguments" : ["regex=^\\\p{Upper}+$"] } } }, "field2" : { - "jcr:primaryType" : "nt:unstructured", - "propertyType" : "date" + "jcr:primaryType" : "nt:unstructured" } } } -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.