[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.13 jsdav.js:1.9 sitesmanager.js:1.15
Paul Everitt
paul@zope.com
Wed, 26 Mar 2003 05:57:14 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv22075
Modified Files:
datasourcemanager.js jsdav.js sitesmanager.js
Log Message:
Major changes, not necessarily for the better:
o datasourcemanagers has a hack to avoid barfing when testing
if a node exists
o jsdav changes to implement callbacks for PROPFIND and GET, explained
in a mailing list message
=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.12 => 1.13 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.12 Sun Mar 23 08:32:52 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js Wed Mar 26 05:57:13 2003
@@ -208,6 +208,14 @@
/* Grab a resource using its urn. This method looks through all
datasources to find the resource. */
var tree = document.getElementById(this.treeId);
+
+ /* XXX: a temporary hack by Paul!! Use composite to get resource */
+ ds - new RDFDataSource();
+ ds.Init(tree.database);
+ resource = ds.getNode(urn);
+ return resource;
+
+
var sources = tree.database.GetDataSources();
// The first datasource is Mozilla internal
sources.getNext();
=== Packages/Moztop/moztop/content/lib/jsdav.js 1.8 => 1.9 ===
--- Packages/Moztop/moztop/content/lib/jsdav.js:1.8 Sun Mar 23 17:46:47 2003
+++ Packages/Moztop/moztop/content/lib/jsdav.js Wed Mar 26 05:57:13 2003
@@ -21,6 +21,7 @@
const RESOURCE_DEPTH = '0';
const CHILDREN_DEPTH = '1';
const ALLSUBS_DEPTH = 'infinity';
+const xml_decl = '<?xml version="1.0" encoding="utf-8" ?>\n'
/* WebDAV Status Code Extensions
@@ -35,16 +36,25 @@
statusCodes[507] = 'Insufficient Storage';
-function DavClient(hostname) {
+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.hostname = hostname;
+
+ /* Callbacks are passed to the various DAV methods for handling */
+ /* the server results from your application. These callback */
+ /* functions sometimes need to be called in the context and n */
+ /* scope of an object. Thus, the application can assign the */
+ /* object as a property of this object. Here we set null as */
+ /* the default, which will tell all the DAV methods here to use */
+ /* the callback function as a function, not a method. */
+
+ this.callbackObj = null;
}
-DavClient.prototype.PROPFIND = function(url, propfind, depth) {
+DavClient.prototype.PROPFIND = function(url, propfind, depth, callback) {
/* Implementation of WebDAV command PROPFIND.
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.1
@@ -53,20 +63,26 @@
function handleResponse(error) {
if (request.responseXML) {
- var response = request.responseXML;
- // XXX: Handle returned XML
-
- // Debugging
- var serializer = new XMLSerializer();
- var response_str = serializer.serializeToString(response);
- dump("\nmade it in PUT\n" + response_str + "\n");
+ /* The DavClient is stashed in request.thisobject and the */
+ /* widget is in DavClient.callbackObj */
+ var thisobj = request.thisobj;
+ var responseXML = request.responseXML;
+ request.callback(responseXML, thisobj.callbackObj);
}
+ return;
+ }
+
+ if (!url) {
+ alert("You must supply a URL");
+ return;
}
request.onload = handleResponse;
+ request.callback = callback;
+ request.thisobj = this;
request.open("PROPFIND", url);
- request.setRequestHeader("Content-type", "text/xml");
- request.setRequestHeader("Host", this.hostname);
+ request.setRequestHeader("Content-Type", "text/xml");
+
// look for optional Depth Header
if (depth)
request.setRequestHeader('Depth', this.createDepthHeader(depth))
@@ -75,6 +91,8 @@
request.send("");
else
request.send(propfind.serialize());
+
+ return;
}
@@ -99,7 +117,6 @@
request.onload = handleResponse;
request.open("PROPFIND", url);
request.setRequestHeader("Content-type", "text/xml");
- request.setRequestHeader("Host", this.hostname);
request.send(propertyupdate.serialize());
}
@@ -118,14 +135,13 @@
request.onload = handleResponse;
request.open("MKCOL", url);
request.setRequestHeader("Content-type", "text/plain");
- request.setRequestHeader("Host", this.hostname);
// XXX: Supposely a message body is possible, but the specs were
// incredibly unclear about the form of the message
request.send("");
}
-DavClient.prototype.GET = function(url) {
+DavClient.prototype.GET = function(url, callback) {
/* Implementation of WebDAV command GET.
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.4
@@ -133,13 +149,18 @@
var request = new XMLHttpRequest();
function handleResponse(error) {
- // XXX: Handle simple return value and status;
+ /* The DavClient is stashed in request.thisobject and the */
+ /* widget is in DavClient.callbackObj */
+ var thisobj = request.thisobj;
+ request.callback(request, thisobj.callbackObj);
+
};
request.onload = handleResponse;
+ request.callback = callback;
+ request.thisobj = this;
request.open("GET", url);
request.setRequestHeader("Content-type", "text/plain");
- request.setRequestHeader("Host", this.hostname);
request.send("");
}
@@ -158,7 +179,6 @@
request.onload = handleResponse;
request.open("HEAD", url);
request.setRequestHeader("Content-type", "text/plain");
- request.setRequestHeader("Host", this.hostname);
request.send("");
}
@@ -193,7 +213,6 @@
request.onload = handleResponse;
request.open("DELETE", url);
request.setRequestHeader("Content-type", "text/plain");
- request.setRequestHeader("Host", this.hostname);
request.send("");
return;
@@ -228,13 +247,12 @@
document.createTextNode("My Stuff\nYeah"));
var s = new XMLSerializer();
- str = s.serializeToString(x);
+ str = xml_decl + s.serializeToString(x);
request.onload = handleResponse;
request.open("PUT", url);
request.setRequestHeader("Content-type", "text/xml");
request.setRequestHeader("Host","localhost");
- // XXX: implement "Host" header in a non-static way
request.setRequestHeader(typeheader, "PageTemplate");
request.send(x);
@@ -520,15 +538,15 @@
},
createXML: function() {
- doc = document.implementation.createDocument("DAV:", "propfind",
+ doc = document.implementation.createDocument("DAV:", "D:propfind",
null);
- node = doc.documentElement
+ node = doc.documentElement;
if (this.allprop == true)
- node.appendChild(doc.createElementNS('DAV:', 'allprop'));
+ node.appendChild(doc.createElementNS('DAV:', 'D:allprop'));
if (this.propname == true)
- node.appendChild(doc.createElementNS('DAV:', 'propname'));
+ node.appendChild(doc.createElementNS('DAV:', 'D:propname'));
if (this.props.length > 0) {
for (var index = 0; index < this.props.length; index++)
@@ -539,7 +557,7 @@
serialize: function() {
var doc = this.createXML();
var serializer = new XMLSerializer();
- return serializer.serializeToString(doc);
+ return xml_decl + serializer.serializeToString(doc);
}
}
=== Packages/Moztop/moztop/content/lib/sitesmanager.js 1.14 => 1.15 ===
--- Packages/Moztop/moztop/content/lib/sitesmanager.js:1.14 Sun Mar 23 16:09:16 2003
+++ Packages/Moztop/moztop/content/lib/sitesmanager.js Wed Mar 26 05:57:13 2003
@@ -228,7 +228,7 @@
// Setting initialization attributes
viewer.id = typeViewerName + "-" + new Date().getTime();
viewer.setAttribute("urn", rdf.getValue());
- viewer.setAttribute("resourcetitle", resourcetitle);
+ viewer.setAttribute("resourcetypeurn", typeURN);
// Prepare tabs
var tab = document.createElement("tab");