MobileAbstractOperation.java 4.5 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.ui.components.HtmlResponse
 *  com.adobe.granite.xss.XSSAPI
 *  javax.jcr.RepositoryException
 *  org.apache.commons.lang.StringUtils
 *  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.servlets.post.AbstractPostOperation
 *  org.apache.sling.servlets.post.Modification
 *  org.apache.sling.servlets.post.PostResponse
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.platform.impl.operations;

import com.adobe.cq.mobile.appcache.impl.AppCacheManagerAdapterFactory;
import com.adobe.granite.ui.components.HtmlResponse;
import com.adobe.granite.xss.XSSAPI;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
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.servlets.post.AbstractPostOperation;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.PostResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0, label="Mobile Abstract Operation")
@Service
public abstract class MobileAbstractOperation
extends AbstractPostOperation {
    @Reference
    protected XSSAPI xssAPI;
    @Reference
    protected AppCacheManagerAdapterFactory appCacheManagerAdapterFactory;
    public static final String NS_MOBILE = "mobileapps:";
    public static final Logger LOGGER = LoggerFactory.getLogger(MobileAbstractOperation.class);

    protected void doRun(SlingHttpServletRequest request, PostResponse response, List<Modification> changes) throws RepositoryException {
        this.perform(request, (HtmlResponse)response, changes);
    }

    protected abstract void perform(SlingHttpServletRequest var1, HtmlResponse var2, List<Modification> var3);

    protected void generateResponse(HtmlResponse response, int statusCode, String message, String title, String redirectLink, String linkTitle) {
        response.setStatus(statusCode, message);
        response.setTitle(title);
        response.setDescription(message);
        if (StringUtils.isNotBlank((String)redirectLink)) {
            response.addRedirectLink(redirectLink, linkTitle);
        }
    }

    protected void addLink(HtmlResponse response, String rel, String url, String title) {
        response.addLink(rel, url, title);
    }

    protected void generateResponse(HtmlResponse response, int statusCode, String message, String title) {
        this.generateResponse(response, statusCode, message, title, null, null);
    }

    protected void generateError(HtmlResponse response, String message, String title) {
        this.generateError(response, message, title, null);
    }

    protected void generateError(HtmlResponse response, String message, String title, Throwable exception) {
        if (exception == null) {
            LOGGER.error(title + ":" + message);
        } else {
            LOGGER.error(title + ":" + message, exception);
        }
        this.generateResponse(response, 500, message, title);
    }

    protected void generateError(HtmlResponse response, String message, String title, Throwable exception, String redirect, String redirectTitle) {
        if (exception == null) {
            LOGGER.error(title + ":" + message);
        } else {
            LOGGER.error(title + ":" + message, exception);
        }
        this.generateResponse(response, 500, message, title, redirect, redirectTitle);
    }

    protected String getRedirect(SlingHttpServletRequest request) {
        return request.getParameter("redirectTo");
    }

    protected void bindXssAPI(XSSAPI xSSAPI) {
        this.xssAPI = xSSAPI;
    }

    protected void unbindXssAPI(XSSAPI xSSAPI) {
        if (this.xssAPI == xSSAPI) {
            this.xssAPI = null;
        }
    }

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

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