AEMSightlyBindingsValuesProvider.java
3.07 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.scripting.SlingScriptHelper
* org.apache.sling.scripting.api.BindingsValuesProvider
*/
package com.adobe.cq.sightly.internal;
import com.adobe.cq.sightly.SightlyWCMMode;
import com.adobe.cq.sightly.WCMScriptHelper;
import com.adobe.cq.sightly.internal.WCMInheritanceValueMap;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import javax.script.Bindings;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.scripting.api.BindingsValuesProvider;
@Component
@Service
@Properties(value={@Property(name="service.vendor", value={"Adobe Systems"}), @Property(name="service.description", value={"AEM Sightly Bindings Values Provider"}), @Property(name="javax.script.name", value={"sightly"})})
public class AEMSightlyBindingsValuesProvider
implements BindingsValuesProvider {
public static final String PROP_WCM_SCRIPT_HELPER = "slyWcmHelper";
public void addBindings(Bindings bindings) {
SlingHttpServletRequest request = (SlingHttpServletRequest)bindings.get("request");
if (request != null) {
if (bindings.get("slyWcmHelper") == null) {
SlingScriptHelper sling = (SlingScriptHelper)bindings.get("sling");
bindings.put("slyWcmHelper", (Object)new WCMScriptHelper(sling));
}
if (bindings.get("wcmmode") == null) {
bindings.put("wcmmode", (Object)new SightlyWCMMode(request));
}
if (bindings.get("inheritedPageProperties") == null) {
Page currentPage = null;
if (bindings.get("currentPage") != null) {
currentPage = (Page)bindings.get("currentPage");
} else {
Resource resource = (Resource)bindings.get("resource");
PageManager pageManager = (PageManager)resource.getResourceResolver().adaptTo(PageManager.class);
if (pageManager != null) {
currentPage = pageManager.getContainingPage(resource);
}
}
if (currentPage != null) {
bindings.put("inheritedPageProperties", (Object)new WCMInheritanceValueMap(currentPage.getContentResource()));
}
}
}
}
}