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