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 info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.HierarchyManager;
38 import info.magnolia.module.InstallContext;
39
40 import javax.jcr.RepositoryException;
41
42
43
44
45 public abstract class NodeCheckDelegateTask extends ConditionalDelegateTask {
46 protected final String workspaceName;
47 protected final String nodePath;
48 protected final String propertyName;
49
50 public NodeCheckDelegateTask(String taskName, String taskDescription, String workspaceName, String nodePath, String propertyName, Task ifTrue, Task ifFalse) {
51 super(taskName, taskDescription, ifTrue, ifFalse);
52 this.workspaceName = workspaceName;
53 this.nodePath = nodePath;
54 this.propertyName = propertyName;
55 }
56
57 @Override
58 protected boolean condition(InstallContext ctx) throws TaskExecutionException {
59 final HierarchyManager hm = ctx.getHierarchyManager(workspaceName);
60 if (!hm.isExist(nodePath)) {
61 return false;
62 }
63
64 try {
65 final Content node = hm.getContent(nodePath);
66 return checkNode(node, ctx);
67 } catch (RepositoryException e) {
68 throw new TaskExecutionException("Can't check for property " + propertyName + " in " + nodePath + ".", e);
69 }
70 }
71
72 protected abstract boolean checkNode(Content node, InstallContext ctx) throws RepositoryException, TaskExecutionException;
73 }