InfoServlet.java
3.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.TidyJSONWriter
* com.day.cq.commons.servlets.AbstractPredicateServlet
* com.day.cq.wcm.msm.api.RolloutManager
* javax.jcr.RepositoryException
* javax.servlet.ServletException
* org.apache.commons.collections.Predicate
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.apache.sling.commons.osgi.OsgiUtil
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceReference
* org.osgi.service.component.ComponentContext
*/
package com.day.cq.wcm.msm.impl.servlets;
import com.day.cq.commons.TidyJSONWriter;
import com.day.cq.commons.servlets.AbstractPredicateServlet;
import com.day.cq.wcm.msm.api.RolloutManager;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import javax.jcr.RepositoryException;
import javax.servlet.ServletException;
import org.apache.commons.collections.Predicate;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
@SlingServlet(resourceTypes={"wcm/msm/components/msminfo"}, extensions={"json"}, methods={"GET"})
public class InfoServlet
extends AbstractPredicateServlet {
private static final long serialVersionUID = -4077076965843907619L;
private static final String TIDY_PARAM = "tidy";
private BundleContext ctx;
protected void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp, Predicate predicate) throws ServletException, IOException {
StringWriter buf = new StringWriter();
TidyJSONWriter out = new TidyJSONWriter((Writer)buf);
out.setTidy("true".equals(req.getParameter("tidy")));
try {
out.object().key("config").object();
String sv = RolloutManager.class.getName();
ServiceReference svcRef = this.ctx.getServiceReference(sv);
if (svcRef != null) {
out.key(RolloutManager.class.getName()).object();
InfoServlet.writePropertyArray(svcRef, "rolloutmgr.excludedprops.default", (JSONWriter)out);
InfoServlet.writePropertyArray(svcRef, "rolloutmgr.excludedparagraphprops.default", (JSONWriter)out);
out.endObject();
}
out.endObject().endObject();
}
catch (Exception e) {
throw new ServletException((Throwable)e);
}
resp.setContentType("application/json");
resp.setCharacterEncoding("utf-8");
resp.getWriter().print(buf.getBuffer().toString());
}
@Activate
protected void activate(ComponentContext context) throws RepositoryException {
this.ctx = context.getBundleContext();
}
private static void writePropertyArray(ServiceReference svcRef, String name, JSONWriter out) throws JSONException {
String[] excludes = OsgiUtil.toStringArray((Object)svcRef.getProperty("rolloutmgr.excludedprops.default"));
out.key(name).array();
for (String exclude : excludes) {
out.value((Object)exclude);
}
out.endArray();
}
}