]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/acr/dav/DavContentProvider.java
1 package org
.argeo
.cms
.acr
.dav
;
4 import java
.net
.URISyntaxException
;
5 import java
.util
.Iterator
;
7 import org
.argeo
.api
.acr
.RuntimeNamespaceContext
;
8 import org
.argeo
.api
.acr
.spi
.ContentProvider
;
9 import org
.argeo
.api
.acr
.spi
.ProvidedContent
;
10 import org
.argeo
.api
.acr
.spi
.ProvidedSession
;
11 import org
.argeo
.cms
.dav
.DavClient
;
12 import org
.argeo
.cms
.dav
.DavResponse
;
14 public class DavContentProvider
implements ContentProvider
{
15 private String mountPath
;
18 private DavClient davClient
;
20 public DavContentProvider(String mountPath
, URI baseUri
) {
21 this.mountPath
= mountPath
;
22 this.baseUri
= baseUri
;
23 if (!baseUri
.getPath().endsWith("/"))
24 throw new IllegalArgumentException("Base URI " + baseUri
+ " path does not end with /");
25 this.davClient
= new DavClient();
29 public String
getNamespaceURI(String prefix
) {
30 // FIXME retrieve mappings from WebDav
31 return RuntimeNamespaceContext
.getNamespaceContext().getNamespaceURI(prefix
);
35 public Iterator
<String
> getPrefixes(String namespaceURI
) {
36 // FIXME retrieve mappings from WebDav
37 return RuntimeNamespaceContext
.getNamespaceContext().getPrefixes(namespaceURI
);
41 public ProvidedContent
get(ProvidedSession session
, String relativePath
) {
42 URI contentUri
= relativePathToUri(relativePath
);
43 return getDavContent(session
, contentUri
);
46 DavContent
getDavContent(ProvidedSession session
, URI uri
) {
47 DavResponse response
= davClient
.get(uri
);
48 return new DavContent(session
, this, uri
, response
.getPropertyNames());
52 public boolean exists(ProvidedSession session
, String relativePath
) {
53 URI contentUri
= relativePathToUri(relativePath
);
54 return davClient
.exists(contentUri
);
58 public String
getMountPath() {
62 DavClient
getDavClient() {
66 URI
relativePathToUri(String relativePath
) {
68 // TODO check last slash
69 String path
= relativePath
.startsWith("/") ? relativePath
: baseUri
.getPath() + relativePath
;
70 URI uri
= new URI(baseUri
.getScheme(), baseUri
.getHost(), path
, baseUri
.getFragment());
72 } catch (URISyntaxException e
) {
73 throw new IllegalArgumentException("Cannot build URI for " + relativePath
+ " relatively to " + baseUri
, e
);