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 public class AddFilterBypassTask extends AbstractRepositoryTask implements Task {
54
55 private static final String BYPASSES_NODE = "bypasses";
56
57 private final String filterPath;
58 private final String bypassName;
59 private final Class bypassClass;
60 private final String bypassPattern;
61
62 public AddFilterBypassTask(String filterPath, String bypassName, Class bypassClass, String bypassPattern) {
63 super("Filters", "Adds a bypass with pattern '" + bypassPattern + "' to the filter " + filterPath + "");
64 this.filterPath = filterPath;
65 this.bypassName = bypassName;
66 this.bypassClass = bypassClass;
67 this.bypassPattern = bypassPattern;
68 }
69
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 }