ScriptInputProcessor.java
3.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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.scripting.SlingBindings
* org.apache.sling.api.scripting.SlingScript
*/
package com.adobe.aemfd.watchfolder.script;
import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.service.api.ProcessorContext;
import com.adobe.aemfd.watchfolder.util.AbstractSyncInputProcessor;
import com.adobe.aemfd.watchfolder.util.JcrUtil;
import com.adobe.aemfd.watchfolder.util.SessionUtil;
import java.io.File;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScript;
@Component(immediate=1)
@Service(value={ScriptInputProcessor.class})
public class ScriptInputProcessor
extends AbstractSyncInputProcessor {
@Reference
private SessionUtil sessionUtil;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Activate
public void activate() throws Exception {
Session s = this.sessionUtil.getServiceSession(null);
try {
JcrUtil.makeSubDirIfRequired(s, "scripts", "sling:Folder");
}
finally {
s.logout();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void doProcess(String jobId, WatchFolderConfiguration config, File source, ProcessorContext ctxt) throws Exception {
ResourceResolver rr = this.sessionUtil.getServiceResolver("scripts");
try {
SlingBindings sb = new SlingBindings();
sb.put((Object)"processorContext", (Object)ctxt);
SlingScript script = null;
Resource r = rr.getResource(config.getInputProcessorId());
if (r != null) {
script = (SlingScript)r.adaptTo(SlingScript.class);
}
if (script == null) {
throw new Exception("Failed to resolve script at path " + config.getInputProcessorId() + ". Verify that the resource exists, is an executable script and is accessible to the" + " service-user used for watch-folder script execution.");
}
script.eval(sb);
}
finally {
rr.close();
}
}
protected void bindSessionUtil(SessionUtil sessionUtil) {
this.sessionUtil = sessionUtil;
}
protected void unbindSessionUtil(SessionUtil sessionUtil) {
if (this.sessionUtil == sessionUtil) {
this.sessionUtil = null;
}
}
}