Skip to content

Instantly share code, notes, and snippets.

@alexkli
Last active June 25, 2024 16:30
Show Gist options
  • Save alexkli/fe955b1d651e68b2a01db24be31c844f to your computer and use it in GitHub Desktop.
Save alexkli/fe955b1d651e68b2a01db24be31c844f to your computer and use it in GitHub Desktop.
Groovy script for displaying hidden Oak content structures
import org.apache.sling.jcr.api.SlingRepository
import javax.jcr.Session
import javax.jcr.Node
import javax.jcr.Property
SlingRepository repo = sling.getService(SlingRepository.class)
Session session = null
InputStream is = null
try {
session = repo.loginAdministrative(null);
// get oak ContentSession via reflection
def obj1 = java.lang.reflect.Proxy.getInvocationHandler(session).delegatee;
def field = obj1.class.superclass.getDeclaredField("sd");
field.setAccessible(true);
def obj2 = field.get(obj1);
field = obj2.class.superclass.getDeclaredField("contentSession");
field.setAccessible(true);
def cs = field.get(obj2);
out.println(cs.dump());
def root = cs.latestRoot;
// go wild here
// Note: hidden nodes (prefixed with ":") do not appear in getChildren()
// instead you have to know their path
def t = root.getTree("/oak:index/nodetype/:index");
out.println(t.exists());
t.properties.each { kid ->
out.println(kid);
}
out.println(t.getChildrenCount(1000));
t.children.each { kid ->
out.println(kid);
}
} finally {
is?.close()
session?.logout()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment