]> git.argeo.org Git - lgpl/argeo-commons.git/blob - spi/ContentProvider.java
Prepare next development cycle
[lgpl/argeo-commons.git] / spi / ContentProvider.java
1 package org.argeo.api.acr.spi;
2
3 import java.util.Iterator;
4 import java.util.Spliterator;
5
6 import javax.xml.namespace.NamespaceContext;
7
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;
12
13 /**
14 * A prover of {@link Content}, which can be mounted in a
15 * {@link ProvidedRepository}.
16 */
17 public interface ContentProvider extends NamespaceContext {
18
19 /**
20 * Return the content at this path, relative to the mount path.
21 *
22 * @return the content at this relative path, never <code>null</code>
23 * @throws ContentNotFoundException if there is no content at this relative path
24 */
25 ProvidedContent get(ProvidedSession session, String relativePath) throws ContentNotFoundException;
26
27 /**
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
32 * content.
33 */
34 default boolean exists(ProvidedSession session, String relativePath) {
35 try {
36 get(session, relativePath);
37 return true;
38 } catch (ContentNotFoundException e) {
39 return false;
40 }
41 }
42
43 /** The absolute path where this provider is mounted. */
44 String getMountPath();
45
46 /**
47 * Search content within this provider. The default implementation throws an
48 * {@link UnsupportedOperationException}.
49 */
50 default Spliterator<Content> search(ProvidedSession session, BasicSearch search, String relPath) {
51 throw new UnsupportedOperationException();
52 }
53
54 /*
55 * EDITION
56 */
57 /** Switch this content (and its subtree) to editing mode. */
58 default void openForEdit(ProvidedSession session, String relativePath) {
59 throw new UnsupportedOperationException();
60 }
61
62 /** Switch this content (and its subtree) to frozen mode. */
63 default void freeze(ProvidedSession session, String relativePath) {
64 throw new UnsupportedOperationException();
65 }
66
67 /** Whether this content (and its subtree) are in editing mode. */
68 default boolean isOpenForEdit(ProvidedSession session, String relativePath) {
69 throw new UnsupportedOperationException();
70 }
71
72 /**
73 * Called when an edition cycle is completed. Does nothing by default.
74 *
75 * @see ContentSession#edit(java.util.function.Consumer)
76 */
77 default void persist(ProvidedSession session) {
78 }
79
80 /*
81 * NAMESPACE CONTEXT
82 */
83 @Override
84 default String getPrefix(String namespaceURI) {
85 Iterator<String> prefixes = getPrefixes(namespaceURI);
86 return prefixes.hasNext() ? prefixes.next() : null;
87 }
88
89 }