LaunchesInfoProvider.java
4.52 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchManager
* com.adobe.cq.launches.api.LaunchManagerFactory
* com.adobe.granite.security.user.util.AuthorizableUtil
* com.adobe.granite.xss.XSSAPI
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageInfoProvider
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONException
* 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.LaunchManager;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.adobe.granite.security.user.util.AuthorizableUtil;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;
import java.util.Calendar;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, immediate=1)
@Service(value={PageInfoProvider.class})
public class LaunchesInfoProvider
implements PageInfoProvider {
private static final Logger log = LoggerFactory.getLogger(LaunchesInfoProvider.class);
@Reference
private LaunchManagerFactory launchManagerFactory;
@Reference
private XSSAPI xssApi;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
JSONObject launchesInfo = new JSONObject();
Page page = (Page)resource.adaptTo(Page.class);
if (page == null) {
log.warn("Ignoring '{}' for non-page resource: {}", (Object)this.getClass().getCanonicalName(), (Object)resource.getPath());
return;
}
Resource lRes = LaunchUtils.getLaunchResource(resource);
boolean isLaunch = lRes != null;
launchesInfo.put("isLaunch", isLaunch);
if (isLaunch) {
launchesInfo.put("launch", (Object)this.getLaunchInfo((Launch)lRes.adaptTo(Launch.class)));
} else {
LaunchManager launchManager = (LaunchManager)resource.getResourceResolver().adaptTo(LaunchManager.class);
launchesInfo.put("isInLaunch", launchManager.isInLaunch(resource));
}
info.put("launches", (Object)launchesInfo);
}
private JSONObject getLaunchInfo(Launch launch) throws JSONException {
JSONObject launchInfo = new JSONObject();
launchInfo.put("path", (Object)launch.getResource().getPath());
launchInfo.put("title", (Object)this.xssApi.filterHTML(launch.getTitle()));
Calendar liveDate = launch.getLiveDate();
if (liveDate != null) {
launchInfo.put("liveDate", liveDate.getTimeInMillis());
}
launchInfo.put("isProductionReady", launch.isProductionReady());
launchInfo.put("sourceRootResource", (Object)launch.getSourceRootResource().getPath());
launchInfo.put("isLiveCopy", launch.isLiveCopy());
launchInfo.put("cq:lastModified", launch.getModified().getTimeInMillis());
launchInfo.put("cq:lastModifiedBy", (Object)AuthorizableUtil.getFormattedName((ResourceResolver)launch.getResource().getResourceResolver(), (String)this.xssApi.encodeForJSString(launch.getModifiedBy())));
return launchInfo;
}
protected void bindLaunchManagerFactory(LaunchManagerFactory launchManagerFactory) {
this.launchManagerFactory = launchManagerFactory;
}
protected void unbindLaunchManagerFactory(LaunchManagerFactory launchManagerFactory) {
if (this.launchManagerFactory == launchManagerFactory) {
this.launchManagerFactory = null;
}
}
protected void bindXssApi(XSSAPI xSSAPI) {
this.xssApi = xSSAPI;
}
protected void unbindXssApi(XSSAPI xSSAPI) {
if (this.xssApi == xSSAPI) {
this.xssApi = null;
}
}
}