ColumnCtlPostProcessor.java
5.86 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.text.Text
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* 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.jcr.api.SlingRepository
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.ModificationType
* org.apache.sling.servlets.post.SlingPostProcessor
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.foundation.impl;
import com.day.cq.wcm.foundation.ParagraphSystem;
import com.day.text.Text;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
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.jcr.api.SlingRepository;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.ModificationType;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={SlingPostProcessor.class})
public class ColumnCtlPostProcessor
implements SlingPostProcessor {
private Logger log;
private static final String COLCTL_POSTPROCESSOR_SERVICE = "colctl-postprocessor-service";
@Reference
private SlingRepository repository;
private Session serviceSession;
public ColumnCtlPostProcessor() {
this.log = LoggerFactory.getLogger(this.getClass());
}
protected void activate(ComponentContext context) {
try {
this.serviceSession = this.repository.loginService("colctl-postprocessor-service", null);
}
catch (RepositoryException e) {
this.log.error("unable to initialize service session.");
}
}
protected void deactivate(ComponentContext componentContext) {
if (this.serviceSession != null) {
this.serviceSession.logout();
this.serviceSession = null;
}
}
public void process(SlingHttpServletRequest request, List<Modification> changes) throws Exception {
if (this.serviceSession == null) {
return;
}
Session session = (Session)request.getResourceResolver().adaptTo(Session.class);
String prt = request.getParameter("parentResourceType");
if (prt != null && prt.length() == 0) {
prt = null;
}
HashMap<String, String> parsys = new HashMap<String, String>();
block9 : for (Modification mod : changes) {
switch (mod.getType()) {
case DELETE: {
String colctrlProperty = null;
try {
String rt;
if (!this.serviceSession.nodeExists(mod.getSource()) || !(rt = this.serviceSession.getProperty(colctrlProperty = mod.getSource() + "/sling:resourceType").getString()).endsWith("/colctrl")) continue block9;
parsys.put(Text.getRelativeParent((String)mod.getSource(), (int)1), "");
}
catch (RepositoryException e) {}
break;
}
case ORDER:
case MOVE:
case COPY: {
break;
}
case MODIFY:
case CREATE: {
String path = mod.getSource();
if (!path.endsWith("/sling:resourceType")) break;
if (session.propertyExists(path)) {
String rt = session.getProperty(path).getString();
String parSysPath = Text.getRelativeParent((String)path, (int)2);
if (rt.endsWith("/colctrl")) {
parsys.put(parSysPath, Text.getRelativeParent((String)rt, (int)1));
break;
}
if (prt == null) continue block9;
try {
if (session.propertyExists(parSysPath + "/sling:resourceType")) continue block9;
parsys.put(parSysPath, prt);
prt = null;
}
catch (RepositoryException e) {}
break;
}
this.log.info("Could not find property {} in jcr session.", (Object)path);
}
}
}
for (String path : parsys.keySet()) {
String rt;
this.log.info("columns control modified - repairing parsys at {}", (Object)path);
if (!session.propertyExists(path + "/sling:resourceType") && (rt = (String)parsys.get(path)).length() > 0) {
session.getNode(path).setProperty("sling:resourceType", rt);
}
Resource res = request.getResourceResolver().getResource(path);
ParagraphSystem p = new ParagraphSystem(res);
p.repair();
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}