You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/20 14:40:12 UTC
[sling-org-apache-sling-validation-examples] 23/24: SLING-6914:
Remove commons.json from bundles/extensions/validation/examples
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-examples.git
commit 9f4aa15a9f24038615c1bb27a4746322e882ee36
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Thu Jun 1 22:02:38 2017 +0000
SLING-6914: Remove commons.json from bundles/extensions/validation/examples
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1797284 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 9 ++++---
.../examples/servlets/ModifyUserServlet.java | 31 +++++++++-------------
2 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index c1462fc..9ce976a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,9 @@
</Export-Package>
<Sling-Model-Packages>org.apache.sling.validation.examples.models</Sling-Model-Packages>
<Sling-Initial-Content>SLING-INF;</Sling-Initial-Content>
+ <Embed-Dependency>
+ org.apache.felix.utils;inline=org/apache/felix/utils/json/JSONWriter.class
+ </Embed-Dependency>
</instructions>
</configuration>
</plugin>
@@ -115,9 +118,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.json</artifactId>
- <version>2.0.6</version>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <version>1.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
diff --git a/src/main/java/org/apache/sling/validation/examples/servlets/ModifyUserServlet.java b/src/main/java/org/apache/sling/validation/examples/servlets/ModifyUserServlet.java
index b3a832f..71a5806 100644
--- a/src/main/java/org/apache/sling/validation/examples/servlets/ModifyUserServlet.java
+++ b/src/main/java/org/apache/sling/validation/examples/servlets/ModifyUserServlet.java
@@ -27,14 +27,12 @@ import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
+import org.apache.felix.utils.json.JSONWriter;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestDispatcherOptions;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.validation.ValidationFailure;
import org.apache.sling.validation.ValidationResult;
import org.apache.sling.validation.ValidationService;
@@ -69,22 +67,19 @@ public class ModifyUserServlet extends SlingAllMethodsServlet {
request.getRequestDispatcher(request.getResource(), options).forward(request, response);
} else {
response.setContentType("application/json");
- JSONObject json = new JSONObject();
- try {
- json.put("success", false);
- JSONArray failures = new JSONArray();
- for (ValidationFailure failure : vr.getFailures()) {
- JSONObject failureJson = new JSONObject();
- failureJson.put("message", failure.getMessage(request.getResourceBundle(Locale.US)));
- failureJson.put("location", failure.getLocation());
- failures.put(failureJson);
- }
- json.put("failures", failures);
- response.getWriter().print(json.toString());
- response.setStatus(400);
- } catch (JSONException e) {
- throw new IOException(e);
+ JSONWriter writer = new JSONWriter(response.getWriter());
+ writer.object();
+ writer.key("success").value(false);
+ writer.key("failures").array();
+ for (ValidationFailure failure : vr.getFailures()) {
+ writer.object();
+ writer.key("message").value(failure.getMessage(request.getResourceBundle(Locale.US)));
+ writer.key("location").value(failure.getLocation());
+ writer.endObject();
}
+ writer.endArray();
+ writer.endObject();
+ response.setStatus(400);
}
}
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.