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 package info.magnolia.module.delta;
35
36 import static org.apache.commons.lang3.StringUtils.prependIfMissing;
37
38 import info.magnolia.module.InstallContext;
39
40 import javax.jcr.Node;
41 import javax.jcr.RepositoryException;
42 import javax.jcr.Session;
43
44
45
46
47 public abstract class CheckNodeDelegateTask extends ConditionalDelegateTask {
48 protected final String workspaceName;
49 protected final String nodePath;
50 protected final String propertyName;
51
52 public CheckNodeDelegateTask(String taskName, String taskDescription, String workspaceName, String nodePath, String propertyName, Taskef="../../../../info/magnolia/module/delta/Task.html#Task">Task ifTrue, Task ifFalse) {
53 super(taskName, taskDescription, ifTrue, ifFalse);
54 this.workspaceName = workspaceName;
55 this.nodePath = nodePath;
56 this.propertyName = propertyName;
57 }
58
59 @Override
60 protected boolean condition(InstallContext ctx) throws TaskExecutionException {
61 try {
62 final Session session = ctx.getJCRSession(workspaceName);
63 if (!session.nodeExists(prependIfMissing(nodePath, "/"))) {
64 return false;
65 }
66
67 final Node node = session.getNode(nodePath);
68 return checkNode(node, ctx);
69 } catch (RepositoryException e) {
70 throw new TaskExecutionException("Can't check for property " + propertyName + " in " + nodePath + ".", e);
71 }
72 }
73
74 protected abstract boolean checkNode(Node node, InstallContext ctx) throws RepositoryException, TaskExecutionException;
75 }