PreviewOperation.java 3.13 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.ui.components.HtmlResponse
 *  com.day.cq.i18n.I18n
 *  javax.servlet.http.HttpServletRequest
 *  org.apache.commons.lang.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.servlets.post.Modification
 *  org.slf4j.Logger
 */
package com.adobe.cq.mobile.dps.impl.operations;

import com.adobe.cq.mobile.dps.DPSException;
import com.adobe.cq.mobile.dps.DPSProject;
import com.adobe.cq.mobile.dps.impl.DPSClient;
import com.adobe.cq.mobile.dps.impl.operations.MobilePublishAbstractOperation;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
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.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlets.post.Modification;
import org.slf4j.Logger;

@Component(metatype=0, label="Experience Manager Mobile Preview")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"dpsapps:preview"}), @Property(name="sling.servlet.methods", value={"POST"})})
public class PreviewOperation
extends MobilePublishAbstractOperation {
    @Override
    protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> modifications) {
        I18n i18n = new I18n((HttpServletRequest)request);
        Resource resource = request.getResource();
        try {
            DPSProject dpsProject = this.getDPSProject(request);
            DPSClient dpsClient = this.getDPSClient(request);
            if (dpsProject == null) {
                String message = i18n.get("Invalid project resource {0}", "resource path", new Object[]{resource.getPath()});
                throw new DPSException(message);
            }
            dpsClient.preview(dpsProject);
            response.setPath(resource.getPath());
            String title = i18n.get("Preview initiated");
            String message = i18n.get("Preview initiated for {0}.", "project path", new Object[]{resource.getPath()});
            this.generateResponse(response, 200, message, title);
        }
        catch (Exception ex) {
            String title = i18n.get("Error");
            String cause = this.getCauseMessage(ex);
            if (StringUtils.isEmpty((String)cause)) {
                cause = ex.getLocalizedMessage();
            }
            String message = i18n.get("Error initiating preview: {0}. {1}", "project path and root cause", new Object[]{resource.getName(), cause});
            this.getLogger().error(message, (Throwable)ex);
            this.generateError(response, message, title, ex);
        }
    }
}