Skip to content

Commit

Permalink
Support RFC 4331: Quota and Size Properties for DAV Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Makarov committed May 31, 2013
1 parent e330114 commit 86c89a2
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 78 deletions.
1 change: 1 addition & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xjc webdav.xsd -d src/main/java -p com.github.sardine.model -nv
43 changes: 43 additions & 0 deletions src/main/java/com/github/sardine/DavQuota.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.sardine;

import com.github.sardine.model.Prop;
import com.github.sardine.model.Response;

/**
* Quota and Size Properties
*
* @author Alexander Makarov
*/
public class DavQuota {
/**
* The DAV:quota-available-bytes property value is the value in octets
* representing the amount of additional disk space beyond the current
* allocation that can be allocated to this resource before further
* allocations will be refused.
*/
private final long quotaAvailableBytes;

/**
* The DAV:quota-used-bytes value is the value in octets representing
* the amount of space used by this resource and possibly a number of
* other similar resources, where the set of "similar" meets at least
* the criterion that allocating space to any resource in the set will
* count against the DAV:quota-available-bytes.
*/
private final long quotaUsedBytes;

public DavQuota(Response response) {
Prop prop = response.getPropstat().get(0).getProp();
this.quotaAvailableBytes = Long.valueOf(prop.getQuotaAvailableBytes().getContent().get(0));
this.quotaUsedBytes = Long.valueOf(prop.getQuotaUsedBytes().getContent().get(0));
}

public long getQuotaAvailableBytes() {
return quotaAvailableBytes;
}

public long getQuotaUsedBytes() {
return quotaUsedBytes;
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/github/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ public interface Sardine
*/
DavAcl getAcl(String url) throws IOException;

/**
* Read quota properties for resource
*
* @param url Path to the resource including protocol and hostname
* @return Current Quota and Size Properties for resource
* @throws IOException I/O error or HTTP response validation failure
*/
DavQuota getQuota(String url) throws IOException;

/**
* Write access control list for resource
*
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/com/github/sardine/impl/SardineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;

import com.github.sardine.DavAce;
import com.github.sardine.DavAcl;
import com.github.sardine.DavPrincipal;
import com.github.sardine.DavQuota;
import com.github.sardine.DavResource;
import com.github.sardine.Sardine;
import com.github.sardine.Version;
Expand Down Expand Up @@ -117,6 +117,8 @@
import com.github.sardine.model.Propertyupdate;
import com.github.sardine.model.Propfind;
import com.github.sardine.model.Propstat;
import com.github.sardine.model.QuotaUsedBytes;
import com.github.sardine.model.QuotaAvailableBytes;
import com.github.sardine.model.Remove;
import com.github.sardine.model.Resourcetype;
import com.github.sardine.model.Response;
Expand Down Expand Up @@ -515,6 +517,29 @@ public DavAcl getAcl(String url) throws IOException
}
}

@Override
public DavQuota getQuota(String url) throws IOException
{
HttpPropFind entity = new HttpPropFind(url);
entity.setDepth("0");
Propfind body = new Propfind();
Prop prop = new Prop();
prop.setQuotaAvailableBytes(new QuotaAvailableBytes());
prop.setQuotaUsedBytes(new QuotaUsedBytes());
body.setProp(prop);
entity.setEntity(new StringEntity(SardineUtil.toXml(body), UTF_8));
Multistatus multistatus = this.execute(entity, new MultiStatusResponseHandler());
List<Response> responses = multistatus.getResponse();
if (responses.isEmpty())
{
return null;
}
else
{
return new DavQuota(responses.get(0));
}
}

@Override
public List<DavPrincipal> getPrincipals(String url) throws IOException
{
Expand Down
Loading

0 comments on commit 86c89a2

Please sign in to comment.