]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ProvidedContent.java
f1e5aaaa80f24af4dce505a935b342645d9910c8
[lgpl/argeo-commons.git] / ProvidedContent.java
1 package org.argeo.api.acr.spi;
2
3 import java.util.Optional;
4
5 import org.argeo.api.acr.Content;
6
7 /** A {@link Content} implementation. */
8 public interface ProvidedContent extends Content {
9 /** The related {@link ProvidedSession}. */
10 ProvidedSession getSession();
11
12 /** The {@link ContentProvider} this {@link Content} belongs to. */
13 ContentProvider getProvider();
14
15 /** Depth relative to the root of the repository. */
16 int getDepth();
17
18 /**
19 * Whether this is the root node of the related repository. Default checks
20 * whether <code>{@link #getDepth()} == 0</code>, but it can be optimised by
21 * implementations.
22 */
23 default boolean isRoot() {
24 return getDepth() == 0;
25 }
26
27 /**
28 * An opaque ID which is guaranteed to uniquely identify this content within the
29 * session return by {@link #getSession()}. Typically used for UI.
30 */
31 String getSessionLocalId();
32
33 /**
34 * The {@link Content} within the same {@link ContentProvider} which can be used
35 * to mount another {@link ContentProvider}.
36 */
37 default ProvidedContent getMountPoint(String relativePath) {
38 throw new UnsupportedOperationException("This content doe not support mount");
39 }
40
41 @Override
42 default Optional<Content> getContent(String path) {
43 String absolutePath;
44 if (path.startsWith(Content.ROOT_PATH)) {// absolute
45 absolutePath = path;
46 } else {// relative
47 absolutePath = getPath() + '/' + path;
48 }
49 return getSession().exists(absolutePath) ? Optional.of(getSession().get(absolutePath)) : Optional.empty();
50 }
51
52 /*
53 * ACCESS
54 */
55 /** Whether the session has the right to access the parent. */
56 default boolean isParentAccessible() {
57 return true;
58 }
59
60 /** Whether the related session can open this content for edit. */
61 default boolean canEdit() {
62 return false;
63 }
64 }