X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2Fspi%2FContentProvider.java;h=e354672a781c77adc1a09a009f42a3f2264c71b1;hb=f0f342072b85e1d97e79ef2148f7501f1bd646cd;hp=d83cf49c95e27e8b828924a1f71547c235f16f83;hpb=7d2a002f5dcfe8a8c7b29803b70d4b1aff265ed1;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 d83cf49c9..e354672a7 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 @@ -1,9 +1,89 @@ package org.argeo.api.acr.spi; +import java.util.Iterator; +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 { + + /** + * 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; + + /** + * 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 + */ + /** Switch this content (and its subtree) to editing mode. */ + default void openForEdit(ProvidedSession session, String relativePath) { + throw new UnsupportedOperationException(); + } + + /** Switch this content (and its subtree) to frozen mode. */ + default void freeze(ProvidedSession session, String relativePath) { + throw new UnsupportedOperationException(); + } + + /** Whether this content (and its subtree) are in editing mode. */ + default boolean isOpenForEdit(ProvidedSession session, String relativePath) { + throw new UnsupportedOperationException(); + } -public interface ContentProvider { + /** + * Called when an edition cycle is completed. Does nothing by default. + * + * @see ContentSession#edit(java.util.function.Consumer) + */ + default void persist(ProvidedSession session) { + } - Content get(ProvidedSession session, String mountPath, String relativePath); + /* + * NAMESPACE CONTEXT + */ + @Override + default String getPrefix(String namespaceURI) { + Iterator prefixes = getPrefixes(namespaceURI); + return prefixes.hasNext() ? prefixes.next() : null; + } }