X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2Fspi%2FContentProvider.java;h=8b59f2fa23120784660d1c4a6e4defd3b9f44754;hb=54098df1bc3ba263dd1e3290aafa880d54d96805;hp=25b9be5c2081b924b7f08a0d4f0ce72b8a5e1559;hpb=6d463a65d04d641c94a493579a75f8015c82097d;p=lgpl%2Fargeo-commons.git
diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/spi/ContentProvider.java b/org.argeo.api.acr/src/org/argeo/api/acr/spi/ContentProvider.java
index 25b9be5c2..8b59f2fa2 100644
--- a/org.argeo.api.acr/src/org/argeo/api/acr/spi/ContentProvider.java
+++ b/org.argeo.api.acr/src/org/argeo/api/acr/spi/ContentProvider.java
@@ -6,16 +6,62 @@ import java.util.Spliterator;
import javax.xml.namespace.NamespaceContext;
import org.argeo.api.acr.Content;
+import org.argeo.api.acr.ContentNotFoundException;
+import org.argeo.api.acr.ContentSession;
import org.argeo.api.acr.search.BasicSearch;
+/**
+ * A prover of {@link Content}, which can be mounted in a
+ * {@link ProvidedRepository}.
+ */
public interface ContentProvider extends NamespaceContext {
- ProvidedContent get(ProvidedSession session, String relativePath);
+ /**
+ * Return the content at this path, relative to the mount path.
+ *
+ * @return the content at this relative path, never null
+ * @throws ContentNotFoundException if there is no content at this relative path
+ */
+ ProvidedContent get(ProvidedSession session, String relativePath) throws ContentNotFoundException;
- boolean exists(ProvidedSession session, String relativePath);
+ /**
+ * Whether a content exist at his relative path. The default implementation call
+ * {@link #get(ProvidedSession, String)} and check whether a
+ * {@link ContentNotFoundException} is thrown or not. It should be overridden as
+ * soon as there is a mechanism to check existence before actually getting the
+ * content.
+ */
+ default boolean exists(ProvidedSession session, String relativePath) {
+ try {
+ get(session, relativePath);
+ return true;
+ } catch (ContentNotFoundException e) {
+ return false;
+ }
+ }
+ /** The absolute path where this provider is mounted. */
String getMountPath();
+ /**
+ * Search content within this provider. The default implementation throws an
+ * {@link UnsupportedOperationException}.
+ */
+ default Spliterator search(ProvidedSession session, BasicSearch search, String relPath) {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * EDITION
+ */
+ /**
+ * Called when an edition cycle is completed. Does nothing by default.
+ *
+ * @see ContentSession#edit(java.util.function.Consumer)
+ */
+ default void persist(ProvidedSession session) {
+ }
+
/*
* NAMESPACE CONTEXT
*/
@@ -25,16 +71,4 @@ public interface ContentProvider extends NamespaceContext {
return prefixes.hasNext() ? prefixes.next() : null;
}
- default Spliterator search(ProvidedSession session, BasicSearch search, String relPath) {
- throw new UnsupportedOperationException();
- }
-
-// default ContentName parsePrefixedName(String nameWithPrefix) {
-// return NamespaceUtils.parsePrefixedName(this, nameWithPrefix);
-// }
-//
-// default String toPrefixedName(QName name) {
-// return NamespaceUtils.toPrefixedName(this, name);
-// }
-
}