WCMUse.java 3.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  aQute.bnd.annotation.ConsumerType
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.api.components.Component
 *  com.day.cq.wcm.api.designer.Design
 *  com.day.cq.wcm.api.designer.Designer
 *  com.day.cq.wcm.api.designer.Style
 *  io.sightly.java.api.Use
 *  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.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.sightly;

import aQute.bnd.annotation.ConsumerType;
import com.adobe.cq.sightly.SightlyWCMMode;
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.designer.Design;
import com.day.cq.wcm.api.designer.Designer;
import com.day.cq.wcm.api.designer.Style;
import io.sightly.java.api.Use;
import javax.script.Bindings;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Deprecated
@ConsumerType
public abstract class WCMUse
implements Use {
    private static final Logger LOG = LoggerFactory.getLogger(WCMUse.class);
    private Bindings bindings;

    public 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 <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 SightlyWCMMode getWcmMode() {
        return this.get("wcmmode", SightlyWCMMode.class);
    }

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

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

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

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

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

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

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

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

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

    public ValueMap getInheritedProperties() {
        return this.get("inheritedPageProperties", ValueMap.class);
    }

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

    public ResourceResolver getResourceResolver() {
        return this.getRequest().getResourceResolver();
    }

    public SlingHttpServletRequest getRequest() {
        return this.get("request", SlingHttpServletRequest.class);
    }

    public SlingHttpServletResponse getResponse() {
        return this.get("response", SlingHttpServletResponse.class);
    }

    public SlingScriptHelper getSlingScriptHelper() {
        return this.get("sling", SlingScriptHelper.class);
    }
}