ContentPolicyStatus.java
6.1 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.components.Component
* com.day.cq.wcm.api.components.ComponentContext
* com.day.cq.wcm.api.policies.ContentPolicyManager
* javax.servlet.http.HttpServletRequest
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.SyntheticResource
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.wcm.core.impl;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.components.Component;
import com.day.cq.wcm.api.components.ComponentContext;
import com.day.cq.wcm.api.policies.ContentPolicyManager;
import com.day.cq.wcm.core.impl.TemplateUtils;
import com.day.cq.wcm.core.impl.policies.ContentPolicyManagerImpl;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.SyntheticResource;
import org.apache.sling.api.resource.ValueMap;
public class ContentPolicyStatus {
public final boolean usePolicy;
public final boolean isPageUsingAuthoredTemplate;
public final String policyDirectoryPath;
public final String policyMappingPath;
public final String policyPath;
public final String policyNodeName;
public final boolean hasPolicyMapping;
public final boolean isAllowedComponent;
private String resourceType;
public String allowedComponentDesignDialogPath;
private ContentPolicyStatus(HttpServletRequest request, ComponentContext context, boolean usePolicy, boolean isPageUsingAuthoredTemplate, String policyMappingPath, String policyPath, String policyDirectoryPath, String policyNodeName, boolean hasPolicyMapping, boolean isAllowedComponent) {
this.usePolicy = usePolicy;
this.isPageUsingAuthoredTemplate = isPageUsingAuthoredTemplate;
this.policyMappingPath = policyMappingPath;
this.policyPath = policyPath;
this.policyDirectoryPath = policyDirectoryPath;
this.policyNodeName = policyNodeName;
this.hasPolicyMapping = hasPolicyMapping;
this.isAllowedComponent = isAllowedComponent;
Resource resource = context.getResource();
ValueMap resourceVM = resource.getValueMap();
if (resourceVM != null && resourceVM.containsKey((Object)"sling:resourceType")) {
this.resourceType = (String)resourceVM.get("sling:resourceType", String.class);
}
if (this.isAllowedComponent) {
ResourceResolver resolver = resource.getResourceResolver();
String resourcePath = context.getResource().getPath();
if (!StringUtils.isEmpty((CharSequence)resourcePath)) {
Component component;
Resource dialog;
Resource targetResource = (Resource)request.getAttribute(resourcePath);
this.resourceType = TemplateUtils.getRelativePath(targetResource);
if (targetResource != null && (dialog = TemplateUtils.getDialog(resolver, component = (Component)targetResource.adaptTo(Component.class), "design_dialog")) != null) {
this.allowedComponentDesignDialogPath = dialog.getPath();
}
}
}
}
public static ContentPolicyStatus buildContentPolicyStatus(HttpServletRequest request, ComponentContext componentContext) {
Page page = componentContext.getPage();
boolean usePolicy = false;
boolean hasPolicyMapping = false;
boolean isAllowedComponent = false;
boolean isPageUsingAuthoredTemplate = TemplateUtils.isPageAuthoredTemplated(page) && !TemplateUtils.isTemplateStructureComponent(componentContext);
boolean isContextAuthoredTemplate = TemplateUtils.isPageOfAuthoredTemplate(page) || TemplateUtils.isTemplateStructureComponent(componentContext);
String policyMappingPath = null;
String policyDirectoryPath = null;
String policyPath = null;
String policyNodeName = null;
if (isPageUsingAuthoredTemplate || isContextAuthoredTemplate) {
Resource policyResource;
Resource resource = componentContext.getResource();
usePolicy = true;
ContentPolicyManagerImpl contentPolicyManager = (ContentPolicyManagerImpl)resource.getResourceResolver().adaptTo(ContentPolicyManager.class);
policyMappingPath = contentPolicyManager.buildPolicyMappingPath(componentContext.getResource());
hasPolicyMapping = TemplateUtils.hasPolicyMapping(resource.getResourceResolver(), policyMappingPath);
policyDirectoryPath = ContentPolicyManagerImpl.getPolicyLocation(resource);
if (resource instanceof SyntheticResource) {
Resource parent = null;
String parentPath = resource.getPath();
ResourceResolver resolver = resource.getResourceResolver();
while (!StringUtils.isEmpty((CharSequence)parentPath) && parentPath.indexOf("/") > -1 && parent == null) {
parentPath = parentPath.substring(0, parentPath.lastIndexOf("/"));
parent = resolver.getResource(parentPath);
}
if (parent != null) {
ValueMap parentValueMap = parent.getValueMap();
boolean bl = isAllowedComponent = parentValueMap.containsKey((Object)"editable") && (Boolean)parentValueMap.get("editable", Boolean.class) != false;
}
}
if ((policyResource = TemplateUtils.getPolicyResource(resource.getResourceResolver(), policyMappingPath)) != null) {
policyPath = policyResource.getPath();
policyNodeName = policyResource.getName();
}
}
return new ContentPolicyStatus(request, componentContext, usePolicy, isPageUsingAuthoredTemplate, policyMappingPath, policyPath, policyDirectoryPath, policyNodeName, hasPolicyMapping, isAllowedComponent);
}
public String getResourceType() {
return this.resourceType;
}
}