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.setup;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.HierarchyManager;
38 import info.magnolia.cms.core.ItemType;
39 import info.magnolia.cms.util.ContentUtil;
40 import info.magnolia.module.InstallContext;
41 import info.magnolia.module.delta.AbstractRepositoryTask;
42 import info.magnolia.module.delta.Task;
43 import info.magnolia.module.delta.TaskExecutionException;
44
45 import javax.jcr.RepositoryException;
46
47
48
49
50
51
52
53
54 public class AddFilterBypassTask extends AbstractRepositoryTask implements Task {
55
56 private static final String BYPASSES_NODE = "bypasses";
57
58 private final String filterPath;
59 private final String bypassName;
60 private final Class bypassClass;
61 private final String bypassPattern;
62
63 public AddFilterBypassTask(String filterPath, String bypassName, Class bypassClass, String bypassPattern) {
64 super("Filters", "Adds a bypass with pattern '" + bypassPattern + "' to the filter " + filterPath + "");
65 this.filterPath = filterPath;
66 this.bypassName = bypassName;
67 this.bypassClass = bypassClass;
68 this.bypassPattern = bypassPattern;
69 }
70
71 protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
72 final HierarchyManager hm = installContext.getConfigHierarchyManager();
73 final Content filter = hm.getContent(filterPath);
74 final Content bypasses = ContentUtil.getOrCreateContent(filter, BYPASSES_NODE, ItemType.CONTENTNODE);
75
76 final Content newBypass = ContentUtil.getOrCreateContent(bypasses, bypassName, ItemType.CONTENTNODE);
77 newBypass.createNodeData("class", bypassClass.getName());
78 newBypass.createNodeData("pattern", bypassPattern);
79 }
80 }