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.blossom.setup;
35
36 import javax.jcr.Property;
37 import javax.jcr.RepositoryException;
38 import javax.jcr.Session;
39
40 import org.apache.commons.lang.ArrayUtils;
41
42 import info.magnolia.module.InstallContext;
43 import info.magnolia.module.delta.AbstractTask;
44 import info.magnolia.module.delta.TaskExecutionException;
45
46
47
48
49
50
51 public class MultiCheckAndModifyPropertyValueTask extends AbstractTask {
52
53 private final String nodePath;
54 private final String propertyName;
55 private final String[] expectedValues;
56 private final String newValue;
57
58 public MultiCheckAndModifyPropertyValueTask(String name, String description, String nodePath, String propertyName, String[] expectedValues, String newValue) {
59 super(name, description);
60 this.nodePath = nodePath;
61 this.propertyName = propertyName;
62 this.newValue = newValue;
63 this.expectedValues = expectedValues;
64 }
65
66 @Override
67 public void execute(InstallContext installContext) throws TaskExecutionException {
68 String propertyPath = nodePath + "/" + propertyName;
69 try {
70 Session session = installContext.getConfigJCRSession();
71 Property property = session.getProperty(propertyPath);
72 if (ArrayUtils.contains(expectedValues, property.getString())) {
73 property.setValue(newValue);
74 }
75 } catch (RepositoryException e) {
76 installContext.error("Could not check property " + propertyPath + ", should be set to " + newValue, e);
77 }
78 }
79 }