Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
import java.util.List
def setProperty(def session, def nodepath, def propertyName, def propertyValue, def isMulti) {
NodeStore ns =
def rnb = ns.root.builder()
def nb = rnb;
String path;
if (PathUtils.isAbsolute(nodepath)) {
path = nodepath;
} else {
path = PathUtils.concat(session.getWorkingPath(), nodepath);
List<String> elements = Lists.newArrayList();
PathUtils.elements(path).each{String element ->
if (PathUtils.denotesParent(element)) {
if (!elements.isEmpty()) {
elements.remove(elements.size() - 1);
} else if (!PathUtils.denotesCurrent(element)) {
elements.each {
if(it.size() > 0) {
nb = nb.getChildNode(it)
println "Setting property ${propertyName}: ${propertyValue} on node ${nodepath}"
if(isMulti) {
nb.setProperty(propertyName, Lists.newArrayList(propertyValue), org.apache.jackrabbit.oak.api.Type.STRINGS)
} else {
nb.setProperty(propertyName, propertyValue)
ns.merge(rnb, EmptyHook.INSTANCE, CommitInfo.EMPTY)
println "Done"
  1. Download (or build oak-run 1.1.x version)
  2. Stop all AEM instances
  3. Upload the oak-run 1.1 version to the AEM server if using TarMK or MongoDB server (if using MongoMK)
  4. Run this command to start the oak console
  • on TarMK:
   java -jar target/oak-run.jar console --quiet /path/to/segmentstore
  • For MongoMK run this:
   java -jar oak-run.jar console mongodb://localhost/aem-author
  1. Run these commands to set a property on a node
setProperty(session, "/path", "propName", "propValue", false)

To build latest oak version:

   $ svn checkout
   $ cd oak-run
   $ mvn clean install

Note: use at least maven 3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.