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