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.cms.core.Content.ContentFilter;
39 import info.magnolia.cms.util.ContentUtil;
40 import info.magnolia.module.InstallContext;
41
42 import java.util.Collection;
43
44 import javax.jcr.RepositoryException;
45
46
47
48
49
50
51 public abstract class AllChildrenNodesOperation extends AbstractRepositoryTask {
52 private final String repositoryName;
53 private final String parentNodePath;
54 private final ContentFilter filter;
55
56 public AllChildrenNodesOperation(String name, String description, String repositoryName, String parentNodePath) {
57 this(name, description, repositoryName, parentNodePath, ContentUtil.EXCLUDE_META_DATA_CONTENT_FILTER);
58 }
59
60 public AllChildrenNodesOperation(String name, String description, String repositoryName, String parentNodePath, ContentFilter filter) {
61 super(name, description);
62 this.repositoryName = repositoryName;
63 this.parentNodePath = parentNodePath;
64 this.filter = filter;
65 }
66
67 protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {
68 final Content parentNode = getParentNode(ctx);
69 final Collection<Content> childNodes = parentNode.getChildren(filter);
70 for (Content node : childNodes) {
71 operateOnChildNode(node, ctx);
72 }
73 }
74
75 protected Content getParentNode(InstallContext ctx) throws RepositoryException, TaskExecutionException {
76 final HierarchyManager hm = ctx.getHierarchyManager(repositoryName);
77 return hm.getContent(parentNodePath);
78 }
79
80 protected abstract void operateOnChildNode(Content node, InstallContext ctx) throws RepositoryException, TaskExecutionException;
81 }