TemplatedContainer.java
3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* 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();
}
}