ClassificationsTransformerServlet.java
3.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.servlets.SlingSafeMethodsServlet
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.sitecatalyst.impl.servlets;
import com.day.cq.analytics.sitecatalyst.ClassificationsTransformer;
import com.day.cq.analytics.sitecatalyst.impl.servlets.ClassificationsTransformerService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(extensions={"json"}, selectors={"transformeroptions"}, resourceTypes={"cq/analytics/components/saintclassificationpage"}, methods={"GET"})
public class ClassificationsTransformerServlet
extends SlingSafeMethodsServlet {
private static final Logger LOG = LoggerFactory.getLogger(ClassificationsTransformerServlet.class);
@Reference
ClassificationsTransformerService transformerService;
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
JSONArray transformers = new JSONArray();
if (this.transformerService != null) {
Map<String, ClassificationsTransformer> transformersMap = this.transformerService.getTransformers();
if (transformersMap.size() > 0) {
for (Map.Entry<String, ClassificationsTransformer> entry : transformersMap.entrySet()) {
ClassificationsTransformer t = entry.getValue();
JSONObject o = new JSONObject();
o.put("name", (Object)entry.getKey());
o.put("class", (Object)t.getClass().getName());
transformers.put((Object)o);
}
}
} else {
LOG.warn("ClassificationsTransformerService not available.");
}
json.put("transformers", (Object)transformers);
out.write(json.toString());
}
catch (Exception e) {
throw new ServletException((Throwable)e);
}
}
protected void bindTransformerService(ClassificationsTransformerService classificationsTransformerService) {
this.transformerService = classificationsTransformerService;
}
protected void unbindTransformerService(ClassificationsTransformerService classificationsTransformerService) {
if (this.transformerService == classificationsTransformerService) {
this.transformerService = null;
}
}
}