LiveRelationshipReferenceProvider.java
3.75 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.wcm.launches.utils.LaunchUtils
* com.adobe.granite.references.Reference
* com.adobe.granite.references.ReferenceProvider
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveRelationshipManager
* com.day.cq.wcm.msm.api.LiveStatus
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.api.RolloutManager$Trigger
* javax.jcr.RangeIterator
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.references;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.adobe.granite.references.ReferenceProvider;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.RangeIterator;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={ReferenceProvider.class})
public class LiveRelationshipReferenceProvider
implements ReferenceProvider {
@Reference
private LiveRelationshipManager liveRelationshipManager = null;
public static final String REFERENCE_TYPE = "liveCopy";
private static final Logger log = LoggerFactory.getLogger(LiveRelationshipReferenceProvider.class);
public List<com.adobe.granite.references.Reference> getReferences(Resource resource) {
ArrayList<com.adobe.granite.references.Reference> references = new ArrayList<com.adobe.granite.references.Reference>();
ResourceResolver resolver = resource.getResourceResolver();
try {
RangeIterator relationships = this.liveRelationshipManager.getLiveRelationships(resource, null, null);
while (relationships.hasNext()) {
LiveRelationship liveRelationship = (LiveRelationship)relationships.next();
boolean isLaunch = LaunchUtils.isLaunchResourcePath((String)liveRelationship.getTargetPath());
if (liveRelationship.getStatus().isTargetExisting() && !isLaunch) {
references.add(new com.adobe.granite.references.Reference(resolver.getResource(liveRelationship.getSourcePath()), resolver.getResource(liveRelationship.getTargetPath()), "liveCopy"));
continue;
}
log.debug("Omitted reference to non-existing Target from {} to {}", (Object)liveRelationship.getSourcePath(), (Object)liveRelationship.getTargetPath());
}
}
catch (WCMException e) {
log.error("Failed to access the LiveRelationships for {}, {} -> return empty", (Object)resource.getPath(), (Object)e);
}
return references;
}
public String getType() {
return "liveCopy";
}
protected void bindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
this.liveRelationshipManager = liveRelationshipManager;
}
protected void unbindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
if (this.liveRelationshipManager == liveRelationshipManager) {
this.liveRelationshipManager = null;
}
}
}