LiveRelationshipReferenceProvider.java 3.75 KB
/*
 * 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;
        }
    }
}