1 package org
.argeo
.cms
.acr
;
3 import java
.util
.Collections
;
4 import java
.util
.Iterator
;
8 import javax
.xml
.namespace
.QName
;
10 import org
.argeo
.api
.acr
.Content
;
11 import org
.argeo
.api
.acr
.ContentName
;
12 import org
.argeo
.api
.acr
.spi
.ContentProvider
;
13 import org
.argeo
.api
.acr
.spi
.ProvidedContent
;
14 import org
.argeo
.api
.acr
.spi
.ProvidedSession
;
15 import org
.argeo
.api
.cms
.CmsConstants
;
18 * Base for simple content providers based on a service supporting only one
19 * namespace. Typically used in higher level applications for domain-specific
22 public abstract class AbstractSimpleContentProvider
<SERVICE
> implements ContentProvider
{
23 private final String namespaceUri
;
24 private final String defaultPrefix
;
25 private SERVICE service
;
26 private String mountPath
;
27 private String mountName
;
29 protected AbstractSimpleContentProvider(String namespaceUri
, String defaultPrefix
) {
30 this(namespaceUri
, defaultPrefix
, null, null);
33 protected AbstractSimpleContentProvider(String namespaceUri
, String defaultPrefix
, SERVICE service
,
35 this.namespaceUri
= namespaceUri
;
36 this.defaultPrefix
= defaultPrefix
;
37 this.service
= service
;
38 setMountPath(mountPath
);
41 /** The first level of content provided by the service. */
42 protected abstract Iterator
<Content
> firstLevel(ProvidedSession session
);
45 * Retrieve the content at this relative path. Root content is already dealt
48 protected abstract ProvidedContent
get(ProvidedSession session
, List
<String
> segments
);
51 public final ProvidedContent
get(ProvidedSession session
, String relativePath
) {
52 List
<String
> segments
= ContentUtils
.toPathSegments(relativePath
);
53 if (segments
.size() == 0)
54 return new ServiceContent(session
);
55 return get(session
, segments
);
58 public void start(Map
<String
, String
> properties
) {
59 mountPath
= properties
.get(CmsConstants
.ACR_MOUNT_PATH
);
60 if (mountPath
== null)
61 throw new IllegalStateException(CmsConstants
.ACR_MOUNT_PATH
+ " must be specified.");
62 setMountPath(mountPath
);
65 private void setMountPath(String mountPath
) {
66 if (mountPath
== null)
68 this.mountPath
= mountPath
;
69 List
<String
> mountSegments
= ContentUtils
.toPathSegments(mountPath
);
70 this.mountName
= mountSegments
.get(mountSegments
.size() - 1);
75 public String
getNamespaceURI(String prefix
) {
76 if (defaultPrefix
.equals(prefix
))
78 throw new IllegalArgumentException("Only prefix " + defaultPrefix
+ " is supported");
82 public Iterator
<String
> getPrefixes(String namespaceURI
) {
83 if (namespaceUri
.equals(namespaceURI
))
84 return Collections
.singletonList(defaultPrefix
).iterator();
85 throw new IllegalArgumentException("Only namespace URI " + namespaceUri
+ " is supported");
89 public String
getMountPath() {
93 protected String
getMountName() {
97 protected SERVICE
getService() {
101 public void setService(SERVICE service
) {
102 this.service
= service
;
105 protected class ServiceContent
extends AbstractContent
{
107 public ServiceContent(ProvidedSession session
) {
112 public ContentProvider
getProvider() {
113 return AbstractSimpleContentProvider
.this;
117 public QName
getName() {
118 return new ContentName(getMountName());
122 public Content
getParent() {
127 public Iterator
<Content
> iterator() {
128 return firstLevel(getSession());