ContentDiffZipServlet.java 5.53 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.contentsync.config.Config
 *  javax.jcr.Session
 *  javax.servlet.ServletException
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.SlingHttpServletResponse
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.apache.sling.api.servlets.SlingAllMethodsServlet
 *  org.osgi.service.cm.ConfigurationAdmin
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.appcache.impl;

import com.adobe.cq.mobile.appcache.impl.AppCacheManager;
import com.adobe.cq.mobile.appcache.impl.AppCacheManagerAdapterFactory;
import com.adobe.cq.mobile.appcache.impl.AppCacheUtil;
import com.day.cq.contentsync.config.Config;
import java.io.IOException;
import java.util.Date;
import javax.jcr.Session;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
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.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0, label="CQ Content Sync Diff Zip Servlet")
@Service
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"contentsync/config"}, propertyPrivate=1), @Property(name="sling.servlet.methods", value={"GET"}, propertyPrivate=1), @Property(name="sling.servlet.selectors", value={"pge-updates"}, propertyPrivate=1), @Property(name="sling.servlet.extensions", value={"zip"}, propertyPrivate=1)})
public class ContentDiffZipServlet
extends SlingAllMethodsServlet {
    private static final long serialVersionUID = 4572843577190321593L;
    protected static final Logger log = LoggerFactory.getLogger(ContentDiffZipServlet.class);
    @Reference
    private AppCacheManagerAdapterFactory appCacheManagerAdapterFactory;
    @Reference
    private ResourceResolverFactory resolverFactory;
    @Reference
    private ConfigurationAdmin configurationAdmin = null;

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        try {
            Session session = (Session)request.getResourceResolver().adaptTo(Session.class);
            String zipRedirectPath = null;
            Resource resource = request.getResource();
            Config config = (Config)resource.adaptTo(Config.class);
            long ifModifiedSince = request.getDateHeader("If-Modified-Since");
            if (ifModifiedSince == -1 && request.getParameter("ifModifiedSince") != null && request.getParameter("ifModifiedSince").length() > 0) {
                ifModifiedSince = new Long(request.getParameter("ifModifiedSince"));
            }
            log.debug("ifModifiedSince: " + ifModifiedSince);
            String authorizable = AppCacheUtil.getAuthorizable(this.configurationAdmin, config);
            AppCacheUtil.setupCacheACLs(this.resolverFactory, config, session, false, true, true, authorizable);
            if (ifModifiedSince != -1) {
                AppCacheManager appCacheManager = this.appCacheManagerAdapterFactory.getAdapter((Object)session, AppCacheManager.class);
                zipRedirectPath = AppCacheUtil.getZipPath(appCacheManager, config, new Date(ifModifiedSince), session);
            }
            log.debug("redirect path: " + zipRedirectPath);
            if (zipRedirectPath != null) {
                response.sendRedirect(request.getContextPath() + zipRedirectPath);
            } else {
                response.setStatus(304);
            }
        }
        catch (Exception e) {
            throw new ServletException((Throwable)e);
        }
    }

    protected void bindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
        this.appCacheManagerAdapterFactory = appCacheManagerAdapterFactory;
    }

    protected void unbindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
        if (this.appCacheManagerAdapterFactory == appCacheManagerAdapterFactory) {
            this.appCacheManagerAdapterFactory = null;
        }
    }

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

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

    protected void bindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
        this.configurationAdmin = configurationAdmin;
    }

    protected void unbindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
        if (this.configurationAdmin == configurationAdmin) {
            this.configurationAdmin = null;
        }
    }
}