JsonResponse.java
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletResponse
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
*/
package com.day.crx.packaging.impl.response;
import com.day.crx.packaging.impl.response.BaseResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import javax.servlet.http.HttpServletResponse;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
public class JsonResponse
extends BaseResponse {
private boolean inTextarea;
public JsonResponse(boolean inTextarea) {
this.inTextarea = inTextarea;
}
@Override
public void send() throws IOException {
HttpServletResponse response = this.getServletResponse();
if (this.inTextarea) {
response.setContentType("text/html; charset=utf-8");
} else {
response.setContentType("application/json; charset=utf-8");
}
PrintWriter out = response.getWriter();
if (this.inTextarea) {
out.print("<textarea>");
}
JSONWriter w = new JSONWriter((Writer)out);
try {
w.object();
w.key("success").value(this.successful());
if (this.message.length() > 0) {
w.key("msg").value((Object)this.message);
}
if (this.path.length() > 0) {
w.key("path").value((Object)this.path);
}
w.endObject();
}
catch (JSONException e) {
throw new IOException(e.toString());
}
if (this.inTextarea) {
out.print("</textarea>");
}
}
}