diff --git a/src/main/java/com/github/sardine/DavResource.java b/src/main/java/com/github/sardine/DavResource.java index 248579ca..fe40a710 100644 --- a/src/main/java/com/github/sardine/DavResource.java +++ b/src/main/java/com/github/sardine/DavResource.java @@ -7,6 +7,7 @@ package com.github.sardine; +import com.github.sardine.model.Activelock; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -31,6 +32,8 @@ import com.github.sardine.model.Getcontenttype; import com.github.sardine.model.Getetag; import com.github.sardine.model.Getlastmodified; +import com.github.sardine.model.Lockdiscovery; +import com.github.sardine.model.Locktoken; import com.github.sardine.model.Propstat; import com.github.sardine.model.Report; import com.github.sardine.model.Resourcetype; @@ -87,6 +90,7 @@ private class DavProperties final String contentType; final String etag; final String displayName; + final String lockToken; final List resourceTypes; final String contentLanguage; final Long contentLength; @@ -94,7 +98,7 @@ private class DavProperties final Map customProps; DavProperties(Date creation, Date modified, String contentType, - Long contentLength, String etag, String displayName, List resourceTypes, + Long contentLength, String etag, String displayName, String lockToken, List resourceTypes, String contentLanguage, List supportedReports, Map customProps) { this.creation = creation; @@ -103,6 +107,7 @@ private class DavProperties this.contentLength = contentLength; this.etag = etag; this.displayName = displayName; + this.lockToken = lockToken; this.resourceTypes = resourceTypes; this.contentLanguage = contentLanguage; this.supportedReports = supportedReports; @@ -116,6 +121,7 @@ private class DavProperties this.contentLength = getContentLength(response); this.etag = getEtag(response); this.displayName = getDisplayName(response); + this.lockToken = getLockToken(response); this.resourceTypes = getResourceTypes(response); this.contentLanguage = getContentLanguage(response); this.supportedReports = getSupportedReports(response); @@ -130,13 +136,13 @@ private class DavProperties * @throws java.net.URISyntaxException If parsing the href from the response element fails */ protected DavResource(String href, Date creation, Date modified, String contentType, - Long contentLength, String etag, String displayName, List resourceTypes, + Long contentLength, String etag, String displayName, String lockToken, List resourceTypes, String contentLanguage, List supportedReports, Map customProps) throws URISyntaxException { this.href = new URI(href); this.status = DEFAULT_STATUS_CODE; - this.props = new DavProperties(creation, modified, contentType, contentLength, etag, displayName, + this.props = new DavProperties(creation, modified, contentType, contentLength, etag, displayName, lockToken, resourceTypes, contentLanguage, supportedReports, customProps); } @@ -204,6 +210,46 @@ private String getModifiedDate(Response response) return null; } + /** + * Retrieves locktocken from props. If it is not available return null. + * + * @param response The response complex type of the multistatus + * @return Null if not found in props + */ + private String getLockToken(Response response) + { + List list = response.getPropstat(); + if (list.isEmpty()) + { + return null; + } + for (Propstat propstat : list) + { + if (propstat.getProp() != null) { + Lockdiscovery ld = propstat.getProp().getLockdiscovery(); + if (ld != null) + { + if (ld.getActivelock().size() == 1) + { + final Activelock al = ld.getActivelock().get(0); + if (al != null) + { + final Locktoken lt = al.getLocktoken(); + if (lt != null) + { + if (lt.getHref().size() == 1) + { + return lt.getHref().get(0); + } + } + } + } + } + } + } + return null; + } + /** * Retrieves creationdate from props. If it is not available return null. * @@ -552,6 +598,14 @@ public String getDisplayName() return this.props.displayName; } + /** + * @return Lock Token + */ + public String getLockToken() + { + return this.props.lockToken; + } + /** * @return Resource types */ diff --git a/src/main/java/com/github/sardine/impl/SardineImpl.java b/src/main/java/com/github/sardine/impl/SardineImpl.java index 8fedf091..dcfca751 100644 --- a/src/main/java/com/github/sardine/impl/SardineImpl.java +++ b/src/main/java/com/github/sardine/impl/SardineImpl.java @@ -429,6 +429,7 @@ public List list(String url, int depth, java.util.Set props) prop.setGetcontenttype(objectFactory.createGetcontenttype()); prop.setResourcetype(objectFactory.createResourcetype()); prop.setGetetag(objectFactory.createGetetag()); + prop.setLockdiscovery(objectFactory.createLockdiscovery()); addCustomProperties(prop, props); body.setProp(prop); return propfind(url, depth, body); diff --git a/src/test/java/com/github/sardine/DavResourceTest.java b/src/test/java/com/github/sardine/DavResourceTest.java index cc0ffbe5..1934f4ba 100644 --- a/src/test/java/com/github/sardine/DavResourceTest.java +++ b/src/test/java/com/github/sardine/DavResourceTest.java @@ -43,6 +43,7 @@ private static class Builder private String contentType; private String etag; private String displayName; + private String lockToken; private List resourceTypes= Collections.emptyList(); private String contentLanguage; private Long contentLength = -1L; @@ -90,6 +91,11 @@ Builder withDisplayName(String displayName) { return this; } + Builder withLockToken(String lockToken) { + this.lockToken = lockToken; + return this; + } + Builder withResourceTypes(List resourceTypes) { this.resourceTypes = resourceTypes; return this; @@ -114,7 +120,7 @@ Builder withCustomProps(Map customProps) { DavResource build() throws URISyntaxException { return new DavResource(href, creation, modified, contentType, contentLength, etag, - displayName, resourceTypes, contentLanguage, supportedReports, customProps); + displayName, lockToken, resourceTypes, contentLanguage, supportedReports, customProps); } }