diff --git a/generate.sh b/generate.sh new file mode 100755 index 00000000..e848d840 --- /dev/null +++ b/generate.sh @@ -0,0 +1 @@ +xjc webdav.xsd -d src/main/java -p com.github.sardine.model -nv diff --git a/src/main/java/com/github/sardine/DavQuota.java b/src/main/java/com/github/sardine/DavQuota.java new file mode 100644 index 00000000..ae598726 --- /dev/null +++ b/src/main/java/com/github/sardine/DavQuota.java @@ -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; + } + +} diff --git a/src/main/java/com/github/sardine/Sardine.java b/src/main/java/com/github/sardine/Sardine.java index 08631ff1..af635fa4 100644 --- a/src/main/java/com/github/sardine/Sardine.java +++ b/src/main/java/com/github/sardine/Sardine.java @@ -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 * diff --git a/src/main/java/com/github/sardine/impl/SardineImpl.java b/src/main/java/com/github/sardine/impl/SardineImpl.java index 2e94ea24..8c37164e 100644 --- a/src/main/java/com/github/sardine/impl/SardineImpl.java +++ b/src/main/java/com/github/sardine/impl/SardineImpl.java @@ -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; @@ -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; @@ -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 responses = multistatus.getResponse(); + if (responses.isEmpty()) + { + return null; + } + else + { + return new DavQuota(responses.get(0)); + } + } + @Override public List getPrincipals(String url) throws IOException { diff --git a/src/main/java/com/github/sardine/model/Prop.java b/src/main/java/com/github/sardine/model/Prop.java index dcbc8d57..194bf0b4 100644 --- a/src/main/java/com/github/sardine/model/Prop.java +++ b/src/main/java/com/github/sardine/model/Prop.java @@ -1,31 +1,29 @@ // -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1.4-10/27/2009 06:09 PM(mockbuild)-fcs -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2009.12.23 at 06:27:19 PM PST +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.05.31 at 06:14:58 PM MSK // package com.github.sardine.model; -import org.w3c.dom.Element; - +import java.util.ArrayList; +import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import java.util.ArrayList; -import java.util.List; - +import org.w3c.dom.Element; /** *

Java class for anonymous complex type. - * + * *

The following schema fragment specifies the expected content contained within this class. - * + * *

  * <complexType>
  *   <complexContent>
@@ -41,15 +39,16 @@
  *         <element ref="{DAV:}lockdiscovery" minOccurs="0"/>
  *         <element ref="{DAV:}resourcetype" minOccurs="0"/>
  *         <element ref="{DAV:}supportedlock" minOccurs="0"/>
- *         <element ref="{DAV:}owner" minOccurs="0"/>  <!-- (for DAV:acl) -->
- *         <any/>
+ *         <element ref="{DAV:}quota-available-bytes" minOccurs="0"/>
+ *         <element ref="{DAV:}quota-used-bytes" minOccurs="0"/>
+ *         <any processContents='skip' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
  *       </all>
  *     </restriction>
  *   </complexContent>
  * </complexType>
  * 
- * - * + * + * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { @@ -58,17 +57,23 @@ @XmlRootElement(name = "prop") public class Prop { - private Creationdate creationdate; - private Displayname displayname; - private Getcontentlanguage getcontentlanguage; - private Getcontentlength getcontentlength; - private Getcontenttype getcontenttype; - private Getetag getetag; - private Getlastmodified getlastmodified; - private Lockdiscovery lockdiscovery; - private Resourcetype resourcetype; - private Supportedlock supportedlock; - + protected Creationdate creationdate; + protected Displayname displayname; + protected Getcontentlanguage getcontentlanguage; + protected Getcontentlength getcontentlength; + protected Getcontenttype getcontenttype; + protected Getetag getetag; + protected Getlastmodified getlastmodified; + protected Lockdiscovery lockdiscovery; + protected Resourcetype resourcetype; + protected Supportedlock supportedlock; + @XmlElement(name = "quota-available-bytes") + protected QuotaAvailableBytes quotaAvailableBytes; + @XmlElement(name = "quota-used-bytes") + protected QuotaUsedBytes quotaUsedBytes; + @XmlAnyElement + protected List any; + //ACL elements private Owner owner; private Group group; @@ -76,18 +81,16 @@ public class Prop { @XmlElement(name="principal-collection-set") private PrincipalCollectionSet principalCollectionSet; @XmlElement(name="principal-URL") - private PrincipalURL principalURL; + private PrincipalURL principalURL; - @XmlAnyElement - private List any; /** * Gets the value of the creationdate property. - * + * * @return * possible object is * {@link Creationdate } - * + * */ public Creationdate getCreationdate() { return creationdate; @@ -95,11 +98,11 @@ public Creationdate getCreationdate() { /** * Sets the value of the creationdate property. - * + * * @param value * allowed object is * {@link Creationdate } - * + * */ public void setCreationdate(Creationdate value) { this.creationdate = value; @@ -107,11 +110,11 @@ public void setCreationdate(Creationdate value) { /** * Gets the value of the displayname property. - * + * * @return * possible object is * {@link Displayname } - * + * */ public Displayname getDisplayname() { return displayname; @@ -119,11 +122,11 @@ public Displayname getDisplayname() { /** * Sets the value of the displayname property. - * + * * @param value * allowed object is * {@link Displayname } - * + * */ public void setDisplayname(Displayname value) { this.displayname = value; @@ -131,11 +134,11 @@ public void setDisplayname(Displayname value) { /** * Gets the value of the getcontentlanguage property. - * + * * @return * possible object is * {@link Getcontentlanguage } - * + * */ public Getcontentlanguage getGetcontentlanguage() { return getcontentlanguage; @@ -143,11 +146,11 @@ public Getcontentlanguage getGetcontentlanguage() { /** * Sets the value of the getcontentlanguage property. - * + * * @param value * allowed object is * {@link Getcontentlanguage } - * + * */ public void setGetcontentlanguage(Getcontentlanguage value) { this.getcontentlanguage = value; @@ -155,11 +158,11 @@ public void setGetcontentlanguage(Getcontentlanguage value) { /** * Gets the value of the getcontentlength property. - * + * * @return * possible object is * {@link Getcontentlength } - * + * */ public Getcontentlength getGetcontentlength() { return getcontentlength; @@ -167,11 +170,11 @@ public Getcontentlength getGetcontentlength() { /** * Sets the value of the getcontentlength property. - * + * * @param value * allowed object is * {@link Getcontentlength } - * + * */ public void setGetcontentlength(Getcontentlength value) { this.getcontentlength = value; @@ -179,11 +182,11 @@ public void setGetcontentlength(Getcontentlength value) { /** * Gets the value of the getcontenttype property. - * + * * @return * possible object is * {@link Getcontenttype } - * + * */ public Getcontenttype getGetcontenttype() { return getcontenttype; @@ -191,11 +194,11 @@ public Getcontenttype getGetcontenttype() { /** * Sets the value of the getcontenttype property. - * + * * @param value * allowed object is * {@link Getcontenttype } - * + * */ public void setGetcontenttype(Getcontenttype value) { this.getcontenttype = value; @@ -203,11 +206,11 @@ public void setGetcontenttype(Getcontenttype value) { /** * Gets the value of the getetag property. - * + * * @return * possible object is * {@link Getetag } - * + * */ public Getetag getGetetag() { return getetag; @@ -215,11 +218,11 @@ public Getetag getGetetag() { /** * Sets the value of the getetag property. - * + * * @param value * allowed object is * {@link Getetag } - * + * */ public void setGetetag(Getetag value) { this.getetag = value; @@ -227,11 +230,11 @@ public void setGetetag(Getetag value) { /** * Gets the value of the getlastmodified property. - * + * * @return * possible object is * {@link Getlastmodified } - * + * */ public Getlastmodified getGetlastmodified() { return getlastmodified; @@ -239,11 +242,11 @@ public Getlastmodified getGetlastmodified() { /** * Sets the value of the getlastmodified property. - * + * * @param value * allowed object is * {@link Getlastmodified } - * + * */ public void setGetlastmodified(Getlastmodified value) { this.getlastmodified = value; @@ -251,11 +254,11 @@ public void setGetlastmodified(Getlastmodified value) { /** * Gets the value of the lockdiscovery property. - * + * * @return * possible object is * {@link Lockdiscovery } - * + * */ public Lockdiscovery getLockdiscovery() { return lockdiscovery; @@ -263,11 +266,11 @@ public Lockdiscovery getLockdiscovery() { /** * Sets the value of the lockdiscovery property. - * + * * @param value * allowed object is * {@link Lockdiscovery } - * + * */ public void setLockdiscovery(Lockdiscovery value) { this.lockdiscovery = value; @@ -275,11 +278,11 @@ public void setLockdiscovery(Lockdiscovery value) { /** * Gets the value of the resourcetype property. - * + * * @return * possible object is * {@link Resourcetype } - * + * */ public Resourcetype getResourcetype() { return resourcetype; @@ -287,11 +290,11 @@ public Resourcetype getResourcetype() { /** * Sets the value of the resourcetype property. - * + * * @param value * allowed object is * {@link Resourcetype } - * + * */ public void setResourcetype(Resourcetype value) { this.resourcetype = value; @@ -299,11 +302,11 @@ public void setResourcetype(Resourcetype value) { /** * Gets the value of the supportedlock property. - * + * * @return * possible object is * {@link Supportedlock } - * + * */ public Supportedlock getSupportedlock() { return supportedlock; @@ -311,37 +314,85 @@ public Supportedlock getSupportedlock() { /** * Sets the value of the supportedlock property. - * + * * @param value * allowed object is * {@link Supportedlock } - * + * */ public void setSupportedlock(Supportedlock value) { this.supportedlock = value; } + /** + * Gets the value of the quotaAvailableBytes property. + * + * @return + * possible object is + * {@link QuotaAvailableBytes } + * + */ + public QuotaAvailableBytes getQuotaAvailableBytes() { + return quotaAvailableBytes; + } + + /** + * Sets the value of the quotaAvailableBytes property. + * + * @param value + * allowed object is + * {@link QuotaAvailableBytes } + * + */ + public void setQuotaAvailableBytes(QuotaAvailableBytes value) { + this.quotaAvailableBytes = value; + } + + /** + * Gets the value of the quotaUsedBytes property. + * + * @return + * possible object is + * {@link QuotaUsedBytes } + * + */ + public QuotaUsedBytes getQuotaUsedBytes() { + return quotaUsedBytes; + } + + /** + * Sets the value of the quotaUsedBytes property. + * + * @param value + * allowed object is + * {@link QuotaUsedBytes } + * + */ + public void setQuotaUsedBytes(QuotaUsedBytes value) { + this.quotaUsedBytes = value; + } + /** * Gets the value of the any property. - * + * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the any property. - * + * *

* For example, to add a new item, do as follows: *

      *    getAny().add(newItem);
      * 
- * - * + * + * *

* Objects of the following type(s) are allowed in the list * {@link Element } - * - * + * + * */ public List getAny() { if (any == null) { @@ -365,7 +416,8 @@ public Group getGroup() { public void setGroup(Group group) { this.group = group; } - public Acl getAcl() { + + public Acl getAcl() { return acl; } @@ -388,5 +440,4 @@ public PrincipalURL getPrincipalURL() { public void setPrincipalURL(PrincipalURL principalURL) { this.principalURL = principalURL; } - } diff --git a/src/main/java/com/github/sardine/model/QuotaAvailableBytes.java b/src/main/java/com/github/sardine/model/QuotaAvailableBytes.java new file mode 100644 index 00000000..bfafc01f --- /dev/null +++ b/src/main/java/com/github/sardine/model/QuotaAvailableBytes.java @@ -0,0 +1,77 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.05.31 at 06:14:58 PM MSK +// + + +package com.github.sardine.model; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "content" +}) +@XmlRootElement(name = "quota-available-bytes") +public class QuotaAvailableBytes { + + @XmlMixed + protected List content; + + /** + * Gets the value of the content property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the content property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getContent().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getContent() { + if (content == null) { + content = new ArrayList(); + } + return this.content; + } + +} diff --git a/src/main/java/com/github/sardine/model/QuotaUsedBytes.java b/src/main/java/com/github/sardine/model/QuotaUsedBytes.java new file mode 100644 index 00000000..7c3f2c21 --- /dev/null +++ b/src/main/java/com/github/sardine/model/QuotaUsedBytes.java @@ -0,0 +1,77 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.05.31 at 06:14:58 PM MSK +// + + +package com.github.sardine.model; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "content" +}) +@XmlRootElement(name = "quota-used-bytes") +public class QuotaUsedBytes { + + @XmlMixed + protected List content; + + /** + * Gets the value of the content property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the content property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getContent().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getContent() { + if (content == null) { + content = new ArrayList(); + } + return this.content; + } + +} diff --git a/webdav.xsd b/webdav.xsd index 7a0f9ff2..e1a6f7ef 100644 --- a/webdav.xsd +++ b/webdav.xsd @@ -184,6 +184,8 @@ + +