CommandServlet.java
2.88 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.servlets.AbstractCommandServlet
* com.day.cq.commons.servlets.HtmlStatusResponseHelper
* javax.servlet.ServletException
* javax.servlet.http.HttpServletResponse
* 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.HtmlResponse
*/
package com.day.cq.analytics.testandtarget.impl.servlets;
import com.day.cq.analytics.testandtarget.TestandtargetCommand;
import com.day.cq.analytics.testandtarget.impl.servlets.TargetCommandService;
import com.day.cq.commons.servlets.AbstractCommandServlet;
import com.day.cq.commons.servlets.HtmlStatusResponseHelper;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
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.HtmlResponse;
@SlingServlet(name="com.day.cq.analytics.testandtarget.impl.servlets.CommandServlet", paths={"/libs/cq/analytics/testandtarget/command"}, methods={"POST"})
public class CommandServlet
extends AbstractCommandServlet {
@Reference
private TargetCommandService commandService;
protected boolean hasCommand(SlingHttpServletRequest request) throws ServletException {
String cmd = request.getParameter("cmd");
return cmd != null;
}
protected void performCommand(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
try {
TestandtargetCommand cmd;
String command = request.getParameter("cmd");
HtmlResponse htmlResponse = null;
htmlResponse = this.commandService != null ? ((cmd = this.commandService.getCommand(command)) != null ? cmd.performCommand(request, response) : HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)("Unknown action " + command))) : HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)"TargetCommandService not available");
if (htmlResponse != null) {
htmlResponse.send((HttpServletResponse)response, false);
}
}
catch (Exception e) {
throw new ServletException(e.getMessage(), (Throwable)e);
}
}
protected void bindCommandService(TargetCommandService targetCommandService) {
this.commandService = targetCommandService;
}
protected void unbindCommandService(TargetCommandService targetCommandService) {
if (this.commandService == targetCommandService) {
this.commandService = null;
}
}
}