Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Working PUT

  • Loading branch information...
commit 6a5fe7569938aea2e41da3733cd0b894ddc8518d 1 parent 30c5853
Aslak Hellesøy authored
1,948  jsdav.js
... ...
@@ -1,1948 +0,0 @@
1  
-/******************************************************************************
2  
-* Version: MPL 1.1
3  
-*
4  
-* The contents of this file are subject to the Mozilla Public License Version
5  
-* 1.1 (the "License"); you may not use this file except in compliance with
6  
-* the License. You may obtain a copy of the License at
7  
-* http://www.mozilla.org/MPL/
8  
-*
9  
-* Software distributed under the License is distributed on an "AS IS" basis,
10  
-* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  
-* for the specific language governing rights and limitations under the
12  
-* License.
13  
-*
14  
-* The Original Code is Twingle.
15  
-*
16  
-* The Initial Developer of the Original Code is Paul Everitt.
17  
-* Portions created by the Initial Developer are Copyright (C) 2003
18  
-* the Initial Developer. All Rights Reserved.
19  
-*
20  
-* Contributor(s): Stephan Richter
21  
-*
22  
-******************************************************************************
23  
-WebDAV specific methods.
24  
-
25  
-Features:
26  
-
27  
-  PROPFIND
28  
-
29  
-    - Responses are received and parsed.
30  
-
31  
-    - propfind XML is completely generatable using object tree.
32  
-
33  
-  PROPPATCH
34  
-
35  
-    - Responses received and parsed
36  
-
37  
-    - propertyupdate XML is completely generatable using object tree.
38  
-
39  
-  MKCOL
40  
-
41  
-    - Creates new collection (folder/directory/container).
42  
-
43  
-  GET
44  
-
45  
-    - Returns the request text
46  
-
47  
-  HEAD
48  
-
49  
-    - Returns the request object, so that headers can be looked up individually.
50  
-
51  
-  OPTIONS
52  
-
53  
-    - Check the supportion operations on the server.
54  
-
55  
-  DELETE
56  
-
57  
-    - Deletes resource on server and returns properly.
58  
-
59  
-  COPY
60  
-
61  
-    - Server copies objects.
62  
-
63  
-    - Depth, Overwrite Headers implemented.
64  
-
65  
-  MOVE
66  
-
67  
-    - Server moves objects.
68  
-
69  
-    - Depth, Overwrite Headers implemented.
70  
-
71  
-
72  
-To do:
73  
-
74  
-  PROPFIND
75  
-
76  
-    - Handle negative responses.
77  
-
78  
-  PROPPATCH
79  
-
80  
-    - Handle negative responses.
81  
-
82  
-  MKCOL
83  
-
84  
-    - Supposely, MKCOL should allow its body to be some sort of XML. But the
85  
-      specs do not tell us how this should look like. Does anyone have a clue?
86  
-
87  
-  GET
88  
-
89  
-    - Handle failures and errors.
90  
-
91  
-  HEAD
92  
-
93  
-    - Should generate an array of all header names and values.
94  
-
95  
-    - Handle failures.
96  
-
97  
-  DELETE
98  
-
99  
-    - Handle errors approriately.
100  
-
101  
-  COPY
102  
-
103  
-    - Handle errors approriately.
104  
-
105  
-  MOVE
106  
-
107  
-    - Handle errors approriately.
108  
-
109  
-  LOCK
110  
-
111  
-    - Implement Handler.
112  
-
113  
-    - Implement Timeout header.
114  
-
115  
-    - Implement Authorization header.
116  
-
117  
-    - Implement If header.
118  
-
119  
-  UNLOCK
120  
-
121  
-    - Implement Handler.
122  
-
123  
-    - Implement Lock-Token Header.
124  
-
125  
-$Id: jsdav.js,v 1.5 2006/10/29 18:04:46 dayala Exp $
126  
-
127  
-******************************************************************************/
128  
-
129  
-// Some constants
130  
-const DAV_RESOURCE_DEPTH = '0';
131  
-const DAV_CHILDREN_DEPTH = '1';
132  
-const DAV_INFINITY_DEPTH = 'infinity';
133  
-
134  
-const DAV_TIMETYPE_SECOND = 'Second-';
135  
-const DAV_TIMETYPE_INFINITE = 'Infinite';
136  
-const DAV_TIMETYPE_EXTEND = 'Extend';
137  
-
138  
-const DAV_SHARED_LOCKSCOPE = 'shared';
139  
-const DAV_EXCLUSIVE_LOCKSCOPE = 'exclusive';
140  
-
141  
-const DAV_WRITE_LOCKTYPE = 'write';
142  
-
143  
-const xml_decl = '<?xml version="1.0" encoding="utf-8" ?>\n';
144  
-
145  
-/* WebDAV Status Code Extensions
146  
-
147  
-   See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-10
148  
-*/
149  
-var statusCodes = new Array();
150  
-statusCodes[102] = 'Processing';
151  
-statusCodes[207] = 'Multi-Status';
152  
-statusCodes[422] = 'Unprocessable Entity';
153  
-statusCodes[423] = 'Locked';
154  
-statusCodes[424] = 'Failed Dependency';
155  
-statusCodes[507] = 'Insufficient Storage';
156  
-
157  
-
158  
-function serialize(xml) {
159  
-    var serializer = new XMLSerializer();
160  
-    var doc = document.implementation.createDocument("DAV:", "dummy", null);
161  
-    var node = doc.documentElement;
162  
-    xml.createXML(node, doc);
163  
-    return xml_decl + serializer.serializeToString(node.firstChild);
164  
-}
165  
-
166  
-
167  
-function DavClient() {
168  
-    /* This library intends to be a complete implementation of the WebDAV RFC.
169  
-
170  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.6
171  
-    */
172  
-    this.request = new XMLHttpRequest();
173  
-}
174  
-
175  
-/* Define read-only responseObjects attribute that contains an object tree of
176  
-   the returned XML.
177  
-*/
178  
-DavClient.prototype.__defineGetter__(
179  
-    'responseObjects',
180  
-		function() {
181  
-			if (this.request.responseXML) {
182  
-				status = new DavMultiStatus();
183  
-				status.parseXML(this.request.responseXML.documentElement);
184  
-				return status;
185  
-			}
186  
-			return undefined;
187  
-		}
188  
-);
189  
-
190  
-DavClient.prototype.PROPFIND = function(url, propfind, depth) {
191  
-    /* Implementation of WebDAV command PROPFIND.
192  
-
193  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.1
194  
-    */
195  
-
196  
-    // Make sure we have a URL
197  
-    if (!url)
198  
-	throw new Error("You must supply a URL.");
199  
-
200  
-    // Prepare the request
201  
-    this.request.open("PROPFIND", url);
202  
-    this.request.setRequestHeader("Content-type", "text/xml");
203  
-
204  
-    // look for optional Depth Header
205  
-    if (!depth)
206  
-       depth = 0;
207  
-
208  
-    this.request.setRequestHeader('Depth', this.createDepthHeader(depth))
209  
-
210  
-    // request body optional (if not, all names and values are returned)
211  
-    if (!propfind)
212  
-	this.request.send("");
213  
-    else
214  
-	this.request.send(serialize(propfind));
215  
-
216  
-    return;
217  
-}
218  
-
219  
-
220  
-DavClient.prototype.PROPPATCH = function(url, propertyupdate) {
221  
-    /* Implementation of WebDAV command PROPPATCH.
222  
-
223  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.2
224  
-    */
225  
-    // Make sure we have a URL
226  
-    if (!url)
227  
-	throw new Error("You must supply a URL.");
228  
-
229  
-    this.request.open("PROPPATCH", url);
230  
-    this.request.setRequestHeader("Content-type", "text/xml");
231  
-    this.request.send(serialize(propertyupdate));
232  
-}
233  
-
234  
-
235  
-DavClient.prototype.MKCOL = function(url) {
236  
-    /* Implementation of WebDAV command MKCOL.
237  
-
238  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.3
239  
-    */
240  
-    // Make sure we have a URL
241  
-    if (!url)
242  
-	throw new Error("You must supply a URL.");
243  
-
244  
-    this.request.open("MKCOL", url);
245  
-    this.request.setRequestHeader("Content-type", "text/xml");
246  
-    // XXX: Supposely a message body is possible, but the specs were
247  
-    //      incredibly unclear about the form of the message
248  
-    this.request.send("");
249  
-}
250  
-
251  
-
252  
-DavClient.prototype.GET = function(url) {
253  
-    /* Implementation of WebDAV command GET.
254  
-
255  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
256  
-    */
257  
-    // Make sure we have a URL
258  
-    if (!url)
259  
-	throw new Error("You must supply a URL.");
260  
-
261  
-    this.request.open("GET", url);
262  
-    this.request.setRequestHeader("Content-type", "text/xml");
263  
-    this.request.send("");
264  
-}
265  
-
266  
-
267  
-DavClient.prototype.HEAD = function(url) {
268  
-    /* Implementation of WebDAV command HEAD.
269  
-
270  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
271  
-    */
272  
-    // Make sure we have a URL
273  
-    if (!url)
274  
-	throw new Error("You must supply a URL.");
275  
-
276  
-    this.request.open("HEAD", url);
277  
-    this.request.setRequestHeader("Content-type", "text/xml");
278  
-    this.request.send("");
279  
-}
280  
-
281  
-
282  
-DavClient.prototype.OPTIONS = function(url) {
283  
-    /* Implementation of WebDAV command OPTIONS.
284  
-
285  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html
286  
-    */
287  
-    // Make sure we have a URL
288  
-    if (!url)
289  
-	throw new Error("You must supply a URL.");
290  
-
291  
-    this.request.open("OPTIONS", url);
292  
-    this.request.send("");
293  
-}
294  
-
295  
-
296  
-DavClient.prototype.POST = function(url, content, headers) {
297  
-    /* Implementation of WebDAV command POST.
298  
-
299  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.5
300  
-    */
301  
-    if (!url)
302  
-	throw new Error("You must supply a URL.");
303  
-
304  
-}
305  
-
306  
-
307  
-DavClient.prototype.DELETE = function(url) {
308  
-    /* Implementation of WebDAV command DELETE.
309  
-
310  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.6
311  
-
312  
-       - Must act as depth=infinity (but no Depth header)
313  
-    */
314  
-    if (!url)
315  
-	throw new Error("You must supply a URL.");
316  
-
317  
-    this.request.open("DELETE", url);
318  
-    this.request.setRequestHeader("Content-type", "text/xml");
319  
-    this.request.send("");
320  
-}
321  
-
322  
-
323  
-DavClient.prototype.PUT = function(url, content) {
324  
-    /* Implementation of WebDAV command PUT.
325  
-
326  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.7
327  
-       and http://asg.web.cmu.edu/rfc/rfc2068.html#sec-9.6
328  
-    */
329  
-    if (!url)
330  
-	throw new Error("You must supply a URL.");
331  
-
332  
-    this.request.open("PUT", url);
333  
-    this.request.setRequestHeader("Content-type", "text/xml");
334  
-    this.request.send(content);
335  
-}
336  
-
337  
-
338  
-DavClient.prototype.COPY = function(url, dest, behavior, depth, overwrite) {
339  
-    /* Implementation of WebDAV command COPY.
340  
-
341  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.8
342  
-    */
343  
-    if (!url)
344  
-	throw new Error("You must supply a URL.");
345  
-
346  
-    this.request.open("COPY", url);
347  
-    this.request.setRequestHeader("Content-type", "text/plain");
348  
-    this.request.setRequestHeader("Destination",
349  
-			     this.createDestinationHeader(dest));
350  
-    // Set Overwrite header
351  
-    if (!overwrite)
352  
-	this.request.setRequestHeader('Overwrite',
353  
-				 this.createOverwriteHeader(overwrite));
354  
-    // Set Depth header
355  
-    if (!depth)
356  
-	this.request.setRequestHeader('Depth',
357  
-				 this.createDepthHeader(depth));
358  
-
359  
-    // Send request
360  
-    if (!behavior)
361  
-	this.request.send("");
362  
-    else
363  
-	this.request.send(behavior.createXML());
364  
-}
365  
-
366  
-
367  
-DavClient.prototype.MOVE = function(url, dest, behavior, depth, overwrite) {
368  
-   /* Implementation of WebDAV command MOVE.
369  
-
370  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.9
371  
-    */
372  
-    if (!url)
373  
-	throw new Error("You must supply a URL.");
374  
-
375  
-    this.request.open("MOVE", url);
376  
-    this.request.setRequestHeader("Content-type", "text/xml");
377  
-    this.request.setRequestHeader("Destination",
378  
-			     this.createDestinationHeader(dest));
379  
-    // Set Overwrite header
380  
-    if (!overwrite)
381  
-	this.request.setRequestHeader('Overwrite',
382  
-				 this.createOverwriteHeader(overwrite));
383  
-    // Set Depth header
384  
-    if (!depth)
385  
-	this.request.setRequestHeader('Depth',
386  
-				 this.createDepthHeader(depth));
387  
-
388  
-    // Send request
389  
-    if (!behavior)
390  
-	this.request.send("");
391  
-    else
392  
-	this.request.send(behavior.createXML());
393  
-}
394  
-
395  
-
396  
-DavClient.prototype.LOCK = function(url, lockinfo, authorization,
397  
-				    ifclause, depth, callback) {
398  
-    /* Implementation of WebDAV command LOCK.
399  
-
400  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.10
401  
-    */
402  
-    if (!url)
403  
-	throw new Error("You must supply a URL.");
404  
-
405  
-    this.request.open("LOCK", url);
406  
-    this.request.setRequestHeader("Content-type", "text/xml");
407  
-
408  
-    // Set Depth header
409  
-    if (!depth)
410  
-	this.request.setRequestHeader('Depth',
411  
-				 this.createDepthHeader(depth));
412  
-
413  
-    // Send request
414  
-    this.request.send(lockinfo.createXML());
415  
-}
416  
-
417  
-
418  
-DavClient.prototype.UNLOCK = function(url) {
419  
-    /* Implementation of WebDAV command UNLOCK.
420  
-
421  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.11
422  
-    */
423  
-    if (!url)
424  
-	throw new Error("You must supply a URL.");
425  
-
426  
-    this.request.open("UNLOCK", url);
427  
-    this.request.setRequestHeader("Content-type", "text/xml");
428  
-    this.request.send(lockinfo.createXML());
429  
-}
430  
-
431  
-
432  
-DavClient.prototype.createDAVHeader = function(classes) {
433  
-    /* Creates a DAV Header.
434  
-
435  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.1
436  
-
437  
-      Example: 'DAV:1,2'
438  
-    */
439  
-    var header = "";
440  
-    for (var index = 0; index < classes.length; index++) {
441  
-	header += classes[index];
442  
-	if (index != classes[length])
443  
-	    header += ",";
444  
-    }
445  
-    return header;
446  
-}
447  
-
448  
-
449  
-DavClient.prototype.createDepthHeader = function(depth) {
450  
-    /* Creates a Depth Header.
451  
-
452  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.2
453  
-    */
454  
-    // XXX: Check for correct depth and raise exception if necessary
455  
-    return depth;
456  
-}
457  
-
458  
-DavClient.prototype.createDestinationHeader = function(absoluteURI) {
459  
-    /* Creates a Destination Header.
460  
-
461  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.3
462  
-    */
463  
-    return absoluteURI;
464  
-}
465  
-
466  
-
467  
-DavClient.prototype.createIfHeader = function() {
468  
-    /* Creates a If Header.
469  
-
470  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.4
471  
-    */
472  
-
473  
-}
474  
-
475  
-
476  
-DavClient.prototype.createLockTokenHeader = function(codedURL) {
477  
-    /* Creates a Lock-Token Header.
478  
-
479  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.5
480  
-    */
481  
-    return codedURL;
482  
-}
483  
-
484  
-
485  
-DavClient.prototype.createOverwriteHeader = function(bool) {
486  
-    /* Creates an Overwrite Header.
487  
-
488  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.6
489  
-    */
490  
-    if (bool == true)
491  
-	return "T";
492  
-    else
493  
-	return "F";
494  
-}
495  
-
496  
-
497  
-DavClient.prototype.handleStatusURIHeader = function(header) {
498  
-    /* Handle a Status-URI Response Header.
499  
-
500  
-      See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.7
501  
-    */
502  
-    // Should return statusCode and CodedURL
503  
-
504  
-}
505  
-
506  
-
507  
-DavClient.prototype.createTimeoutHeader = function(unit, value) {
508  
-    /* Creates an Timeout Request Header.
509  
-
510  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.8
511  
-    */
512  
-    return unit+'-'+value;
513  
-}
514  
-
515  
-
516  
-/* Data structure for the DAV XML Elements */
517  
-
518  
-function DavActiveLock(scope, type, depth, owner, timeout, locktoken) {
519  
-    /* Implementation of activelock XML Element.
520  
-
521  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1
522  
-    */
523  
-    this.lockscope = scope || null;
524  
-    this.locktype = type || null;
525  
-    this.depth = depth || null;
526  
-    this.owner = owner || null;
527  
-    this.timeout = timeout || null;
528  
-    this.locktoken = locktoken || null;
529  
-}
530  
-
531  
-
532  
-DavActiveLock.prototype = {
533  
-    getLockScope: function() {
534  
-	return this.lockscope;
535  
-    },
536  
-    getLockType: function() {
537  
-	return this.locktype;
538  
-    },
539  
-    getDepth: function() {
540  
-	return this.depth;
541  
-    },
542  
-    getOwner: function() {
543  
-	return this.owner;
544  
-    },
545  
-    getTimeout: function() {
546  
-	return this.timeout;
547  
-    },
548  
-    getLockToken: function() {
549  
-	return this.locktoken;
550  
-    },
551  
-    setLockScope: function(scope) {
552  
-	this.lockscope = scope;
553  
-    },
554  
-    setLockType: function(type) {
555  
-	this.locktype = type;
556  
-    },
557  
-    setDepth: function(depth) {
558  
-	this.depth = depth;
559  
-    },
560  
-    setOwner: function(owner) {
561  
-	this.owner = owner;
562  
-    },
563  
-    setTimeout: function(timeout) {
564  
-	this.timeout = timeout;
565  
-    },
566  
-    setLockToken: function(token) {
567  
-	this.locktoken = token;
568  
-    },
569  
-    parseXML: function(node) {
570  
-	this.xmlNode = node;
571  
-	for (var index = 0; index < node.childNodes.length; index++) {
572  
-	    sub = node.childNodes[index];
573  
-	    if (sub.localName == 'lockscope') {
574  
-		this.lockscope = new DavLockScope();
575  
-		this.lockscope.parseXML(sub);
576  
-	    }
577  
-	    if (sub.localName == 'locktype') {
578  
-		this.locktype = new DavLockType();
579  
-		this.locktype.parseXML(sub);
580  
-	    }
581  
-	    if (sub.localName == 'depth') {
582  
-		this.depth = new DavDepth();
583  
-		this.depth.parseXML(sub);
584  
-	    }
585  
-	    if (sub.localName == 'owner') {
586  
-		this.owner = new DavOwner();
587  
-		this.owner.parseXML(sub);
588  
-	    }
589  
-	    if (sub.localName == 'timeout') {
590  
-		this.timeout = new DavTimeout();
591  
-		this.timeout.parseXML(sub);
592  
-	    }
593  
-	    if (sub.localName == 'locktoken') {
594  
-		this.locktoken = new DavLockToken();
595  
-		this.locktoken.parseXML(sub);
596  
-	    }
597  
-	}
598  
-
599  
-    },
600  
-    createXML: function(parent, doc) {
601  
-	var node = doc.createElementNS('DAV:', 'activelock');
602  
-	parent.appendChild(node);
603  
-	node.appendChild(this.lockscope.createXML(node, doc));
604  
-	node.appendChild(this.locktype.createXML(node, doc));
605  
-	node.appendChild(this.depth.createXML(node, doc));
606  
-	node.appendChild(this.owner.createXML(node, doc));
607  
-	node.appendChild(this.timeout.createXML(node, doc));
608  
-	node.appendChild(this.locktoken.createXML(node, doc));
609  
-    }
610  
-}
611  
-
612  
-function DavDepth(value) {
613  
-    /* Implementation of depth XML Element.
614  
-
615  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.1
616  
-    */
617  
-    // The default value should be the simple resource depth '0'
618  
-    if (!value)
619  
-	value = DAV_RESOURCE_DEPTH;
620  
-    this.setValue(value);
621  
-}
622  
-
623  
-DavDepth.prototype = {
624  
-    getValue: function() {
625  
-	return this.value;
626  
-    },
627  
-    setValue: function(value) {
628  
-	if (value in [DAV_RESOURCE_DEPTH, DAV_CHILDREN_DEPTH,
629  
-		      DAV_INFINITY_DEPTH]) {
630  
-	    this.value = value;
631  
-        } else {
632  
-	    throw new DavInvalidDepthValueError(value);
633  
-	}
634  
-    },
635  
-    parseXML: function(node) {
636  
-	this.xmlNode = node;
637  
-	this.value = node.firstChild.nodeValue;
638  
-    },
639  
-    createXML: function(parent, doc) {
640  
-	var node = doc.createElementNS('DAV:', 'depth');
641  
-	parent.appendChild(node);
642  
-	node.appendChild(doc.createTextNode(this.value));
643  
-    }
644  
-}
645  
-
646  
-
647  
-function DavLockToken(href) {
648  
-    /* Implementation of locktoken XML Element.
649  
-
650  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.2
651  
-    */
652  
-    if (!href)
653  
-	href = null;
654  
-    this.setHref(href);
655  
-}
656  
-
657  
-DavLockToken.prototype = {
658  
-    getHref: function() {
659  
-	return this.href;
660  
-    },
661  
-    setHref: function(href) {
662  
-	if (typeof href == 'object') {
663  
-	    this.href = href;
664  
-	} else {
665  
-	    throw new DavWrongTypeError('object', typeof href);
666  
-	}
667  
-    },
668  
-    parseXML: function(node) {
669  
-	this.xmlNode = node;
670  
-	for (var index = 0; index < node.childNodes.length; index++) {
671  
-	    sub = node.childNodes[index];
672  
-	    if (sub.localName == 'href') {
673  
-		this.href = new DavHref();
674  
-		this.href.parseXML(sub)
675  
-	    }
676  
-	}
677  
-    },
678  
-    createXML: function(parent, doc) {
679  
-	var node = doc.createElementNS('DAV:', 'locktoken');
680  
-	parent.appendChild(node);
681  
-	this.href.createXML(node, doc);
682  
-    }
683  
-}
684  
-
685  
-
686  
-function DavTimeout(type, value) {
687  
-    /* Implementation of timeout XML Element.
688  
-
689  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.3
690  
-    */
691  
-    // Handle default behavior
692  
-    if (!type)
693  
-	type = DAV_TIMETYPE_SECOND;
694  
-
695  
-    this.setTimeout(type, value);
696  
-}
697  
-
698  
-DavTimeout.prototype = {
699  
-    getValue: function() {
700  
-	return this.value;
701  
-    },
702  
-    getType: function() {
703  
-	return this.type;
704  
-    },
705  
-    setTimeout: function(type, value) {
706  
-	this.type = type;
707  
-	if ((type == DAV_TIMETYPE_SECOND) && (typeof value != 'number'))
708  
-	    value = 0;
709  
-	if (type == DAV_TIMETYPE_INFINITE)
710  
-	    value = null;
711  
-	if ((type == DAV_TIMETYPE_EXTEND) && (typeof value != 'string'))
712  
-	    value = '';
713  
-	this.value = value;
714  
-    },
715  
-    parseXML: function(node) {
716  
-	this.xmlNode = node;
717  
-	var value_str = node.firstChild.nodeValue.split('-');
718  
-	this.unit = value_str[0];
719  
-	this.value = value_str[1];
720  
-    },
721  
-    createXML: function(parent, doc) {
722  
-	var node = doc.createElementNS('DAV:', 'timeout');
723  
-	parent.appendChild(node);
724  
-	value = this.value;
725  
-	if (value == null)
726  
-	    value = '';
727  
-	node.appendChild(doc.createTextNode(this.type+value));
728  
-    }
729  
-}
730  
-
731  
-
732  
-function DavCollection() {
733  
-    /* Implementation of collection XML Element.
734  
-
735  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.2
736  
-    */
737  
-}
738  
-
739  
-DavCollection.prototype = {
740  
-    parseXML: function(node) {
741  
-	this.xmlNode = node;
742  
-    },
743  
-    createXML: function(parent, doc) {
744  
-	var node = doc.createElementNS('DAV:', 'collection');
745  
-	parent.appendChild(node);
746  
-    }
747  
-}
748  
-
749  
-
750  
-function DavHref(url) {
751  
-    /* Implementation of href XML Element.
752  
-
753  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.3
754  
-    */
755  
-    if (!url)
756  
-	url = null;
757  
-    this.url = url;
758  
-}
759  
-
760  
-DavHref.prototype = {
761  
-    getURL: function() {
762  
-	return this.url;
763  
-    },
764  
-    setURL: function(url) {
765  
-	this.url = url;
766  
-    },
767  
-    parseXML: function(node) {
768  
-	this.xmlNode = node;
769  
-	this.url = node.firstChild.nodeValue
770  
-    },
771  
-    createXML: function(parent, doc) {
772  
-	var node = doc.createElementNS('DAV:', 'href');
773  
-	node.appendChild(doc.createTextNode(this.url));
774  
-	parent.appendChild(node);
775  
-    }
776  
-}
777  
-
778  
-
779  
-function DavLink() {
780  
-    /* Implementation of link XML Element.
781  
-
782  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4
783  
-    */
784  
-    this.sources = new Array();
785  
-    this.destinations = new Array();
786  
-}
787  
-
788  
-DavLink.prototype = {
789  
-    getSources: function() {
790  
-	return this.sources;
791  
-    },
792  
-    addSource: function(src) {
793  
-	this.sources[this.sources.length] = src;
794  
-    },
795  
-    getDestinations: function() {
796  
-	return this.sources;
797  
-    },
798  
-    addDestination: function(dst) {
799  
-	this.destinations[this.destinations.length] = dst;
800  
-    },
801  
-    parseXML: function(node) {
802  
-	this.xmlNode = node;
803  
-	for (var index = 0; index < node.childNodes.length; index++) {
804  
-	    sub = node.childNodes[index];
805  
-	    if (sub.localName == 'src') {
806  
-		src = new DavSrc();
807  
-		src.parseXML(sub);
808  
-		this.sources[this.sources.length] = src;
809  
-	    }
810  
-	    if (sub.localName == 'dst') {
811  
-		dst = new DavDst();
812  
-		dst.parseXML(sub);
813  
-		this.destinations[this.destinations.length] = dst;
814  
-	    }
815  
-	}
816  
-    },
817  
-    createXML: function(parent, doc) {
818  
-	var node = doc.createElementNS('DAV:', 'link');
819  
-	var index;
820  
-	for (index = 0; index < this.sources.length; index++) {
821  
-	    this.sources[index].createXML(node, doc);
822  
-	}
823  
-	for (index = 0; index < this.destinations.length; index++) {
824  
-	    this.destinations[index].createXML(node, doc);
825  
-	}
826  
-	parent.appendChild(node);
827  
-    }
828  
-}
829  
-
830  
-
831  
-function DavDst(url) {
832  
-    /* Implementation of dst XML Element.
833  
-
834  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4.1
835  
-    */
836  
-    if (!url)
837  
-	url = null;
838  
-    this.url = url;
839  
-}
840  
-
841  
-DavDst.prototype = {
842  
-    getURL: function() {
843  
-	return this.url;
844  
-    },
845  
-    setURL: function(url) {
846  
-	this.url = url;
847  
-    },
848  
-    parseXML: function(node) {
849  
-	this.xmlNode = node;
850  
-	this.url = node.firstChild.nodeValue
851  
-    },
852  
-    createXML: function(parent, doc) {
853  
-	var node = doc.createElementNS('DAV:', 'dst');
854  
-	node.appendChild(doc.createTextNode(this.url));
855  
-	parent.appendChild(node);
856  
-    }
857  
-}
858  
-
859  
-
860  
-function DavSrc(url) {
861  
-    /* Implementation of src XML Element.
862  
-
863  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4.2
864  
-    */
865  
-    if (!url)
866  
-	url = null;
867  
-    this.url = url;
868  
-}
869  
-
870  
-DavSrc.prototype = {
871  
-    getURL: function() {
872  
-	return this.url;
873  
-    },
874  
-    setURL: function(url) {
875  
-	this.url = url;
876  
-    },
877  
-    parseXML: function(node) {
878  
-	this.xmlNode = node;
879  
-	this.url = node.firstChild.nodeValue
880  
-    },
881  
-    createXML: function(parent, doc) {
882  
-	var node = doc.createElementNS('DAV:', 'src');
883  
-	node.appendChild(doc.createTextNode(this.url));
884  
-	parent.appendChild(node);
885  
-    }
886  
-}
887  
-
888  
-
889  
-function DavLockEntry(scope, type) {
890  
-    /* Implementation of lockentry XML Element.
891  
-
892  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.5
893  
-    */
894  
-    if (!scope)
895  
-	scope = new DavLockScope();
896  
-    if (!type)
897  
-	type = new DavLockType();
898  
-    this.setLockScope(scope);
899  
-    this.setLockType(type);
900  
-}
901  
-
902  
-DavLockEntry.prototype = {
903  
-    getLockScope: function() {
904  
-	return this.lockscope;
905  
-	    },
906  
-    getLockType: function() {
907  
-	return this.locktype;
908  
-	    },
909  
-    setLockScope: function(scope) {
910  
-	this.lockscope = scope;
911  
-	    },
912  
-    setLockType: function(type) {
913  
-	this.locktype = type;
914  
-	    },
915  
-    parseXML: function(node) {
916  
-	this.xmlNode = node;
917  
-	for (var index = 0; index < node.childNodes.length; index++) {
918  
-	    sub = node.childNodes[index];
919  
-	    if (sub.localName == 'lockscope') {
920  
-		this.lockscope = new DavLockScope();
921  
-		this.lockscope.parseXML(sub);
922  
-	    }
923  
-	    if (sub.localName == 'locktype') {
924  
-		this.lockType = new DavLockType();
925  
-		this.lockType.parseXML(sub);
926  
-	    }
927  
-	}
928  
-
929  
-    },
930  
-    createXML: function(parent, doc) {
931  
-	var node = doc.createElementNS('DAV:', 'lockentry');
932  
-	this.lockscope.createXML(node, doc);
933  
-	this.locktype.createXML(node, doc);
934  
-	parent.appendChild(node);
935  
-    }
936  
-}
937  
-
938  
-
939  
-function DavLockInfo(scope, type, owner) {
940  
-    /* Implementation of lockinfo XML Element.
941  
-
942  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.6
943  
-    */
944  
-    this.lockscope = scope;
945  
-    this.locktype = type;
946  
-    this.owner = owner;
947  
-}
948  
-
949  
-DavLockInfo.prototype = {
950  
-    getLockScope: function() {
951  
-	return this.lockscope;
952  
-	    },
953  
-    getLockType: function() {
954  
-	return this.locktype;
955  
-	    },
956  
-    getOwner: function() {
957  
-	return this.owner;
958  
-    },
959  
-    setLockScope: function(scope) {
960  
-	this.lockscope = scope;
961  
-	    },
962  
-    setLockType: function(type) {
963  
-	this.locktype = type;
964  
-	    },
965  
-    setOwner: function(owner) {
966  
-	this.owner = owner;
967  
-    },
968  
-    parseXML: function(node) {
969  
-	this.xmlNode = node;
970  
-	for (var index = 0; index < node.childNodes.length; index++) {
971  
-	    sub = node.childNodes[index];
972  
-	    if (sub.localName == 'lockscope') {
973  
-		this.lockscope = new DavLockScope();
974  
-		this.lockscope.parseXML(sub);
975  
-	    }
976  
-	    if (sub.localName == 'locktype') {
977  
-		this.lockType = new DavLockType();
978  
-		this.lockType.parseXML(sub);
979  
-	    }
980  
-	    if (sub.localName == 'owner') {
981  
-		this.owner = new DavOwner();
982  
-		this.owner.parseXML(sub);
983  
-	    }
984  
-	}
985  
-
986  
-    },
987  
-    createXML: function() {
988  
-	var doc = document.implementation.createDocument("DAV:", "D:lockinfo",
989  
-						     null);
990  
-	var node = doc.documentElement;
991  
-	node.appendChild(this.lockscope.createXML(node, doc));
992  
-	node.appendChild(this.locktype.createXML(node, doc));
993  
-	node.appendChild(this.owner.createXML(node, doc));
994  
-	return doc
995  
-    }
996  
-}
997  
-
998  
-
999  
-function DavLockScope(scope) {
1000  
-    /* Implementation of lockscope XML Element.
1001  
-
1002  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.7
1003  
-    */
1004  
-    if (!scope)
1005  
-	scope = DAV_SHARED_LOCKSCOPE;
1006  
-    this.setScope(scope);
1007  
-}
1008  
-
1009  
-DavLockScope.prototype = {
1010  
-    getScope: function() {
1011  
-	return this.scope;
1012  
-    },
1013  
-    isExclusive: function() {
1014  
-	return this.scope == DAV_EXCLUSIVE_LOCKSCOPE;
1015  
-    },
1016  
-    isShared: function() {
1017  
-	return this.scope == DAV_SHARED_LOCKSCOPE;
1018  
-    },
1019  
-    setScope: function(scope) {
1020  
-	if ((scope == DAV_EXCLUSIVE_LOCKSCOPE) ||
1021  
-	    (scope == DAV_SHARED_LOCKSCOPE)) {
1022  
-	    this.scope = scope;
1023  
-	}
1024  
-	else
1025  
-	    throw new DavInvalidScopeValueError(scope);
1026  
-    },
1027  
-    parseXML: function(node) {
1028  
-	this.xmlNode = node;
1029  
-	this.scope = node.firstChild.localName;
1030  
-    },
1031  
-    createXML: function(parent, doc) {
1032  
-	var node = doc.createElementNS('DAV:', 'lockscope');
1033  
-	node.appendChild(doc.createElementNS('DAV:', this.scope));
1034  
-	parent.appendChild(node);
1035  
-    }
1036  
-}
1037  
-
1038  
-
1039  
-function DavLockType(type) {
1040  
-    /* Implementation of locktype XML Element.
1041  
-
1042  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.8
1043  
-    */
1044  
-    if (!type)
1045  
-	type = DAV_WRITE_LOCKTYPE;
1046  
-    this.setType(type);
1047  
-}
1048  
-
1049  
-DavLockType.prototype = {
1050  
-    getType: function() {
1051  
-	return this.type;
1052  
-    },
1053  
-    setType: function(type) {
1054  
-	if (type == DAV_WRITE_LOCKTYPE)
1055  
-	    this.type = type;
1056  
-	else
1057  
-	    DavInvalidLockTypeError(type);
1058  
-    },
1059  
-    isWrite: function() {
1060  
-	return this.type == DAV_WRITE_LOCKTYPE;
1061  
-    },
1062  
-    parseXML: function(node) {
1063  
-	this.xmlNode = node;
1064  
-	for (var index = 0; index < node.childNodes.length; index++) {
1065  
-	    sub = node.childNodes[index];
1066  
-	    if (sub.localName != null)
1067  
-		this.type = sub.localName;
1068  
-	}
1069  
-    },
1070  
-    createXML: function(parent, doc) {
1071  
-	var node = doc.createElementNS('DAV:', 'locktype');
1072  
-	node.appendChild(doc.createElementNS('DAV:', this.type));
1073  
-	parent.appendChild(node);
1074  
-    }
1075  
-}
1076  
-
1077  
-
1078  
-function DavMultiStatus() {
1079  
-    /* Implementation of multistatus XML Element.
1080  
-
1081  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9
1082  
-    */
1083  
-    this.responsedescription = "";
1084  
-    this.responses = new Array();
1085  
-}
1086  
-
1087  
-DavMultiStatus.prototype = {
1088  
-    getDescription: function() {
1089  
-	return this.responsedescription;
1090  
-	    },
1091  
-    getResponses: function() {
1092  
-	return this.responses;
1093  
-    },
1094  
-    parseXML: function(node) {
1095  
-	this.xmlNode = node;
1096  
-	for (var index=0; index < node.childNodes.length; index++) {
1097  
-	    sub = node.childNodes[index];
1098  
-	    if (sub.localName == 'responsrdescription') {
1099  
-		this.responsedescription = sub.firstChild.nodeValue
1100  
-	    }
1101  
-	    if (sub.localName == 'response') {
1102  
-		var resp = new DavResponse();
1103  
-		resp.parseXML(sub);
1104  
-		this.responses[this.responses.length] = resp;
1105  
-	    }
1106  
-	}
1107  
-
1108  
-    },
1109  
-    createXML: function(parent, doc) {
1110  
-
1111  
-    }
1112  
-}
1113  
-
1114  
-
1115  
-function DavResponse() {
1116  
-    /* Implementation of response XML Element.
1117  
-
1118  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9.1
1119  
-    */
1120  
-    this.responsedescription = "";
1121  
-    this.href = null;
1122  
-    this.propstats = new Array();
1123  
-}
1124  
-
1125  
-DavResponse.prototype = {
1126  
-    getDescription: function() {
1127  
-	return this.responsedescription;
1128  
-	    },
1129  
-    getHRef: function() {
1130  
-	return this.href;
1131  
-	    },
1132  
-    getPropStats: function() {
1133  
-	return this.propstats;
1134  
-    },
1135  
-
1136  
-    parseXML: function(node) {
1137  
-	this.xmlNode = node;
1138  
-	for (var index=0; index<node.childNodes.length; index++) {
1139  
-	    sub = node.childNodes[index];
1140  
-	    if (sub.localName == 'responsrdescription') {
1141  
-		this.responsrdescription = sub.firstChild.nodeValue
1142  
-	    }
1143  
-	    if (sub.localName == 'href') {
1144  
-		this.href = new DavHref();
1145  
-		this.href.parseXML(sub);
1146  
-	    }
1147  
-	    if (sub.localName == 'propstat') {
1148  
-	    	var stat = new DavPropStat();
1149  
-	    	stat.parseXML(sub);
1150  
-	    	this.propstats[this.propstats.length] = stat;
1151  
-	    }
1152  
-	}
1153  
-
1154  
-    },
1155  
-    createXML: function(parent, doc) {
1156  
-
1157  
-    }
1158  
-}
1159  
-
1160  
-function DavPropStat() {
1161  
-    /* Implementation of response XML Element.
1162  
-
1163  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9.2
1164  
-    */
1165  
-    this.responsedescription = "";
1166  
-    this.status = null;
1167  
-    this.prop = null;
1168  
-}
1169  
-
1170  
-DavPropStat.prototype = {
1171  
-    getDescription: function() {
1172  
-	return this.responsedescription;
1173  
-	    },
1174  
-    getStatus: function() {
1175  
-	return this.status;
1176  
-	    },
1177  
-    getProp: function() {
1178  
-	return this.prop;
1179  
-    },
1180  
-    parseXML: function(node) {
1181  
-	this.xmlNode = node;
1182  
-	for (var index = 0; index < node.childNodes.length; index++) {
1183  
-	    sub = node.childNodes[index];
1184  
-	    if (sub.localName == 'responsrdescription') {
1185  
-		this.responsrdescription = sub.firstChild.nodeValue
1186  
-	    }
1187  
-	    if (sub.localName == 'status') {
1188  
-		this.status = sub.firstChild.nodeValue
1189  
-	    }
1190  
-	    if (sub.localName == 'prop') {
1191  
-		this.prop = new DavProp();
1192  
-		this.prop.parseXML(sub);
1193  
-	    }
1194  
-	}
1195  
-
1196  
-    },
1197  
-    createXML: function(parent, doc) {
1198  
-    }
1199  
-}
1200  
-
1201  
-
1202  
-function DavOwner(name) {
1203  
-    /* Implementation of owner XML Element.
1204  
-
1205  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.10
1206  
-    */
1207  
-    this.name = name;
1208  
-}
1209  
-
1210  
-DavOwner.prototype = {
1211  
-    getName: function() {
1212  
-	return this.name
1213  
-    },
1214  
-    setName: function(name) {
1215  
-	this.name = name;
1216  
-    },
1217  
-    parseXML: function(node) {
1218  
-	this.xmlNode = node;
1219  
-	this.name = node.firstChild.nodeValue;
1220  
-    },
1221  
-    createXML: function(parent, doc) {
1222  
-	node = doc.createElementNS('DAV:', 'owner');
1223  
-	node.appendChild(doc.createTextNode(this.name));
1224  
-	parent.appendChild(node);
1225  
-    }
1226  
-}
1227  
-
1228  
-
1229  
-function DavProp() {
1230  
-    /* Implementation of prop XML Element.
1231  
-
1232  
-       See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.11
1233  
-    */
1234  
-    this.properties = new Array();
1235  
-}
1236  
-
1237  
-DavProp.prototype = {
1238  
-    getProperties: function() {
1239  
-	return this.properties;
1240  
-    },
1241  
-    addProperty: function(name) {
1242  
-	this.properties[this.properties.length] = name;
1243  
-    },
1244  
-    parseXML: function(node) {
1245  
-	this.xmlNode = node;
1246  
-	for (var index = 0; index < node.childNodes.length; index++) {
1247  
-	    sub = node.childNodes[index];
1248  
-	    if (sub.localName != null)
1249  
-		this.properties[this.properties.length] = sub.localName;
1250  
-	}