LaunchesInfoProvider.java 4.52 KB
/*
 * 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;
        }
    }
}