Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working PUT

  • Loading branch information...
commit 6a5fe7569938aea2e41da3733cd0b894ddc8518d 1 parent 30c5853
@aslakhellesoy authored
Showing with 18 additions and 2,359 deletions.
  1. +0 −1,948 jsdav.js
  2. +0 −405 mozileDataTransport.js
  3. +7 −3 spec/webdav_spec.js
  4. +11 −3 src/env.rhino.js
View
1,948 jsdav.js
@@ -1,1948 +0,0 @@
-/******************************************************************************
-* Version: MPL 1.1
-*
-* The contents of this file are subject to the Mozilla Public License Version
-* 1.1 (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS" basis,
-* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-* for the specific language governing rights and limitations under the
-* License.
-*
-* The Original Code is Twingle.
-*
-* The Initial Developer of the Original Code is Paul Everitt.
-* Portions created by the Initial Developer are Copyright (C) 2003
-* the Initial Developer. All Rights Reserved.
-*
-* Contributor(s): Stephan Richter
-*
-******************************************************************************
-WebDAV specific methods.
-
-Features:
-
- PROPFIND
-
- - Responses are received and parsed.
-
- - propfind XML is completely generatable using object tree.
-
- PROPPATCH
-
- - Responses received and parsed
-
- - propertyupdate XML is completely generatable using object tree.
-
- MKCOL
-
- - Creates new collection (folder/directory/container).
-
- GET
-
- - Returns the request text
-
- HEAD
-
- - Returns the request object, so that headers can be looked up individually.
-
- OPTIONS
-
- - Check the supportion operations on the server.
-
- DELETE
-
- - Deletes resource on server and returns properly.
-
- COPY
-
- - Server copies objects.
-
- - Depth, Overwrite Headers implemented.
-
- MOVE
-
- - Server moves objects.
-
- - Depth, Overwrite Headers implemented.
-
-
-To do:
-
- PROPFIND
-
- - Handle negative responses.
-
- PROPPATCH
-
- - Handle negative responses.
-
- MKCOL
-
- - Supposely, MKCOL should allow its body to be some sort of XML. But the
- specs do not tell us how this should look like. Does anyone have a clue?
-
- GET
-
- - Handle failures and errors.
-
- HEAD
-
- - Should generate an array of all header names and values.
-
- - Handle failures.
-
- DELETE
-
- - Handle errors approriately.
-
- COPY
-
- - Handle errors approriately.
-
- MOVE
-
- - Handle errors approriately.
-
- LOCK
-
- - Implement Handler.
-
- - Implement Timeout header.
-
- - Implement Authorization header.
-
- - Implement If header.
-
- UNLOCK
-
- - Implement Handler.
-
- - Implement Lock-Token Header.
-
-$Id: jsdav.js,v 1.5 2006/10/29 18:04:46 dayala Exp $
-
-******************************************************************************/
-
-// Some constants
-const DAV_RESOURCE_DEPTH = '0';
-const DAV_CHILDREN_DEPTH = '1';
-const DAV_INFINITY_DEPTH = 'infinity';
-
-const DAV_TIMETYPE_SECOND = 'Second-';
-const DAV_TIMETYPE_INFINITE = 'Infinite';
-const DAV_TIMETYPE_EXTEND = 'Extend';
-
-const DAV_SHARED_LOCKSCOPE = 'shared';
-const DAV_EXCLUSIVE_LOCKSCOPE = 'exclusive';
-
-const DAV_WRITE_LOCKTYPE = 'write';
-
-const xml_decl = '<?xml version="1.0" encoding="utf-8" ?>\n';
-
-/* WebDAV Status Code Extensions
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-10
-*/
-var statusCodes = new Array();
-statusCodes[102] = 'Processing';
-statusCodes[207] = 'Multi-Status';
-statusCodes[422] = 'Unprocessable Entity';
-statusCodes[423] = 'Locked';
-statusCodes[424] = 'Failed Dependency';
-statusCodes[507] = 'Insufficient Storage';
-
-
-function serialize(xml) {
- var serializer = new XMLSerializer();
- var doc = document.implementation.createDocument("DAV:", "dummy", null);
- var node = doc.documentElement;
- xml.createXML(node, doc);
- return xml_decl + serializer.serializeToString(node.firstChild);
-}
-
-
-function DavClient() {
- /* This library intends to be a complete implementation of the WebDAV RFC.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.6
- */
- this.request = new XMLHttpRequest();
-}
-
-/* Define read-only responseObjects attribute that contains an object tree of
- the returned XML.
-*/
-DavClient.prototype.__defineGetter__(
- 'responseObjects',
- function() {
- if (this.request.responseXML) {
- status = new DavMultiStatus();
- status.parseXML(this.request.responseXML.documentElement);
- return status;
- }
- return undefined;
- }
-);
-
-DavClient.prototype.PROPFIND = function(url, propfind, depth) {
- /* Implementation of WebDAV command PROPFIND.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.1
- */
-
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- // Prepare the request
- this.request.open("PROPFIND", url);
- this.request.setRequestHeader("Content-type", "text/xml");
-
- // look for optional Depth Header
- if (!depth)
- depth = 0;
-
- this.request.setRequestHeader('Depth', this.createDepthHeader(depth))
-
- // request body optional (if not, all names and values are returned)
- if (!propfind)
- this.request.send("");
- else
- this.request.send(serialize(propfind));
-
- return;
-}
-
-
-DavClient.prototype.PROPPATCH = function(url, propertyupdate) {
- /* Implementation of WebDAV command PROPPATCH.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.2
- */
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("PROPPATCH", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send(serialize(propertyupdate));
-}
-
-
-DavClient.prototype.MKCOL = function(url) {
- /* Implementation of WebDAV command MKCOL.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.3
- */
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("MKCOL", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- // XXX: Supposely a message body is possible, but the specs were
- // incredibly unclear about the form of the message
- this.request.send("");
-}
-
-
-DavClient.prototype.GET = function(url) {
- /* Implementation of WebDAV command GET.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
- */
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("GET", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send("");
-}
-
-
-DavClient.prototype.HEAD = function(url) {
- /* Implementation of WebDAV command HEAD.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
- */
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("HEAD", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send("");
-}
-
-
-DavClient.prototype.OPTIONS = function(url) {
- /* Implementation of WebDAV command OPTIONS.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html
- */
- // Make sure we have a URL
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("OPTIONS", url);
- this.request.send("");
-}
-
-
-DavClient.prototype.POST = function(url, content, headers) {
- /* Implementation of WebDAV command POST.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.5
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
-}
-
-
-DavClient.prototype.DELETE = function(url) {
- /* Implementation of WebDAV command DELETE.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.6
-
- - Must act as depth=infinity (but no Depth header)
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("DELETE", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send("");
-}
-
-
-DavClient.prototype.PUT = function(url, content) {
- /* Implementation of WebDAV command PUT.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.7
- and http://asg.web.cmu.edu/rfc/rfc2068.html#sec-9.6
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("PUT", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send(content);
-}
-
-
-DavClient.prototype.COPY = function(url, dest, behavior, depth, overwrite) {
- /* Implementation of WebDAV command COPY.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.8
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("COPY", url);
- this.request.setRequestHeader("Content-type", "text/plain");
- this.request.setRequestHeader("Destination",
- this.createDestinationHeader(dest));
- // Set Overwrite header
- if (!overwrite)
- this.request.setRequestHeader('Overwrite',
- this.createOverwriteHeader(overwrite));
- // Set Depth header
- if (!depth)
- this.request.setRequestHeader('Depth',
- this.createDepthHeader(depth));
-
- // Send request
- if (!behavior)
- this.request.send("");
- else
- this.request.send(behavior.createXML());
-}
-
-
-DavClient.prototype.MOVE = function(url, dest, behavior, depth, overwrite) {
- /* Implementation of WebDAV command MOVE.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.9
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("MOVE", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.setRequestHeader("Destination",
- this.createDestinationHeader(dest));
- // Set Overwrite header
- if (!overwrite)
- this.request.setRequestHeader('Overwrite',
- this.createOverwriteHeader(overwrite));
- // Set Depth header
- if (!depth)
- this.request.setRequestHeader('Depth',
- this.createDepthHeader(depth));
-
- // Send request
- if (!behavior)
- this.request.send("");
- else
- this.request.send(behavior.createXML());
-}
-
-
-DavClient.prototype.LOCK = function(url, lockinfo, authorization,
- ifclause, depth, callback) {
- /* Implementation of WebDAV command LOCK.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.10
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("LOCK", url);
- this.request.setRequestHeader("Content-type", "text/xml");
-
- // Set Depth header
- if (!depth)
- this.request.setRequestHeader('Depth',
- this.createDepthHeader(depth));
-
- // Send request
- this.request.send(lockinfo.createXML());
-}
-
-
-DavClient.prototype.UNLOCK = function(url) {
- /* Implementation of WebDAV command UNLOCK.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.11
- */
- if (!url)
- throw new Error("You must supply a URL.");
-
- this.request.open("UNLOCK", url);
- this.request.setRequestHeader("Content-type", "text/xml");
- this.request.send(lockinfo.createXML());
-}
-
-
-DavClient.prototype.createDAVHeader = function(classes) {
- /* Creates a DAV Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.1
-
- Example: 'DAV:1,2'
- */
- var header = "";
- for (var index = 0; index < classes.length; index++) {
- header += classes[index];
- if (index != classes[length])
- header += ",";
- }
- return header;
-}
-
-
-DavClient.prototype.createDepthHeader = function(depth) {
- /* Creates a Depth Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.2
- */
- // XXX: Check for correct depth and raise exception if necessary
- return depth;
-}
-
-DavClient.prototype.createDestinationHeader = function(absoluteURI) {
- /* Creates a Destination Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.3
- */
- return absoluteURI;
-}
-
-
-DavClient.prototype.createIfHeader = function() {
- /* Creates a If Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.4
- */
-
-}
-
-
-DavClient.prototype.createLockTokenHeader = function(codedURL) {
- /* Creates a Lock-Token Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.5
- */
- return codedURL;
-}
-
-
-DavClient.prototype.createOverwriteHeader = function(bool) {
- /* Creates an Overwrite Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.6
- */
- if (bool == true)
- return "T";
- else
- return "F";
-}
-
-
-DavClient.prototype.handleStatusURIHeader = function(header) {
- /* Handle a Status-URI Response Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.7
- */
- // Should return statusCode and CodedURL
-
-}
-
-
-DavClient.prototype.createTimeoutHeader = function(unit, value) {
- /* Creates an Timeout Request Header.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-9.8
- */
- return unit+'-'+value;
-}
-
-
-/* Data structure for the DAV XML Elements */
-
-function DavActiveLock(scope, type, depth, owner, timeout, locktoken) {
- /* Implementation of activelock XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1
- */
- this.lockscope = scope || null;
- this.locktype = type || null;
- this.depth = depth || null;
- this.owner = owner || null;
- this.timeout = timeout || null;
- this.locktoken = locktoken || null;
-}
-
-
-DavActiveLock.prototype = {
- getLockScope: function() {
- return this.lockscope;
- },
- getLockType: function() {
- return this.locktype;
- },
- getDepth: function() {
- return this.depth;
- },
- getOwner: function() {
- return this.owner;
- },
- getTimeout: function() {
- return this.timeout;
- },
- getLockToken: function() {
- return this.locktoken;
- },
- setLockScope: function(scope) {
- this.lockscope = scope;
- },
- setLockType: function(type) {
- this.locktype = type;
- },
- setDepth: function(depth) {
- this.depth = depth;
- },
- setOwner: function(owner) {
- this.owner = owner;
- },
- setTimeout: function(timeout) {
- this.timeout = timeout;
- },
- setLockToken: function(token) {
- this.locktoken = token;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'lockscope') {
- this.lockscope = new DavLockScope();
- this.lockscope.parseXML(sub);
- }
- if (sub.localName == 'locktype') {
- this.locktype = new DavLockType();
- this.locktype.parseXML(sub);
- }
- if (sub.localName == 'depth') {
- this.depth = new DavDepth();
- this.depth.parseXML(sub);
- }
- if (sub.localName == 'owner') {
- this.owner = new DavOwner();
- this.owner.parseXML(sub);
- }
- if (sub.localName == 'timeout') {
- this.timeout = new DavTimeout();
- this.timeout.parseXML(sub);
- }
- if (sub.localName == 'locktoken') {
- this.locktoken = new DavLockToken();
- this.locktoken.parseXML(sub);
- }
- }
-
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'activelock');
- parent.appendChild(node);
- node.appendChild(this.lockscope.createXML(node, doc));
- node.appendChild(this.locktype.createXML(node, doc));
- node.appendChild(this.depth.createXML(node, doc));
- node.appendChild(this.owner.createXML(node, doc));
- node.appendChild(this.timeout.createXML(node, doc));
- node.appendChild(this.locktoken.createXML(node, doc));
- }
-}
-
-function DavDepth(value) {
- /* Implementation of depth XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.1
- */
- // The default value should be the simple resource depth '0'
- if (!value)
- value = DAV_RESOURCE_DEPTH;
- this.setValue(value);
-}
-
-DavDepth.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- if (value in [DAV_RESOURCE_DEPTH, DAV_CHILDREN_DEPTH,
- DAV_INFINITY_DEPTH]) {
- this.value = value;
- } else {
- throw new DavInvalidDepthValueError(value);
- }
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'depth');
- parent.appendChild(node);
- node.appendChild(doc.createTextNode(this.value));
- }
-}
-
-
-function DavLockToken(href) {
- /* Implementation of locktoken XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.2
- */
- if (!href)
- href = null;
- this.setHref(href);
-}
-
-DavLockToken.prototype = {
- getHref: function() {
- return this.href;
- },
- setHref: function(href) {
- if (typeof href == 'object') {
- this.href = href;
- } else {
- throw new DavWrongTypeError('object', typeof href);
- }
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'href') {
- this.href = new DavHref();
- this.href.parseXML(sub)
- }
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'locktoken');
- parent.appendChild(node);
- this.href.createXML(node, doc);
- }
-}
-
-
-function DavTimeout(type, value) {
- /* Implementation of timeout XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.1.3
- */
- // Handle default behavior
- if (!type)
- type = DAV_TIMETYPE_SECOND;
-
- this.setTimeout(type, value);
-}
-
-DavTimeout.prototype = {
- getValue: function() {
- return this.value;
- },
- getType: function() {
- return this.type;
- },
- setTimeout: function(type, value) {
- this.type = type;
- if ((type == DAV_TIMETYPE_SECOND) && (typeof value != 'number'))
- value = 0;
- if (type == DAV_TIMETYPE_INFINITE)
- value = null;
- if ((type == DAV_TIMETYPE_EXTEND) && (typeof value != 'string'))
- value = '';
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- var value_str = node.firstChild.nodeValue.split('-');
- this.unit = value_str[0];
- this.value = value_str[1];
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'timeout');
- parent.appendChild(node);
- value = this.value;
- if (value == null)
- value = '';
- node.appendChild(doc.createTextNode(this.type+value));
- }
-}
-
-
-function DavCollection() {
- /* Implementation of collection XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.2
- */
-}
-
-DavCollection.prototype = {
- parseXML: function(node) {
- this.xmlNode = node;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'collection');
- parent.appendChild(node);
- }
-}
-
-
-function DavHref(url) {
- /* Implementation of href XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.3
- */
- if (!url)
- url = null;
- this.url = url;
-}
-
-DavHref.prototype = {
- getURL: function() {
- return this.url;
- },
- setURL: function(url) {
- this.url = url;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.url = node.firstChild.nodeValue
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'href');
- node.appendChild(doc.createTextNode(this.url));
- parent.appendChild(node);
- }
-}
-
-
-function DavLink() {
- /* Implementation of link XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4
- */
- this.sources = new Array();
- this.destinations = new Array();
-}
-
-DavLink.prototype = {
- getSources: function() {
- return this.sources;
- },
- addSource: function(src) {
- this.sources[this.sources.length] = src;
- },
- getDestinations: function() {
- return this.sources;
- },
- addDestination: function(dst) {
- this.destinations[this.destinations.length] = dst;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'src') {
- src = new DavSrc();
- src.parseXML(sub);
- this.sources[this.sources.length] = src;
- }
- if (sub.localName == 'dst') {
- dst = new DavDst();
- dst.parseXML(sub);
- this.destinations[this.destinations.length] = dst;
- }
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'link');
- var index;
- for (index = 0; index < this.sources.length; index++) {
- this.sources[index].createXML(node, doc);
- }
- for (index = 0; index < this.destinations.length; index++) {
- this.destinations[index].createXML(node, doc);
- }
- parent.appendChild(node);
- }
-}
-
-
-function DavDst(url) {
- /* Implementation of dst XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4.1
- */
- if (!url)
- url = null;
- this.url = url;
-}
-
-DavDst.prototype = {
- getURL: function() {
- return this.url;
- },
- setURL: function(url) {
- this.url = url;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.url = node.firstChild.nodeValue
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'dst');
- node.appendChild(doc.createTextNode(this.url));
- parent.appendChild(node);
- }
-}
-
-
-function DavSrc(url) {
- /* Implementation of src XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.4.2
- */
- if (!url)
- url = null;
- this.url = url;
-}
-
-DavSrc.prototype = {
- getURL: function() {
- return this.url;
- },
- setURL: function(url) {
- this.url = url;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.url = node.firstChild.nodeValue
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'src');
- node.appendChild(doc.createTextNode(this.url));
- parent.appendChild(node);
- }
-}
-
-
-function DavLockEntry(scope, type) {
- /* Implementation of lockentry XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.5
- */
- if (!scope)
- scope = new DavLockScope();
- if (!type)
- type = new DavLockType();
- this.setLockScope(scope);
- this.setLockType(type);
-}
-
-DavLockEntry.prototype = {
- getLockScope: function() {
- return this.lockscope;
- },
- getLockType: function() {
- return this.locktype;
- },
- setLockScope: function(scope) {
- this.lockscope = scope;
- },
- setLockType: function(type) {
- this.locktype = type;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'lockscope') {
- this.lockscope = new DavLockScope();
- this.lockscope.parseXML(sub);
- }
- if (sub.localName == 'locktype') {
- this.lockType = new DavLockType();
- this.lockType.parseXML(sub);
- }
- }
-
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'lockentry');
- this.lockscope.createXML(node, doc);
- this.locktype.createXML(node, doc);
- parent.appendChild(node);
- }
-}
-
-
-function DavLockInfo(scope, type, owner) {
- /* Implementation of lockinfo XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.6
- */
- this.lockscope = scope;
- this.locktype = type;
- this.owner = owner;
-}
-
-DavLockInfo.prototype = {
- getLockScope: function() {
- return this.lockscope;
- },
- getLockType: function() {
- return this.locktype;
- },
- getOwner: function() {
- return this.owner;
- },
- setLockScope: function(scope) {
- this.lockscope = scope;
- },
- setLockType: function(type) {
- this.locktype = type;
- },
- setOwner: function(owner) {
- this.owner = owner;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'lockscope') {
- this.lockscope = new DavLockScope();
- this.lockscope.parseXML(sub);
- }
- if (sub.localName == 'locktype') {
- this.lockType = new DavLockType();
- this.lockType.parseXML(sub);
- }
- if (sub.localName == 'owner') {
- this.owner = new DavOwner();
- this.owner.parseXML(sub);
- }
- }
-
- },
- createXML: function() {
- var doc = document.implementation.createDocument("DAV:", "D:lockinfo",
- null);
- var node = doc.documentElement;
- node.appendChild(this.lockscope.createXML(node, doc));
- node.appendChild(this.locktype.createXML(node, doc));
- node.appendChild(this.owner.createXML(node, doc));
- return doc
- }
-}
-
-
-function DavLockScope(scope) {
- /* Implementation of lockscope XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.7
- */
- if (!scope)
- scope = DAV_SHARED_LOCKSCOPE;
- this.setScope(scope);
-}
-
-DavLockScope.prototype = {
- getScope: function() {
- return this.scope;
- },
- isExclusive: function() {
- return this.scope == DAV_EXCLUSIVE_LOCKSCOPE;
- },
- isShared: function() {
- return this.scope == DAV_SHARED_LOCKSCOPE;
- },
- setScope: function(scope) {
- if ((scope == DAV_EXCLUSIVE_LOCKSCOPE) ||
- (scope == DAV_SHARED_LOCKSCOPE)) {
- this.scope = scope;
- }
- else
- throw new DavInvalidScopeValueError(scope);
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.scope = node.firstChild.localName;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'lockscope');
- node.appendChild(doc.createElementNS('DAV:', this.scope));
- parent.appendChild(node);
- }
-}
-
-
-function DavLockType(type) {
- /* Implementation of locktype XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.8
- */
- if (!type)
- type = DAV_WRITE_LOCKTYPE;
- this.setType(type);
-}
-
-DavLockType.prototype = {
- getType: function() {
- return this.type;
- },
- setType: function(type) {
- if (type == DAV_WRITE_LOCKTYPE)
- this.type = type;
- else
- DavInvalidLockTypeError(type);
- },
- isWrite: function() {
- return this.type == DAV_WRITE_LOCKTYPE;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName != null)
- this.type = sub.localName;
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'locktype');
- node.appendChild(doc.createElementNS('DAV:', this.type));
- parent.appendChild(node);
- }
-}
-
-
-function DavMultiStatus() {
- /* Implementation of multistatus XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9
- */
- this.responsedescription = "";
- this.responses = new Array();
-}
-
-DavMultiStatus.prototype = {
- getDescription: function() {
- return this.responsedescription;
- },
- getResponses: function() {
- return this.responses;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index=0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'responsrdescription') {
- this.responsedescription = sub.firstChild.nodeValue
- }
- if (sub.localName == 'response') {
- var resp = new DavResponse();
- resp.parseXML(sub);
- this.responses[this.responses.length] = resp;
- }
- }
-
- },
- createXML: function(parent, doc) {
-
- }
-}
-
-
-function DavResponse() {
- /* Implementation of response XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9.1
- */
- this.responsedescription = "";
- this.href = null;
- this.propstats = new Array();
-}
-
-DavResponse.prototype = {
- getDescription: function() {
- return this.responsedescription;
- },
- getHRef: function() {
- return this.href;
- },
- getPropStats: function() {
- return this.propstats;
- },
-
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index=0; index<node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'responsrdescription') {
- this.responsrdescription = sub.firstChild.nodeValue
- }
- if (sub.localName == 'href') {
- this.href = new DavHref();
- this.href.parseXML(sub);
- }
- if (sub.localName == 'propstat') {
- var stat = new DavPropStat();
- stat.parseXML(sub);
- this.propstats[this.propstats.length] = stat;
- }
- }
-
- },
- createXML: function(parent, doc) {
-
- }
-}
-
-function DavPropStat() {
- /* Implementation of response XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.9.2
- */
- this.responsedescription = "";
- this.status = null;
- this.prop = null;
-}
-
-DavPropStat.prototype = {
- getDescription: function() {
- return this.responsedescription;
- },
- getStatus: function() {
- return this.status;
- },
- getProp: function() {
- return this.prop;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'responsrdescription') {
- this.responsrdescription = sub.firstChild.nodeValue
- }
- if (sub.localName == 'status') {
- this.status = sub.firstChild.nodeValue
- }
- if (sub.localName == 'prop') {
- this.prop = new DavProp();
- this.prop.parseXML(sub);
- }
- }
-
- },
- createXML: function(parent, doc) {
- }
-}
-
-
-function DavOwner(name) {
- /* Implementation of owner XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.10
- */
- this.name = name;
-}
-
-DavOwner.prototype = {
- getName: function() {
- return this.name
- },
- setName: function(name) {
- this.name = name;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.name = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'owner');
- node.appendChild(doc.createTextNode(this.name));
- parent.appendChild(node);
- }
-}
-
-
-function DavProp() {
- /* Implementation of prop XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.11
- */
- this.properties = new Array();
-}
-
-DavProp.prototype = {
- getProperties: function() {
- return this.properties;
- },
- addProperty: function(name) {
- this.properties[this.properties.length] = name;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName != null)
- this.properties[this.properties.length] = sub.localName;
- }
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'prop');
- for (var index = 0; index < this.properties.length; index++) {
- this.properties[index].createXML(node, doc);
- }
- parent.appendChild(node);
- }
-}
-
-
-function Property(ns, name, value) {
- /* the prop XML Element can contain numerous properties and other dav
- elements. In order to simplify the life of the end user, we provide a
- simple way of adding new property fields to the prop element. */
-
- this.namespace = ns || 'DAV:';
- this.name = name || null;
- this.value = value || null;
-}
-
-Property.prototype = {
- getNamespace: function() {
- return this.namespace;
- },
- getName: function() {
- return this.name;
- },
- getValue: function() {
- return this.value;
- },
- setNamespace: function(ns) {
- this.namespace = ns;
- },
- setName: function(name) {
- this.name = name;
- },
- setValue: function(value) {
- this.value = value;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS(this.getNamespace(), this.getName());
-
- if (this.getValue())
- node.appendChild(doc.createTextNode(this.getValue()));
-
- parent.appendChild(node);
- }
-}
-
-
-
-function DavPropertyBehavior(rule) {
- /* Implementation of propertybehavior XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.12
- */
- this.rule = rule;
-}
-
-DavPropertyBehavior.prototype = {
- getRule: function() {
- return this.rule;
- },
- setRule: function(rule) {
- this.rule = rule;
- },
- getOmit: function() {
- if (this.rule instanceof Omit)
- return this.rule;
- return null;
- },
- getKeepAlive: function() {
- if (this.rule instanceof KeepAlive)
- return this.rule;
- return null;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'omit') {
- this.rule = new DavOmit();
- this.rule.parseXML(sub);
- }
- if (sub.localName == 'keepalive') {
- this.rule = new DavKeepAlive();
- this.rule.parseXML(sub);
- }
- }
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'propertybehavior');
- this.rule.createXML(node, doc);
- parent.appendChild(node);
- }
-}
-
-
-function DavKeepAlive(all, hrefs) {
- /* Implementation of keepalive XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.12.1
- */
- this.all = all;
- this.hrefs = hrefs;
-}
-
-DavKeepAlive.prototype = {
- isKeepingAllAlive: function() {
- return this.all;
- },
- addHref: function(href) {
- this.hrefs[this.hrefs.length] = href;
- },
- getHrefs: function() {
- return this.hrefs;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName != 'href') {
- href = new DavHref();
- href.parseXML(sub);
- this.hrefs[this.hrefs.length] = href;
- }
- if (sub.nodeValue != '*') {
- this.all = true;
- }
- }
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'propertybehavior');
- for (var index = 0; index < this.hrefs.length; index++)
- this.hrefs[index].createXML(node, doc);
- if (this.all == true)
- node.appendChild(doc.createTextNode("*"));
- parent.appendChild(node);
- }
-}
-
-
-function DavOmit() {
- /* Implementation of omit XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.12.2
- */
-}
-
-DavOmit.prototype = {
- parseXML: function(node) {
- this.xmlNode = node;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'omit');
- parent.appendChild(node);
- }
-}
-
-
-function DavPropertyUpdate() {
- /* Implementation of propertyupdate XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.13
- */
- this.removes = new Array();
- this.sets = new Array();
-}
-
-DavPropertyUpdate.prototype = {
- getRemoves: function() {
- return this.removes;
- },
- getSets: function() {
- return this.sets;
- },
- setRemove: function(remove) {
- this.removes[this.removes.length] = remove;
- },
- setSet: function(set) {
- this.sets[this.sets.length] = set;
- },
- removeProperty: function(prop) {
- this.setRemove(new DavRemove(prop));
- },
- setProperty: function(prop) {
- this.setSet(new DavSet(prop));
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'remove') {
- remove = new DavRemove();
- remove.parseXML(set);
- this.removes[this.removes.length] = remove;
- }
- if (sub.localName == 'set') {
- set = new DavSet();
- set.parseXML(set);
- this.sets[this.sets.length] = set;
- }
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS("DAV:", "propertyupdate");
- var index;
- for (index = 0; index < this.removes.length; index++)
- this.removes[index].createXML(node, doc);
- for (index = 0; index < this.sets.length; index++)
- this.sets[index].createXML(node, doc);
- parent.appendChild(node);
- }
-}
-
-function DavRemove(prop) {
- /* Implementation of remove XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.13.1
- */
- this.prop = prop;
-}
-
-DavRemove.prototype = {
- setProp: function(prop) {
- this.prop = prop;
- },
- getProp: function() {
- return this.prop;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.prop = new DavProp();
- this.prop.parseXML(node.firstChild);
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'remove');
- this.prop.createXML(node, doc);
- parent.appendChild(node);
- }
-}
-
-
-function DavSet(prop) {
- /* Implementation of set XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.13.2
- */
- this.prop = prop;
-}
-
-DavSet.prototype = {
- setProp: function(prop) {
- this.prop = prop;
- },
- getProp: function() {
- return this.prop;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.prop = new Prop();
- this.prop.parseXML(node.firstChild);
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'set');
- this.prop.createXML(node, doc);
- parent.appendChild(node);
- }
-}
-
-
-
-function DavPropFind() {
- /* Implementation of propfind XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-12.14
- */
- this.allprop = false;
- this.propname = false;
- this.props = new DavProp();
-}
-
-DavPropFind.prototype = {
- addProperty: function(prop) {
- if ((this.allprop == false) && (this.propname == false))
- this.props.addProperty(prop);
- },
-
- setAllProp: function() {
- if ((this.props.length == 0) && (this.propname == false))
- this.allprop = true;
- },
-
- setPropName: function() {
- if ((this.props.length == 0) && (this.allprop == false))
- this.propname = true;
- },
-
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'propfind');
- if (this.allprop == true)
- node.appendChild(doc.createElementNS('DAV:', 'D:allprop'));
-
- if (this.propname == true)
- node.appendChild(doc.createElementNS('DAV:', 'D:propname'));
-
- if (this.props.properties.length > 0) {
- this.props.createXML(node, doc);
- }
- parent.appendChild(node);
-
- }
-}
-
-
-function DavCreationDate(value) {
- /* Implementation of creationdate XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.1
- */
- this.value = value;
-}
-
-DavCreationDate.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'creationdate');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavDisplayName(value) {
- /* Implementation of displayname XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.2
- */
- this.value = value;
-}
-
-DavDisplayName.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'displayname');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavGetContentLanguage(value) {
- /* Implementation of getcontentlanguage XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.3
- */
- this.value = value;
-}
-
-DavGetContentLanguage.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'getcontentlanguage');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavGetContentLength(value) {
- /* Implementation of getcontentlength XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.4
- */
- this.value = value;
-}
-
-DavGetContentLength.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'getcontentlength');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavGetContentType(value) {
- /* Implementation of getcontenttype XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.5
- */
- this.value = value;
-}
-
-DavGetContentType.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'getcontenttype');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavGetEtag(value) {
- /* Implementation of getetag XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.6
- */
- this.value = value;
-}
-
-DavGetEtag.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'getetag');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavGetLastModified(value) {
- /* Implementation of getlastmodified XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.7
- */
- this.value = value;
-}
-
-DavGetLastModified.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'getlastmodified');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavLockDiscovery() {
- /* Implementation of lockdiscovery XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.8
- */
- this.locks = new Array();
-}
-
-DavLockDiscovery.prototype = {
- getActiveLocks: function() {
- return this.locks;
- },
- addActiveLock: function(lock) {
- this.locks[this.locks.length] = lock;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'activelock') {
- lock = new DavActiveLock();
- lock.parseXML(sub);
- this.locks[this.locks.length] = lock;
- }
- }
- },
- createXML: function(parent, doc) {
- node = doc.createElementNS('DAV:', 'lockdiscovery');
- for (var index = 0; index < this.locks.length; index++) {
- this.locks[index].createXML(node, doc);
- }
- parent.appendChild(node);
- }
-}
-
-
-function DavResourceType(value) {
- /* Implementation of resourcetype XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.9
- */
- if (!value)
- value = '';
- this.value = value;
-}
-
-DavResourceType.prototype = {
- getValue: function() {
- return this.value;
- },
- setValue: function(value) {
- this.value = value;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- this.value = node.firstChild.nodeValue;
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'resourcetype');
- node.appendChild(doc.createTextNode(this.value));
- parent.appendChild(node);
- }
-}
-
-
-function DavSource() {
- /* Implementation of source XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.10
- */
- this.links = new Array();
-}
-
-DavSource.prototype = {
- getLinks: function() {
- return this.links;
- },
- addLink: function(link) {
- this.links[this.links.length] = link;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'link') {
- link = new DavLink();
- link.parseXML(sub);
- this.links[this.links.length] = link;
- }
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'source');
- for (var index = 0; index < this.links.length; index++) {
- this.links[index].createXML(node, doc);
- }
- parent.appendChild(node);
- }
-}
-
-
-function DavSupportedLock() {
- /* Implementation of supportedlock XML Element.
-
- See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-13.11
- */
- this.entries = new Array();
-}
-
-DavSupportedLock.prototype = {
- getEntries: function() {
- return this.entries;
- },
- addEntry: function(entry) {
- this.entries[this.entries.length] = entry;
- },
- parseXML: function(node) {
- this.xmlNode = node;
- for (var index = 0; index < node.childNodes.length; index++) {
- sub = node.childNodes[index];
- if (sub.localName == 'lockentry') {
- entry = new DavLockEntry();
- entry.parseXML(sub);
- this.entries[this.entries.length] = entry;
- }
- }
- },
- createXML: function(parent, doc) {
- var node = doc.createElementNS('DAV:', 'supportedlock');
- for (var index = 0; index < this.entries.length; index++) {
- this.entries[index].createXML(node, doc);
- }
- parent.appendChild(node);
- }
-}
-
-
-/* jsdav specific exceptions */
-
-function DavInvalidDepthValueError(value) {
- /* Handles invalid depth value errors. The constructor accepts the
- false value. */
- this.value = value;
-}
-
-DavInvalidDepthValueError.prototype = {
- serialize: function() {
- return ("The value '" + this.value + "' is not a valid depth. Use " +
- "one of the following values instead: 0, 1, infinity");
- }
-}
-
-
-function DavWrongTypeError(expected, received) {
- /* Handles wrong object type errors. */
- this.expected = expected;
- this.received = received;
-}
-
-DavWrongTypeError.prototype = {
- serialize: function() {
- return ("Expected object type to be [" + this.expected + "], but is [" +
- this.received + "].");
- }
-}
-
-
-function DavInvalidScopeValueError(value) {
- /* Handles invalid scope value errors. The constructor accepts the
- false value. */
- this.value = value;
-}
-
-DavInvalidScopeValueError.prototype = {
- serialize: function() {
- return ("The value '" + this.value + "' is not a valid scope. Use " +
- "one of the following values instead: shared, exclusive");
- }
-}
-
-
-function DavInvalidLockTypeError(value) {
- /* Handles invalid lock type value errors. The constructor accepts the
- false value. */
- this.value = value;
-}
-
-DavInvalidLockTypeError.prototype = {
- serialize: function() {
- return ("The lock type '" + this.value + "' is not valid. Use " +
- "one of the following values instead: write");
- }
-}
View
405 mozileDataTransport.js
@@ -1,405 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Bitflux code.
- *
- * The Initial Developer of the Original Code is Bitflux
- * Portions created by the Initial Developer are Copyright (C) 2002-2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * - Christian Stocker (Bitflux)
- * - James A. Overton <james@overton.ca>
- * - Lars Kiilerich <lars[at]v1p[dot]dk>
- *
- * ***** END LICENSE BLOCK ***** */
-
-/************************************************************************************
- * mozDataTransport v0.52
- *
- * Generic File Transport Driver infrastructure first seen in Bitflux, a multi-purpose,
- * in-browser, XML editor.
- *
- * This infrastructure supports a variety of ways to publish data in Mozilla.
- * Particular drivers for webdav or http specialize this class
- *
- * INPUT: driverName - string to append to "mozTransportDriver_"
- * the options are...
- * "display"
- * "local"
- * "post"
- * "webdav"
- * POST05:
- * - add support for CVS, ftp and other ways to post files to CMSs
- * - save to file: see mozedit and jslib projects - http://www.bokil.com/downloads/
- *
- ************************************************************************************/
-
-function mozTransportDriver (driverName) {
- this.container = eval(" new mozTransportDriver_"+driverName);
-}
-
-mozTransportDriver.prototype.load = function (filename, callback) {
- var id = "mozTransportDriver.load";
- this.callback = this.loadCallback;
- this.userLoadCallback = callback;
- this.filename = filename;
- this.container.load(filename, this);
-};
-
-mozTransportDriver.prototype.loadCallback = function (reqObj) {
- reqObj.td = this;
- reqObj.filename = this.filename;
- if (this.userLoadCallback) {
- this.userLoadCallback(reqObj);
- }
-};
-
-mozTransportDriver.prototype.save = function(filename, content, callback) {
- this.callback = this.saveCallback;
- this.userSaveCallback = callback;
- this.filename = filename;
- this.container.save(filename, content, this);
-};
-
-mozTransportDriver.prototype.saveCallback = function(reqObj){
- reqObj.td = this;
- reqObj.filename = this.filename;
- if (this.userSaveCallback) {
- this.userSaveCallback(reqObj);
- }
-};
-
-mozTransportDriver.prototype.parseResponseXML = function(responseXML, status) {
- var f=["mozileDataTransport.js","parseResponseXML"];
-
- var reqObj = new Object();
- var alerttext="";
-
- try {
- // look to see if there is a parse error
- var parserErrorNode = responseXML.getElementsByTagNameNS("http://www.mozilla.org/newlayout/xml/parsererror.xml","parsererror")[0];
-
- if (parserErrorNode) {
- alerttext = parserErrorNode.firstChild.data;
- var sourceNode = parserErrorNode.getElementsByTagName("sourcetext")[0];
- if (sourceNode) {
- alerttext += "\n" + sourceNode.firstChild.data;
- }
- mozile.bug.write(f,3,"parserErrorNode: "+ alerttext);
- }
- else {
- alerttext="Something went wrong:\n\n" + status + "\n\n";
- var objXMLSerializer = new XMLSerializer;
- var strXML = objXMLSerializer.serializeToString(responseXML.documentElement);
- alerttext += strXML;
- }
- } catch(e) {
- mozile.bug.write(f,3,"Exception: "+e);
- }
- reqObj.isError = true;
- reqObj.statusText = alerttext;
- reqObj.document = responseXML;
- if (status === 0) {
- reqObj.status = 400;
- } else {
- reqObj.status = status;
- }
- return reqObj;
-};
-
-/*
-* parseResponseText
-*
-*INPUT
-* responseText text to parse, as a string
-* status status
-*
-*EXIT
-* reqObj returned object
-* .iserror true
-* .status status, or 400 if status is 0
-* .statusText "Something went wrong" + responseText
-*
-*/
-mozTransportDriver.prototype.parseResponseText = function(responseText, status) {
-
- var reqObj = new Object();
-
- alerttext="Something went wrong:\n\n";
- alerttext += responseText ;
- reqObj.isError = true;
- reqObj.statusText = alerttext;
- if (status === 0) {
- reqObj.status = 400;
- } else {
- reqObj.status = status;
- }
- return reqObj;
-};
-
-/******************************** webDAV driver ***********************************
- *
- * Depends on external implementation of webDAV: for example, jsdav from twingle
- *
- **********************************************************************************/
-
-function mozTransportDriver_webdav() {
- this.p = new DavClient();
-}
-
-mozTransportDriver_webdav.prototype.load = function (filename, td) {
- this.p.request.td = td;
- //backup Massnahme (sometimes td get's lost with the request...)
- bxe_config.td = td;
- this.p.request.onload = this.loadCallback;
- this.p.GET(filename);
-};
-
-mozTransportDriver_webdav.prototype.save = function (filename, content, td) {
- this.p.request.td = td;
- this.p.request.onload = this.saveCallback;
- this.p.PUT(filename, content );
-};
-
-mozTransportDriver_webdav.prototype.loadCallback = function (e) {
-
- var p = e.currentTarget;
- var td = p.td;
- //backup Massnahme (sometimes td get's lost with the request...)
- if (!td) {
- td = bxe_config.td;
- }
-
- var reqObj = new Object();
- // if there's no element called parsererror...
- if (p.responseXML.getElementsByTagNameNS("http://www.mozilla.org/newlayout/xml/parsererror.xml","parsererror").length === 0) {
- reqObj.document = p.responseXML;
- reqObj.isError = false;
- reqObj.status = 200;
- reqObj.statusText = "OK";
- } else if (p.responseXML) {
- reqObj = td.container.parseResponseXML(p.responseXML);
- }
- else {
- reqObj = td.container.parseResponseText(p.responseText);
- }
- td.loadCallback(reqObj);
-};
-
-mozTransportDriver_webdav.prototype.saveCallback = function (e) {
- var p = e.currentTarget;
- var td = p.td;
- var reqObj = new Object();
- // status code = 204, then it's ok
- if (p.status == 204) {
- reqObj.document = p.responseXML;
- reqObj.isError = false;
- reqObj.status = 200;
- reqObj.statusText = "OK";
- }
- else if (p.status == 201) {
- reqObj.document = p.responseXML;
- reqObj.isError = false;
- reqObj.status = 201;
- reqObj.statusText = "Created";
- }
- else if (p.responseXML) {
- reqObj = td.container.parseResponseXML(p.responseXML, p.status);
- } else {
- reqObj = td.container.parseResponseText(p.responseText, p.status);
- }
- reqObj.originalStatus = p.status;
- reqObj.originalStatusText = p.statusText;
- td.saveCallback(reqObj);
-};
-
-mozTransportDriver_webdav.prototype.parseResponseXML = function(responseXML, status) {
- var reqObj = new Object();
-
- // try to find parserror
- var parserErrorNode = responseXML.getElementsByTagNameNS("http://www.mozilla.org/newlayout/xml/parsererror.xml","parsererror")[0];
- if (parserErrorNode)
- {
- alerttext = parserErrorNode.firstChild.data;
- var sourceNode = parserErrorNode.getElementsByTagName("sourcetext")[0];
- if (sourceNode) {
- alerttext += "\n" + sourceNode.firstChild.data;
- }
- alerttext+= strXML;
- }
- else
- {
- alerttext="Something went wrong:\n\n" + status + "\n\n";
- var objXMLSerializer = new XMLSerializer;
- var strXML = objXMLSerializer.serializeToString(responseXML.documentElement);
- alerttext+= strXML;
- }
- reqObj.isError = true;
- reqObj.statusText = alerttext;
- reqObj.document = responseXML;
- if (status === 0) {
- reqObj.status = 400;
- } else {
- reqObj.status = status;
- }
- return reqObj;
-
-};
-
-mozTransportDriver_webdav.prototype.parseResponseText = function(responseText, status) {
-
- var reqObj = new Object();
-
- alerttext="Something went wrong:\n\n";
- alerttext += responseText ;
- reqObj.isError = true;
- reqObj.statusText = alerttext;
- if (status === 0) {
- reqObj.status = 400;
- } else {
- reqObj.status = status;
- }
- return reqObj;
-};
-
-/********************************* HTTP POST driver *******************************/
-function mozTransportDriver_post() {}
-
-/*
- Save a file using HTTP POST.
-*/
-mozTransportDriver_post.prototype.save = function(filename, content, td)
-{
- try {
- var reqObj = new Object();
- var SavePostWindow = window.openDialog(
- "chrome://mozile/content/XUL/savepost.xul",
- "savepost",
- "modal,dialog,centerscreen,chrome,resizable=no,close=no",
- filename, content, reqObj);
- }catch (e){
- var f=["mozileDataTransport.js","mozTransportDriver_post.save"];
- mozile.bug.write(f,1,"POST window open exception: "+e);
- }
- td.callback(reqObj);
-};
-
-/*
-* Loads a file over http get
-* @tparam String filename the filename (can be http://... or just a relative path
-*/
-mozTransportDriver_post.prototype.load = function(filename, td) {
- var docu = document.implementation.createDocument("","",null);
- docu.loader = this.parent;
- docu.td = td;
- docu.onload = this.loadCallback;
- try {
- docu.load(filename);
- }
- catch (e) {
- var reqObj = new Object();
- reqObj.document = docu;
- reqObj.isError = true;
- reqObj.status = 404;
- reqObj.statusText = filename + " could not be loaded\n" + e.message;
- td.loadCallback(reqObj);
- }
- return docu;
-};
-
-mozTransportDriver_post.prototype.loadCallback = function (e) {
- var reqObj = new Object();
- reqObj.document = e.currentTarget;
- reqObj.isError = false;
- reqObj.status = 200;
- reqObj.statusText = "OK";
- var td = e.currentTarget.td;
- if (!td) {
- alert("td was not in e.currentTarget!!! Get it from global var");
- }
- td.loadCallback(reqObj);
-};
-
-/******************************** local file driver ***************************/
-function mozTransportDriver_local() {}
-
-/**
-Saves content to a local file.
-opens a file picker window with HTML, XML and All files filters.
-"filename" is not yet supported.
-
-Refer here for more details of file saving:
-http://developer.mozilla.org/en/docs/Code_snippets:File_I/O
-*/
-mozTransportDriver_local.prototype.save = function (filename, content, td) {
- var f=["mozileDataTransport.js","local.save"];
- try {
- var reqObj = new Object();
-
- var nsIFilePicker = Components.interfaces.nsIFilePicker;
- var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
- // window needs to be set correctly. This is the window that the the filepicker is dependent on.
- // this should probably be mozileTarget ???
-// fp.init(window, "Save to Local File", nsIFilePicker.modeSave);
- fp.init(mozileTarget, "Save to Local File", nsIFilePicker.modeSave);
- fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterHTML | nsIFilePicker.filterXML);
-
- var userAction = fp.show();
-
- switch (userAction) {
- case nsIFilePicker.returnOK :
- case nsIFilePicker.returnReplace :
-
- var nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;
- var fos = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(nsIFileOutputStream);
-
- fos.init(fp.file, 0x2A, 0664, 0); // write, create, truncate
-
- var count = fos.write(content, content.length);
- fos.flush();
- fos.close();
-
- reqObj.isError = false;
- reqObj.status = 200;
- reqObj.statusText = "Saved to local file : "+ count +" bytes written";
- break;
-
- default : // User cancelled without saving.
- reqObj.isError = false;
- reqObj.status = 200;
- reqObj.statusText = "Save to local file cancelled";
- break;
- }
- td.saveCallback(reqObj);
- }
- catch(e)
- {
- mozile.bug.write(f,0,"Exception saving to local file: "+e);
- }
-
-};
-
-/**
-Displays content in a window.
-*/
-function mozTransportDriver_display() {}
-
-mozTransportDriver_display.prototype.save = function (filename, content, td)
-{
- window.openDialog("chrome://mozile/content/XUL/source.xul","Source","chrome,centerscreen,dialog=0,resizable=1,scrollbars=1",content.unicode,content.charset);
- // No callback required, only displaying content not actually saving it.
-};
-
-/*
-This is called by the dialog window to save the displayed contents to a local file.
-*/
-mozTransportDriver_display.saveLocal = function(content) {
- var td = new mozTransportDriver("local");
- td.save("", content, __mozileSaved);
-};
View
10 spec/webdav_spec.js
@@ -37,7 +37,11 @@ suite('WebDAV')
test('should mkdir', function() {
var dir = WebDav.Fs.dir('http://localhost:8085/webdav/testmkdir');
- dir.rm();
+ try {
+ dir.rm();
+ } catch(e) {
+ }
+
var expectedFailure = false;
try {
dir.children();
@@ -51,8 +55,8 @@ suite('WebDAV')
test('should create file', function() {
var file = WebDav.Fs.file('http://localhost:8085/webdav/foo.txt');
- file.write("helloworld");
- assertEquals("helloworld", file.read());
+ file.write("Some\nFile data");
+ assertEquals("Some\nFile data", file.read());
})
run();
View
14 src/env.rhino.js
@@ -112,7 +112,7 @@ var __env__ = {};
file["delete"]();
};
- $env.connection = function(xhr, responseHandler){
+ $env.connection = function(xhr, data, responseHandler){
var url = java.net.URL(xhr.url);//, $w.location);
var connection;
if ( /^file\:/.test(url) ) {
@@ -133,7 +133,15 @@ var __env__ = {};
for (var header in xhr.headers) {
connection.addRequestProperty(header, xhr.headers[header]);
}
- connection.connect();
+
+ if(data) {
+ connection.setDoOutput(true);
+ var out = new java.io.DataOutputStream(connection.getOutputStream());
+ out.writeBytes(data);
+ out.close();
+ } else {
+ connection.connect();
+ }
// Stick the response headers into responseHeaders
for (var i = 0; ; i++) {
@@ -7635,7 +7643,7 @@ XMLHttpRequest.prototype = {
var _this = this;
function makeRequest(){
- $env.connection(_this, function(){
+ $env.connection(_this, data, function(){
var responseXML = null;
_this.__defineGetter__("responseXML", function(){
if ( _this.responseText.match(/^\s*</) ) {
Please sign in to comment.
Something went wrong with that request. Please try again.