[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - jsdav.js:1.8
Stephan Richter
srichter@cbu.edu
Sun, 23 Mar 2003 17:46:48 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv17528/moztop/content/lib
Modified Files:
jsdav.js
Log Message:
Changed XML serialization to use XMLDocument and XMLSerializer. Much
nicer.
=== Packages/Moztop/moztop/content/lib/jsdav.js 1.7 => 1.8 ===
--- Packages/Moztop/moztop/content/lib/jsdav.js:1.7 Sun Mar 23 13:39:27 2003
+++ Packages/Moztop/moztop/content/lib/jsdav.js Sun Mar 23 17:46:47 2003
@@ -46,7 +46,7 @@
DavClient.prototype.PROPFIND = function(url, propfind, depth) {
/* Implementation of WebDAV command PROPFIND.
-
+
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.1
*/
var request = new XMLHttpRequest();
@@ -75,17 +75,32 @@
request.send("");
else
request.send(propfind.serialize());
-
- return;
}
-DavClient.prototype.PROPPATCH = function(url) {
+DavClient.prototype.PROPPATCH = function(url, propertyupdate) {
/* Implementation of WebDAV command PROPPATCH.
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.2
*/
+ // Can have: propertyupdate (must), set, remove
+ var request = new XMLHttpRequest();
+
+ function handleResponse(error) {
+ if (request.responseXML) {
+ var response = request.responseXML;
+ // XXX: Handle returned XML
+
+ // Must handle 200, 403, 409, 423, 507
+
+ }
+ }
+ request.onload = handleResponse;
+ request.open("PROPFIND", url);
+ request.setRequestHeader("Content-type", "text/xml");
+ request.setRequestHeader("Host", this.hostname);
+ request.send(propertyupdate.serialize());
}
@@ -94,7 +109,19 @@
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.3
*/
+ var request = new XMLHttpRequest();
+ function handleResponse(error) {
+ // XXX: Handle simple return status; success: 201
+ };
+
+ request.onload = handleResponse;
+ request.open("MKCOL", url);
+ request.setRequestHeader("Content-type", "text/plain");
+ request.setRequestHeader("Host", this.hostname);
+ // XXX: Supposely a message body is possible, but the specs were
+ // incredibly unclear about the form of the message
+ request.send("");
}
@@ -103,7 +130,17 @@
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
*/
+ var request = new XMLHttpRequest();
+
+ function handleResponse(error) {
+ // XXX: Handle simple return value and status;
+ };
+ request.onload = handleResponse;
+ request.open("GET", url);
+ request.setRequestHeader("Content-type", "text/plain");
+ request.setRequestHeader("Host", this.hostname);
+ request.send("");
}
@@ -112,13 +149,23 @@
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
*/
+ var request = new XMLHttpRequest();
+
+ function handleResponse(error) {
+ // XXX: Handle simple return value and status;
+ };
+ request.onload = handleResponse;
+ request.open("HEAD", url);
+ request.setRequestHeader("Content-type", "text/plain");
+ request.setRequestHeader("Host", this.hostname);
+ request.send("");
}
DavClient.prototype.POST = function(url) {
/* Implementation of WebDAV command POST.
-
+
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.5
*/
@@ -205,7 +252,7 @@
DavClient.prototype.MOVE = function(url, destination, headers) {
- /* Implementation of WebDAV command MOVE.
+ /* Implementation of WebDAV command MOVE.
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.9
*/
@@ -315,7 +362,112 @@
}
-/* Data structure for the propfind XML Element and its children */
+/* Data structure for the DAV XML Elements */
+
+function ActiveLock() {
+ /* Implementation of activelock XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1
+ */
+ this.lockscope = null;
+ this.locktype = null;
+ this.depth = null;
+ this.owner = null;
+ this.timout = null;
+ this.locktoken = null;
+}
+
+
+ActiveLock.prototype = {
+ serialize: function() {
+ xml = ' <DAV:activelock>\n';
+ xml += lockscope.serialize();
+ xml += locktype.serialize();
+ xml += depth.serialize();
+ if (this.owner)
+ xml += this.owner.serialize();
+ if (this.timeout)
+ xml += this.timeout.serialize();
+ if (this.locktoken)
+ xml += this.locktoken.serialize();
+ xml += ' </DAV:activelock>\n';
+ return xml;
+ }
+}
+
+function Depth(depth) {
+ /* Implementation of depth XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.1
+ */
+ this.depth = depth;
+}
+
+Depth.prototype = {
+ serialize: function() {
+ return "<DAV:depth>"+this.depth+"</DAV:depth>";
+ }
+}
+
+
+function LockToken(href) {
+ /* Implementation of locktoken XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.2
+ */
+ this.href = href;
+}
+
+LockToken.prototype = {
+ serialize: function() {
+ return "<DAV:locktoken>"+this.href+"</DAV:locktoken>";
+ }
+}
+
+
+function Timeout(time) {
+ /* Implementation of timeout XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.3
+ */
+ this.time = time;
+}
+
+Timeout.prototype = {
+ serialize: function() {
+ return "<DAV:timeout>"+this.time+"</DAV:timeout>";
+ }
+}
+
+
+function Collection() {
+ /* Implementation of collection XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.2
+ */
+}
+
+Collection.prototype = {
+ serialize: function() {
+ return "<DAV:collection />";
+ }
+}
+
+
+function Href(href) {
+ /* Implementation of href XML Element.
+
+ See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.3
+ */
+ this.href = href;
+}
+
+Href.prototype = {
+ serialize: function() {
+ return "<DAV:href>"+this.href+"</DAV:href>";
+ }
+}
+
function Prop(ns) {
/* Implementation of prop XML Element.
@@ -330,13 +482,12 @@
addProperty: function(name) {
this.properties[this.properties.length] = name;
},
-
- serialize: function(ns) {
- xml = ' <DAV:prop xmlns:'+ns+'="'+this.namespace+'">\n';
+ createXML: function(parent, doc) {
+ node = doc.createElementNS('DAV:', 'prop');
for (var index = 0; index < this.properties.length; index++)
- xml += ' <'+ns+':'+this.properties[index]+' />\n';
- xml += ' </DAV:prop>\n';
- return xml;
+ node.appendChild(doc.createElementNS(this.namespace,
+ this.properties[index]));
+ parent.appendChild(node);
}
}
@@ -368,21 +519,27 @@
this.propname = true;
},
- serialize: function() {
- xml = '<DAV:propfind xmlns:DAV="DAV:">\n';
+ createXML: function() {
+ doc = document.implementation.createDocument("DAV:", "propfind",
+ null);
+ node = doc.documentElement
+
if (this.allprop == true)
- xml += ' <DAV:allprop />\n';
+ node.appendChild(doc.createElementNS('DAV:', 'allprop'));
if (this.propname == true)
- xml += ' <DAV:propname />\n';
+ node.appendChild(doc.createElementNS('DAV:', 'propname'));
if (this.props.length > 0) {
for (var index = 0; index < this.props.length; index++)
- xml += this.props[index].serialize('PROP'+index);
+ xml += this.props[index].createXML(node, doc);
}
-
- xml += '</DAV:propfind>\n';
- return xml;
+ return doc;
+ },
+ serialize: function() {
+ var doc = this.createXML();
+ var serializer = new XMLSerializer();
+ return serializer.serializeToString(doc);
}
}