WCMUsePojo.java 7.58 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  aQute.bnd.annotation.ConsumerType
 *  com.adobe.granite.xss.XSSAPI
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.api.components.Component
 *  com.day.cq.wcm.api.components.ComponentContext
 *  com.day.cq.wcm.api.components.EditContext
 *  com.day.cq.wcm.api.designer.Design
 *  com.day.cq.wcm.api.designer.Designer
 *  com.day.cq.wcm.api.designer.Style
 *  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.ValueMap
 *  org.apache.sling.api.scripting.SlingScriptHelper
 *  org.apache.sling.scripting.sightly.pojo.Use
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.sightly;

import aQute.bnd.annotation.ConsumerType;
import com.adobe.cq.sightly.SightlyWCMMode;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.components.Component;
import com.day.cq.wcm.api.components.ComponentContext;
import com.day.cq.wcm.api.components.EditContext;
import com.day.cq.wcm.api.designer.Design;
import com.day.cq.wcm.api.designer.Designer;
import com.day.cq.wcm.api.designer.Style;
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.ValueMap;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.scripting.sightly.pojo.Use;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.script.Bindings;

@ConsumerType
public abstract class WCMUsePojo
implements Use {
    private static final Logger LOG = LoggerFactory.getLogger(WCMUsePojo.class);
    private Bindings bindings;
    private SightlyWCMMode wcmMode;
    private PageManager pageManager;
    private Page currentPage;
    private Page resourcePage;
    private ValueMap pageProperties;
    private ValueMap properties;
    private Designer designer;
    private Design currentDesign;
    private Style currentStyle;
    private Component component;
    private ValueMap inheritedProperties;
    private Resource resource;
    private ResourceResolver resourceResolver;
    private SlingHttpServletRequest slingHttpServletRequest;
    private SlingHttpServletResponse slingHttpServletResponse;
    private SlingScriptHelper slingScriptHelper;
    private ComponentContext componentContext;
    private EditContext editContext;
    private Design resourceDesign;
    private XSSAPI xssapi;

    public final void init(Bindings scriptBindings) {
        this.bindings = scriptBindings;
        try {
            this.activate();
        }
        catch (Exception e) {
            LOG.error("Failed to activate Use class", (Throwable)e);
        }
    }

    public abstract void activate() throws Exception;

    public final <T> T get(String name, Class<T> type) {
        Object obj = this.bindings.get(name);
        try {
            return type.cast(obj);
        }
        catch (ClassCastException e) {
            LOG.error("Failed to cast value", (Throwable)e);
            return null;
        }
    }

    public final SightlyWCMMode getWcmMode() {
        if (this.wcmMode == null) {
            this.wcmMode = this.get("wcmmode", SightlyWCMMode.class);
        }
        return this.wcmMode;
    }

    public final PageManager getPageManager() {
        if (this.pageManager == null) {
            this.pageManager = this.get("pageManager", PageManager.class);
        }
        return this.pageManager;
    }

    public final Page getCurrentPage() {
        if (this.currentPage == null) {
            this.currentPage = this.get("currentPage", Page.class);
        }
        return this.currentPage;
    }

    public final Page getResourcePage() {
        if (this.resourcePage == null) {
            this.resourcePage = this.get("resourcePage", Page.class);
        }
        return this.resourcePage;
    }

    public final ValueMap getPageProperties() {
        if (this.pageProperties == null) {
            this.pageProperties = this.get("pageProperties", ValueMap.class);
        }
        return this.pageProperties;
    }

    public final ValueMap getProperties() {
        if (this.properties == null) {
            this.properties = this.get("properties", ValueMap.class);
        }
        return this.properties;
    }

    public final Designer getDesigner() {
        if (this.designer == null) {
            this.designer = this.get("designer", Designer.class);
        }
        return this.designer;
    }

    public final Design getCurrentDesign() {
        if (this.currentDesign == null) {
            this.currentDesign = this.get("currentDesign", Design.class);
        }
        return this.currentDesign;
    }

    public final Style getCurrentStyle() {
        if (this.currentStyle == null) {
            this.currentStyle = this.get("currentStyle", Style.class);
        }
        return this.currentStyle;
    }

    public final Component getComponent() {
        if (this.component == null) {
            this.component = this.get("component", Component.class);
        }
        return this.component;
    }

    public final ValueMap getInheritedProperties() {
        if (this.inheritedProperties == null) {
            this.inheritedProperties = this.get("inheritedPageProperties", ValueMap.class);
        }
        return this.inheritedProperties;
    }

    public final Resource getResource() {
        if (this.resource == null) {
            this.resource = this.get("resource", Resource.class);
        }
        return this.resource;
    }

    public final ResourceResolver getResourceResolver() {
        if (this.resourceResolver == null) {
            this.resourceResolver = this.getRequest().getResourceResolver();
        }
        return this.resourceResolver;
    }

    public final SlingHttpServletRequest getRequest() {
        if (this.slingHttpServletRequest == null) {
            this.slingHttpServletRequest = this.get("request", SlingHttpServletRequest.class);
        }
        return this.slingHttpServletRequest;
    }

    public final SlingHttpServletResponse getResponse() {
        if (this.slingHttpServletResponse == null) {
            this.slingHttpServletResponse = this.get("response", SlingHttpServletResponse.class);
        }
        return this.slingHttpServletResponse;
    }

    public final SlingScriptHelper getSlingScriptHelper() {
        if (this.slingScriptHelper == null) {
            this.slingScriptHelper = this.get("sling", SlingScriptHelper.class);
        }
        return this.slingScriptHelper;
    }

    public final ComponentContext getComponentContext() {
        if (this.componentContext == null) {
            this.componentContext = this.get("componentContext", ComponentContext.class);
        }
        return this.componentContext;
    }

    public final EditContext getEditContext() {
        if (this.editContext == null) {
            this.editContext = this.get("editContext", EditContext.class);
        }
        return this.editContext;
    }

    public final Design getResourceDesign() {
        if (this.resourceDesign == null) {
            this.resourceDesign = this.get("resourceDesign", Design.class);
        }
        return this.resourceDesign;
    }

    public final XSSAPI getXSSAPI() {
        if (this.xssapi == null) {
            this.xssapi = this.get("xssAPI", XSSAPI.class);
        }
        return this.xssapi;
    }
}