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.importexport.DataTransporter;
37 import org.apache.commons.lang.StringUtils;
38
39
40
41
42
43
44 public class BootstrapConditionally extends NodeExistsDelegateTask {
45
46
47
48
49 public BootstrapConditionally(String taskName, String taskDescription, String resourceToBootstrap) {
50 super(taskName, taskDescription, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap), null, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap));
51 }
52
53
54
55
56 public BootstrapConditionally(String taskName, String taskDescription, String resourceToBootstrap, Task ifNodeExists) {
57 super(taskName, taskDescription, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap), ifNodeExists, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap));
58 }
59
60
61
62
63 public BootstrapConditionally(String taskName, String taskDescription, String repositoryName, String pathToCheck, String resourceToBootstrap, Task ifNodeExists) {
64 super(taskName, taskDescription, repositoryName, pathToCheck, ifNodeExists, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap));
65 }
66
67
68 private static String determineRepository(String filename) {
69 return StringUtils.substringBefore(cleanupFilename(filename), ".");
70 }
71
72 private static String determinePath(String filename) {
73 String withoutExtensionAndRepository = StringUtils.substringAfter(cleanupFilename(filename), ".");
74 String path = StringUtils.replace(withoutExtensionAndRepository, ".", "/");
75 return (StringUtils.isEmpty(path) ? "/" : "/" + path);
76 }
77
78 private static String cleanupFilename(String filename) {
79 filename = StringUtils.replace(filename, "\\", "/");
80 filename = StringUtils.substringAfterLast(filename, "/");
81 filename = StringUtils.substringBeforeLast(filename, ".");
82
83 return StringUtils.removeEnd(filename, DataTransporter.XML);
84 }
85 }