X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2Fspi%2FProvidedContent.java;h=f1e5aaaa80f24af4dce505a935b342645d9910c8;hb=5724ab347ddfba8f2b21cdcc2fa0b8e1e2b4e527;hp=e2807c0efd19e746c7a9ab41a2971e36c1fe55e9;hpb=d2bca81ff63496bf1d879f4cbcd6a531f598e69c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/spi/ProvidedContent.java b/org.argeo.api.acr/src/org/argeo/api/acr/spi/ProvidedContent.java index e2807c0ef..f1e5aaaa8 100644 --- a/org.argeo.api.acr/src/org/argeo/api/acr/spi/ProvidedContent.java +++ b/org.argeo.api.acr/src/org/argeo/api/acr/spi/ProvidedContent.java @@ -1,35 +1,64 @@ 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(); + /** + * Whether this is the root node of the related repository. Default checks + * whether {@link #getDepth()} == 0, but it can be optimised by + * implementations. + */ + default boolean isRoot() { + return getDepth() == 0; + } + /** * An opaque ID which is guaranteed to uniquely identify this content within the * session return by {@link #getSession()}. Typically used for UI. */ 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; - if (path.startsWith(ROOT_PATH)) {// absolute - fileNode = getSession().get(path); + @Override + default Optional getContent(String path) { + String absolutePath; + if (path.startsWith(Content.ROOT_PATH)) {// absolute + absolutePath = path; } else {// relative - String absolutePath = getPath() + '/' + path; - fileNode = getSession().get(absolutePath); + absolutePath = getPath() + '/' + path; } - return (ProvidedContent) fileNode; + return getSession().exists(absolutePath) ? Optional.of(getSession().get(absolutePath)) : Optional.empty(); + } + + /* + * ACCESS + */ + /** Whether the session has the right to access the parent. */ + default boolean isParentAccessible() { + return true; + } + + /** Whether the related session can open this content for edit. */ + default boolean canEdit() { + return false; } }