javaaemjcr

Java JCR/Adobe AEM: How do I access the node directly without using queries?


as above. I've looked at "getNode" (part of javax.jcr.node) and it requires a relative path. I'm hoping there's a function that I haven't seen yet that accepts an absulate path.

Code example:

Node node = Node.getNodeByAbsulotePath("/content/my-folder-here/my-node-here");

Solution

  • You need a javax.jcr.Session object, to access the repository. It has the wanted session.getNode(absPath) method.

    Every Node-object has a backlink to its session, therefore you can either traverse forward the node-structure via node.getNode(relPath) or just get the session via node.getSession().

    see:

    https://docs.adobe.com/content/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Session.html#getNode(java.lang.String)

    or the JackrabbitSession:

    https://jackrabbit.apache.org/api/2.12/org/apache/jackrabbit/api/JackrabbitSession.html