Skip to content

Instantly share code, notes, and snippets.

@stillalex
Created November 21, 2014 19:16
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stillalex/43c49af065e3dd1fd5bf to your computer and use it in GitHub Desktop.
Save stillalex/43c49af065e3dd1fd5bf to your computer and use it in GitHub Desktop.
Groovy script to remove a node at a given path
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
}
}
@stillalex
Copy link
Author

:load https://gist.githubusercontent.com/alexparvulescu/43c49af065e3dd1fd5bf/raw/9e726a59f75b46e7b474f7ac763b0888d5a3f0c3/rmNode.groovy
rmNode(session, "/path/to/node")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment