ConfigurationPostProcessor.java
4.09 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Component
* 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.resource.ResourceUtil
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.ModificationType
* org.apache.sling.servlets.post.SlingPostProcessor
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.webservicesupport.impl;
import java.util.HashSet;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
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.resource.ResourceUtil;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.ModificationType;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class ConfigurationPostProcessor
implements SlingPostProcessor {
protected final Logger logger;
private final String PAGE_MARKER = "/jcr:content/";
private final String RP_CANCELINHERITANCE = ":cancelInheritance";
public ConfigurationPostProcessor() {
this.logger = LoggerFactory.getLogger((String)this.getClass().getName());
this.PAGE_MARKER = "/jcr:content/";
this.RP_CANCELINHERITANCE = ":cancelInheritance";
}
public void process(SlingHttpServletRequest request, List<Modification> changes) throws Exception {
HashSet<String> fixPaths = new HashSet<String>();
for (Modification mod : changes) {
switch (mod.getType()) {
case ORDER:
case MOVE:
case COPY: {
break;
}
case MODIFY: {
int pageEndPos = mod.getSource().indexOf("/jcr:content/");
if (pageEndPos == -1) break;
String pagePath = mod.getSource().substring(0, pageEndPos);
fixPaths.add(pagePath);
break;
}
}
}
ResourceResolver resolver = request.getResourceResolver();
for (String pagePath : fixPaths) {
String contentPath = pagePath + '/' + "jcr:content";
this.logger.debug("Checking request {} for cloud service configuration", (Object)request);
Resource contentResource = resolver.getResource(contentPath);
if (contentResource == null) continue;
this.fixStructure(request, contentResource);
}
}
private void fixStructure(SlingHttpServletRequest request, Resource resource) {
boolean cancelInheritance = Boolean.valueOf(request.getParameter(":cancelInheritance"));
if (cancelInheritance && !this.hasServiceConfigurations(request) && ResourceUtil.isA((Resource)resource.getParent(), (String)"cq:Page")) {
try {
Node node = (Node)resource.adaptTo(Node.class);
node.setProperty("cq:cloudserviceconfigs", new String[0]);
this.logger.debug("Adding empty {} property to page {}", (Object)"cq:cloudserviceconfigs", (Object)resource.getPath());
}
catch (RepositoryException e) {
this.logger.error("Could not add empty property {}", (Object)"cq:cloudserviceconfigs");
}
}
}
private boolean hasServiceConfigurations(SlingHttpServletRequest request) {
String[] parameters;
for (String value : parameters = request.getParameterValues("./cq:cloudserviceconfigs")) {
if ("".equals(value.trim())) continue;
return true;
}
return false;
}
}