summaryrefslogtreecommitdiffstats
path: root/core/vendor
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-12-01 21:01:12 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-16 11:28:04 +0100
commit857c316bdad86917d79abdea7f18b5fd2510b48d (patch)
tree4a075a9fef25bb8cb1f78dc6be62f1b7571a255c /core/vendor
parent7a239b264274c8e77f6d8aa7ccedb8228e8c4fcb (diff)
downloadnextcloud-server-857c316bdad86917d79abdea7f18b5fd2510b48d.tar.gz
nextcloud-server-857c316bdad86917d79abdea7f18b5fd2510b48d.zip
Backbone transport for Webdav
Diffstat (limited to 'core/vendor')
-rw-r--r--core/vendor/davclient.js/lib/client.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/core/vendor/davclient.js/lib/client.js b/core/vendor/davclient.js/lib/client.js
index 18bbf13f3cd..1a73c7db020 100644
--- a/core/vendor/davclient.js/lib/client.js
+++ b/core/vendor/davclient.js/lib/client.js
@@ -1,5 +1,19 @@
if (typeof dav == 'undefined') { dav = {}; };
+dav._XML_CHAR_MAP = {
+ '<': '&lt;',
+ '>': '&gt;',
+ '&': '&amp;',
+ '"': '&quot;',
+ "'": '&apos;'
+};
+
+dav._escapeXml = function(s) {
+ return s.replace(/[<>&"']/g, function (ch) {
+ return dav._XML_CHAR_MAP[ch];
+ });
+};
+
dav.Client = function(options) {
var i;
for(i in options) {
@@ -86,6 +100,57 @@ dav.Client.prototype = {
},
/**
+ * Generates a propPatch request.
+ *
+ * @param {string} url Url to do the proppatch request on
+ * @param {Array} properties List of properties to store.
+ * @return {Promise}
+ */
+ propPatch : function(url, properties, headers) {
+ headers = headers || {};
+
+ headers['Content-Type'] = 'application/xml; charset=utf-8';
+
+ var body =
+ '<?xml version="1.0"?>\n' +
+ '<d:propertyupdate ';
+ var namespace;
+ for (namespace in this.xmlNamespaces) {
+ body += ' xmlns:' + this.xmlNamespaces[namespace] + '="' + namespace + '"';
+ }
+ body += '>\n' +
+ ' <d:set>\n' +
+ ' <d:prop>\n';
+
+ for(var ii in properties) {
+
+ var property = this.parseClarkNotation(ii);
+ var propName;
+ var propValue = properties[ii];
+ if (this.xmlNamespaces[property.namespace]) {
+ propName = this.xmlNamespaces[property.namespace] + ':' + property.name;
+ } else {
+ propName = 'x:' + property.name + ' xmlns:x="' + property.namespace + '"';
+ }
+ body += ' <' + propName + '>' + dav._escapeXml(propValue) + '</' + propName + '>\n';
+ }
+ body+=' </d:prop>\n';
+ body+=' </d:set>\n';
+ body+='</d:propertyupdate>';
+
+ return this.request('PROPPATCH', url, headers, body).then(
+ function(result) {
+ return {
+ status: result.status,
+ body: result.body,
+ xhr: result.xhr
+ };
+ }.bind(this)
+ );
+
+ },
+
+ /**
* Performs a HTTP request, and returns a Promise
*
* @param {string} method HTTP method