1 package org
.argeo
.api
.acr
.spi
;
3 import java
.util
.Iterator
;
4 import java
.util
.Spliterator
;
6 import javax
.xml
.namespace
.NamespaceContext
;
8 import org
.argeo
.api
.acr
.Content
;
9 import org
.argeo
.api
.acr
.ContentNotFoundException
;
10 import org
.argeo
.api
.acr
.ContentSession
;
11 import org
.argeo
.api
.acr
.search
.BasicSearch
;
14 * A prover of {@link Content}, which can be mounted in a
15 * {@link ProvidedRepository}.
17 public interface ContentProvider
extends NamespaceContext
{
20 * Return the content at this path, relative to the mount path.
22 * @return the content at this relative path, never <code>null</code>
23 * @throws ContentNotFoundException if there is no content at this relative path
25 ProvidedContent
get(ProvidedSession session
, String relativePath
) throws ContentNotFoundException
;
28 * Whether a content exist at his relative path. The default implementation call
29 * {@link #get(ProvidedSession, String)} and check whether a
30 * {@link ContentNotFoundException} is thrown or not. It should be overridden as
31 * soon as there is a mechanism to check existence before actually getting the
34 default boolean exists(ProvidedSession session
, String relativePath
) {
36 get(session
, relativePath
);
38 } catch (ContentNotFoundException e
) {
43 /** The absolute path where this provider is mounted. */
44 String
getMountPath();
47 * Search content within this provider. The default implementation throws an
48 * {@link UnsupportedOperationException}.
50 default Spliterator
<Content
> search(ProvidedSession session
, BasicSearch search
, String relPath
) {
51 throw new UnsupportedOperationException();
57 /** Switch this content (and its subtree) to editing mode. */
58 default void openForEdit(ProvidedSession session
, String relativePath
) {
59 throw new UnsupportedOperationException();
62 /** Switch this content (and its subtree) to frozen mode. */
63 default void freeze(ProvidedSession session
, String relativePath
) {
64 throw new UnsupportedOperationException();
67 /** Whether this content (and its subtree) are in editing mode. */
68 default boolean isOpenForEdit(ProvidedSession session
, String relativePath
) {
69 throw new UnsupportedOperationException();
73 * Called when an edition cycle is completed. Does nothing by default.
75 * @see ContentSession#edit(java.util.function.Consumer)
77 default void persist(ProvidedSession session
) {
84 default String
getPrefix(String namespaceURI
) {
85 Iterator
<String
> prefixes
= getPrefixes(namespaceURI
);
86 return prefixes
.hasNext() ? prefixes
.next() : null;