Get content path from JCR
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 23 Aug 2022 09:44:07 +0000 (11:44 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 23 Aug 2022 09:44:07 +0000 (11:44 +0200)
jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContent.java

index ad90b2df7880fd39b8ea1a7357c4df9d3889142e..b0326f48bca43a0b4bc7957b53a80a5e0254f74b 100644 (file)
@@ -178,6 +178,26 @@ public class JcrContent extends AbstractContent {
 
        }
 
+       @Override
+       public String getPath() {
+               try {
+                       // Note: it is important to to use the default way (recursing through parents),
+                       // since the session may not have access to parent nodes
+                       return ContentUtils.ROOT_SLASH + jcrWorkspace + getJcrNode().getPath();
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot get depth of " + getJcrNode(), e);
+               }
+       }
+
+       @Override
+       public int getDepth() {
+               try {
+                       return getJcrNode().getDepth() + 1;
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot get depth of " + getJcrNode(), e);
+               }
+       }
+
        @Override
        public Content getParent() {
                if (Jcr.isRoot(getJcrNode())) // root
@@ -353,7 +373,7 @@ public class JcrContent extends AbstractContent {
                        if (contentSession == null)
                                throw new IllegalArgumentException(
                                                "Cannot adapt " + node + " to content, because it was not loaded from a content session");
-                       return contentSession.get(CmsConstants.SYS_WORKSPACE + node.getPath());
+                       return contentSession.get(ContentUtils.SLASH + CmsConstants.SYS_WORKSPACE + node.getPath());
                } catch (RepositoryException e) {
                        throw new JcrException("Cannot adapt " + node + " to a content", e);
                }