LiveCopyServiceImpl.java 5.21 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.msm.api.RolloutConfig
 *  com.day.cq.wcm.msm.api.RolloutConfigManager
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.LoginException
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 */
package com.day.cq.wcm.msm.impl;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutConfigManager;
import com.day.cq.wcm.msm.impl.LiveCopyIndexImpl;
import com.day.cq.wcm.msm.impl.LiveCopyManagerImpl;
import com.day.cq.wcm.msm.impl.RolloutConfigManagerFactory;
import java.util.Dictionary;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;

@Component
@Service(value={LiveCopyServiceImpl.class})
public class LiveCopyServiceImpl {
    static final String DEFAULT_PATH = "/content";
    static final String[] DEFAULT_EXCLUDED_PATHS = new String[]{"/content/dam"};
    @Property(value={"/content"}, propertyPrivate=1)
    static final String PATH = "cq.wcm.msm.liveCopyIndex.path";
    @Property(value={"/content/dam"}, propertyPrivate=1)
    static final String EXCLUDED_PATHS = "cq.wcm.msm.liveCopyIndex.excludedPaths";
    @Reference
    private ResourceResolverFactory resolverFactory = null;
    @Reference
    private RolloutConfigManagerFactory rolloutConfigManagerFactory = null;
    private ResourceResolver serviceUser;
    private LiveCopyIndexImpl index;

    @Activate
    protected void activate(ComponentContext context) throws LoginException, RepositoryException {
        String path = PropertiesUtil.toString(context.getProperties().get("cq.wcm.msm.liveCopyIndex.path"), (String)"/content");
        String[] excludedPaths = PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.liveCopyIndex.excludedPaths"), (String[])DEFAULT_EXCLUDED_PATHS);
        this.serviceUser = this.resolverFactory.getServiceResourceResolver(null);
        Session adminSession = (Session)this.serviceUser.adaptTo(Session.class);
        if (adminSession == null) {
            throw new IllegalArgumentException("Need a JCR ResourceResolver to run");
        }
        this.index = new LiveCopyIndexImpl(adminSession, path, excludedPaths);
        this.index.startListening();
    }

    @Deactivate
    protected void deactivate(ComponentContext context) throws RepositoryException {
        if (this.serviceUser != null && this.serviceUser.isLive()) {
            this.index.endListening();
            this.serviceUser.close();
        }
    }

    public LiveCopyManagerImpl createLiveCopyManager(ResourceResolver resolver) {
        Session adminSession = (Session)resolver.adaptTo(Session.class);
        if (adminSession == null) {
            throw new IllegalArgumentException("Need a ResourceResolver that adapts to Session");
        }
        return new LiveCopyManagerImpl(adminSession, this.index, this.rolloutConfigManagerFactory.create(resolver));
    }

    public int getIndexSize() throws RepositoryException, WCMException {
        return -1;
    }

    public void setIndexDirty() {
        this.getLiveCopyIndex().setDirty();
    }

    LiveCopyIndexImpl getLiveCopyIndex() {
        return this.index;
    }

    RolloutConfig getRolloutConfig(String path, ResourceResolver resolver) throws WCMException {
        return this.rolloutConfigManagerFactory.create(resolver).getRolloutConfig(path);
    }

    protected void bindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        this.resolverFactory = resourceResolverFactory;
    }

    protected void unbindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        if (this.resolverFactory == resourceResolverFactory) {
            this.resolverFactory = null;
        }
    }

    protected void bindRolloutConfigManagerFactory(RolloutConfigManagerFactory rolloutConfigManagerFactory) {
        this.rolloutConfigManagerFactory = rolloutConfigManagerFactory;
    }

    protected void unbindRolloutConfigManagerFactory(RolloutConfigManagerFactory rolloutConfigManagerFactory) {
        if (this.rolloutConfigManagerFactory == rolloutConfigManagerFactory) {
            this.rolloutConfigManagerFactory = null;
        }
    }
}