TemplatedContainer.java 3.62 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.sightly.WCMUsePojo
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.Template
 *  com.day.cq.wcm.api.TemplateManager
 *  com.day.cq.wcm.api.components.ComponentContext
 *  com.day.cq.wcm.commons.WCMUtils
 *  javax.servlet.ServletRequest
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.foundation;

import com.adobe.cq.sightly.WCMUsePojo;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.api.TemplateManager;
import com.day.cq.wcm.api.components.ComponentContext;
import com.day.cq.wcm.commons.WCMUtils;
import java.util.List;
import javax.servlet.ServletRequest;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TemplatedContainer
extends WCMUsePojo {
    public static final Logger log = LoggerFactory.getLogger(TemplatedContainer.class);
    private Page page;
    private Template template;
    private ComponentContext componentContext;
    private TemplateManager templateManager;

    public TemplatedContainer(TemplateManager templateManager, ComponentContext componentContext) {
        this.componentContext = componentContext;
        if (componentContext == null) {
            throw new IllegalArgumentException("componentContext is null");
        }
        if (templateManager == null) {
            throw new IllegalArgumentException("templateManger is null");
        }
        this.templateManager = templateManager;
        this.page = componentContext.getPage();
        if (this.page == null) {
            throw new IllegalArgumentException("component's page is null");
        }
        this.template = this.page.getTemplate();
        if (this.template == null) {
            throw new IllegalArgumentException("page has no template assigned");
        }
        if (!this.template.hasStructureSupport()) {
            throw new IllegalArgumentException("template has no structure support");
        }
    }

    public void activate() throws Exception {
        this.componentContext = WCMUtils.getComponentContext((ServletRequest)this.getRequest());
        if (this.componentContext == null) {
            throw new IllegalArgumentException("componentContext is null");
        }
        this.templateManager = (TemplateManager)this.getResourceResolver().adaptTo(TemplateManager.class);
        if (this.templateManager == null) {
            throw new IllegalArgumentException("templateManger is null");
        }
        this.page = this.getResourcePage();
        if (this.page == null) {
            throw new IllegalArgumentException("component's page is null");
        }
        this.template = this.page.getTemplate();
        if (this.template == null) {
            throw new IllegalArgumentException("page has no template assigned");
        }
        if (!this.template.hasStructureSupport()) {
            log.warn("template has no structure support", (Object)this.componentContext.toString());
        }
    }

    public List<Resource> getStructureResources() {
        return this.templateManager.getStructureResources(this.componentContext);
    }

    public String getNewResourceType() {
        return "wcm/foundation/components/templatedcontainer/newcontainer";
    }

    public boolean hasStructureSupport() {
        return this.template.hasStructureSupport();
    }
}