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();
/**
*/
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();
}
/*
return true;
}
+ /** Whether the related session can open this content for edit. */
+ default boolean canEdit() {
+ return false;
+ }
}