Clarify ACR API
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / spi / ProvidedContent.java
index 3cf130a7c456d35e22c5d74e961bc1c2acc0ffd1..5e718223601e80330e6617afd2ca04607488ca09 100644 (file)
@@ -1,15 +1,18 @@
 package org.argeo.api.acr.spi;
 
+import java.util.Optional;
+
 import org.argeo.api.acr.Content;
 
 /** A {@link Content} implementation. */
 public interface ProvidedContent extends Content {
-       final static String ROOT_PATH = "/";
-
+       /** The related {@link ProvidedSession}. */
        ProvidedSession getSession();
 
+       /** The {@link ContentProvider} this {@link Content} belongs to. */
        ContentProvider getProvider();
 
+       /** Depth relative to the root of the repository. */
        int getDepth();
 
        /**
@@ -27,19 +30,23 @@ public interface ProvidedContent extends Content {
         */
        String getSessionLocalId();
 
+       /**
+        * The {@link Content} within the same {@link ContentProvider} which can be used
+        * to mount another {@link ContentProvider}.
+        */
        default ProvidedContent getMountPoint(String relativePath) {
                throw new UnsupportedOperationException("This content doe not support mount");
        }
 
-       default ProvidedContent getContent(String path) {
-               Content fileNode;
+       @Override
+       default Optional<Content> getContent(String path) {
+               String absolutePath;
                if (path.startsWith(ROOT_PATH)) {// absolute
-                       fileNode = getSession().get(path);
+                       absolutePath = path;
                } else {// relative
-                       String absolutePath = getPath() + '/' + path;
-                       fileNode = getSession().get(absolutePath);
+                       absolutePath = getPath() + PATH_SEPARATOR + path;
                }
-               return (ProvidedContent) fileNode;
+               return getSession().exists(absolutePath) ? Optional.of(getSession().get(absolutePath)) : Optional.empty();
        }
 
        /*
@@ -50,4 +57,8 @@ public interface ProvidedContent extends Content {
                return true;
        }
 
+       /** Whether the related session can open this content for edit. */
+       default boolean canEdit() {
+               return false;
+       }
 }