CompareLaunchServlet.java
8.22 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchException
* com.adobe.cq.launches.api.LaunchManager
* com.adobe.cq.launches.api.LaunchManagerFactory
* com.adobe.cq.launches.api.LaunchPromotionScope
* com.adobe.cq.launches.api.LaunchResourceStatus
* com.adobe.cq.launches.api.LaunchResourceStatus$LaunchStatusType
* com.adobe.granite.security.user.util.AuthorizableUtil
* com.day.cq.commons.JSONWriterUtil
* com.day.cq.commons.JSONWriterUtil$WriteMode
* com.day.cq.xss.XSSProtectionService
* javax.jcr.RangeIterator
* javax.servlet.ServletException
* org.apache.commons.lang.StringUtils
* 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.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* 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.adobe.cq.wcm.launches.impl;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchException;
import com.adobe.cq.launches.api.LaunchManager;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.adobe.cq.launches.api.LaunchPromotionScope;
import com.adobe.cq.launches.api.LaunchResourceStatus;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.adobe.granite.security.user.util.AuthorizableUtil;
import com.day.cq.commons.JSONWriterUtil;
import com.day.cq.xss.XSSProtectionService;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Date;
import javax.jcr.RangeIterator;
import javax.servlet.ServletException;
import org.apache.commons.lang.StringUtils;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
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(resourceTypes={"wcm/launches/components/launch"}, selectors={"compare"}, extensions={"json"}, methods={"GET"})
public class CompareLaunchServlet
extends SlingSafeMethodsServlet {
private static final long serialVersionUID = -9165801886033663549L;
private static final String START_PATH_PARAM = "startPath";
private static final String SCOPE_PARAM = "scope";
private static final String TARGET_PARAM = "target";
private static final String MAX_REF_NO = "maxRefNo";
protected static final Logger log = LoggerFactory.getLogger(CompareLaunchServlet.class);
@Reference
LaunchManagerFactory launchesManagerFactory = null;
@Reference
private XSSProtectionService xss;
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
try {
long totalNo;
Resource launchResource;
Integer maxRefNo;
String maxRefNoStr;
LaunchPromotionScope promotionScope;
Resource startResource;
Resource resource = request.getResource();
Launch launch = (Launch)resource.adaptTo(Launch.class);
ResourceResolver resolver = request.getResourceResolver();
JSONObject object = new JSONObject();
String startPath = request.getParameter("startPath");
startPath = StringUtils.isEmpty((String)startPath) ? null : startPath;
String promotionScopeString = request.getParameter("scope");
try {
promotionScope = LaunchPromotionScope.valueOf((String)promotionScopeString.toUpperCase());
}
catch (IllegalArgumentException e) {
throw new LaunchException("Unrecognized launch promotion scope: " + promotionScopeString);
}
Launch target = null;
String targetPath = request.getParameter("target");
if (targetPath != null && (launchResource = request.getResourceResolver().getResource(targetPath)) != null) {
target = (Launch)launchResource.adaptTo(Launch.class);
}
Integer n = maxRefNo = StringUtils.isEmpty((String)(maxRefNoStr = request.getParameter("maxRefNo"))) ? null : Integer.valueOf(Integer.parseInt(maxRefNoStr));
if (startPath != null && LaunchUtils.isLaunchBasedPath(startPath)) {
startResource = LaunchUtils.getTargetResource(resolver.getResource(startPath), target);
if (startResource == null) {
startResource = resolver.getResource(startPath);
}
} else {
startResource = resolver.getResource(startPath);
}
LaunchManager launchManager = this.launchesManagerFactory.getLaunchManager(resolver);
RangeIterator statusesIt = launchManager.getResourcesStatus(launch, startResource, promotionScope, target);
JSONArray pages = new JSONArray();
for (totalNo = 0; statusesIt.hasNext() && (maxRefNo == null || totalNo <= (long)maxRefNo.intValue()); ++totalNo) {
LaunchResourceStatus status = (LaunchResourceStatus)statusesIt.next();
JSONObject stat = new JSONObject();
JSONWriterUtil.put((JSONObject)stat, (String)"path", (String)status.getResourcePath(), (JSONWriterUtil.WriteMode)JSONWriterUtil.WriteMode.BOTH, (XSSProtectionService)this.xss);
JSONWriterUtil.put((JSONObject)stat, (String)"title", (String)status.getTitle(), (JSONWriterUtil.WriteMode)JSONWriterUtil.WriteMode.BOTH, (XSSProtectionService)this.xss);
JSONWriterUtil.putOptional((JSONObject)stat, (String)"launchLastModifiedBy", (String)AuthorizableUtil.getFormattedName((ResourceResolver)resolver, (String)status.getLaunchUserId()), (JSONWriterUtil.WriteMode)JSONWriterUtil.WriteMode.BOTH, (XSSProtectionService)this.xss);
stat.put("launchLastModified", (Object)(status.getLaunchModificationDate() != null ? Long.valueOf(status.getLaunchModificationDate().getTime()) : null));
JSONWriterUtil.putOptional((JSONObject)stat, (String)"productionLastModifiedBy", (String)AuthorizableUtil.getFormattedName((ResourceResolver)resolver, (String)status.getProductionUserId()), (JSONWriterUtil.WriteMode)JSONWriterUtil.WriteMode.BOTH, (XSSProtectionService)this.xss);
stat.put("productionLastModified", (Object)(status.getProductionModificationDate() != null ? Long.valueOf(status.getProductionModificationDate().getTime()) : null));
stat.put("type", (Object)status.getType().toString());
pages.put((Object)stat);
}
object.put("pages", (Object)pages);
if (maxRefNo != null && totalNo > (long)maxRefNo.intValue() && statusesIt.hasNext()) {
totalNo = statusesIt.getSize();
}
object.put("totalPages", totalNo);
object.write((Writer)response.getWriter());
}
catch (Exception e) {
throw new ServletException((Throwable)e);
}
}
protected void bindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
this.launchesManagerFactory = launchManagerFactory;
}
protected void unbindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
if (this.launchesManagerFactory == launchManagerFactory) {
this.launchesManagerFactory = null;
}
}
protected void bindXss(XSSProtectionService xSSProtectionService) {
this.xss = xSSProtectionService;
}
protected void unbindXss(XSSProtectionService xSSProtectionService) {
if (this.xss == xSSProtectionService) {
this.xss = null;
}
}
}