-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeUtils.groovy
More file actions
64 lines (52 loc) · 1.97 KB
/
Copy pathnodeUtils.groovy
File metadata and controls
64 lines (52 loc) · 1.97 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import org.apache.jackrabbit.oak.spi.commit.CommitInfo
import org.apache.jackrabbit.oak.spi.commit.EmptyHook
import org.apache.jackrabbit.oak.spi.state.NodeStore
import org.apache.jackrabbit.oak.commons.PathUtils
def rmNode(def session, String path) {
println "Removing node ${path}"
NodeStore ns = session.store
def nb = ns.root.builder()
def aBuilder = nb
for(p in PathUtils.elements(path)) { aBuilder = aBuilder.getChildNode(p) }
if(aBuilder.exists()) {
rm = aBuilder.remove()
ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY)
return rm
} else {
println "Node ${path} doesn't exist"
return false
}
}
def renameNode(def session, String path, String newName) {
println "Renaming node from ${path} to ${newName}"
NodeStore ns = session.store
def nb = ns.root.builder()
def aBuilder = nb
def parentNodeBuilder = nb
for(p in PathUtils.elements(path)) { parentNodeBuilder = aBuilder; aBuilder = aBuilder.getChildNode(p); }
if(aBuilder.exists()) {
rn = aBuilder.moveTo(parentNodeBuilder, newName);
ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY)
return rn
} else {
println "Node ${path} doesn't exist"
return false
}
}
def addChildNode(def session, String path, String newChildNodeName, String primaryType) {
println "Adding node ${path}/${newChildNodeName}"
NodeStore ns = session.store
def nb = ns.root.builder()
def aBuilder = nb
def parentNodeBuilder = nb
for(p in PathUtils.elements(path)) { aBuilder = aBuilder.getChildNode(p); }
if(aBuilder.exists()) {
newNodeBuilder = aBuilder.setChildNode(newChildNodeName);
newNodeBuilder.setProperty("jcr:primaryType", primaryType, org.apache.jackrabbit.oak.api.Type.NAME,);
ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY)
return newNodeBuilder
} else {
println "Parent node ${path} doesn't exist"
return false
}
}