aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webcals/sax/dav_response.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/webcals/sax/dav_response.js')
-rw-r--r--lib/webcals/sax/dav_response.js100
1 files changed, 73 insertions, 27 deletions
diff --git a/lib/webcals/sax/dav_response.js b/lib/webcals/sax/dav_response.js
index 5b3e0b7..7cf78af 100644
--- a/lib/webcals/sax/dav_response.js
+++ b/lib/webcals/sax/dav_response.js
@@ -21,6 +21,41 @@
}
});
+ var HrefHandler = Base.create({
+ name: 'href',
+
+ //don't add text only elements
+ //to the stack as objects
+ onopentag: null,
+ onclosetag: null,
+
+ onopentag: function() {
+ if (this.currentTag.handler === this.handler) {
+ this.stack.push(this.current);
+ this.current = null;
+ }
+ },
+
+ onclosetag: function() {
+ var current = this.currentTag;
+ var data;
+
+ if (current.handler === this.handler) {
+ data = this.current;
+
+ this.current = this.stack.pop();
+ this.current[current.local] = data;
+ }
+ },
+
+ ontext: function(data) {
+ if (this.currentTag.local === 'href') {
+ this.current = data;
+ }
+ }
+
+ });
+
var HttpStatusHandler = TextHandler.create({
name: 'status',
@@ -71,13 +106,21 @@
handles: {
'DAV:/href': TextHandler,
'DAV:/status': HttpStatusHandler,
- 'DAV:/resourcetype': ArrayHandler
+ 'DAV:/resourcetype': ArrayHandler,
+ 'DAV:/principal-URL': HrefHandler
},
onopentag: function(data, handler) {
//orphan
if (data.tagSpec === 'DAV:/propstat') {
+ //blank slate propstat
+ if (!('propstat' in this.current)) {
+ this.current['propstat'] = {};
+ }
+
this.stack.push(this.current);
+
+ //contents will be copied over later.
return this.current = {};
}
@@ -85,21 +128,24 @@
},
oncomplete: function() {
- var parent = this.stack[this.stack.length - 1];
+ var propstat = this.stack[this.stack.length - 1];
+ propstat = propstat.propstat;
var key;
-
- //console.log(this.current);
-
- for (key in this.current.prop) {
- if (this.current.prop.hasOwnProperty(key)) {
- parent[key] = {
- status: this.current.status,
- value: this.current.prop[key]
- }
+ var status = this.current.status;
+ var props = this.current.prop;
+
+ delete this.current.status;
+ delete this.current.prop;
+
+ for (key in props) {
+ if (props.hasOwnProperty(key)) {
+ propstat[key] = {
+ status: status,
+ value: props[key]
+ };
}
}
- },
-
+ }
});
var Response = Base.create({
@@ -109,23 +155,23 @@
'DAV:/propstat': PropStatHandler
},
- //onopentag: function(data, handler) {
- //if (data.tagSpec === 'DAV:/response') {
- //this.stack.push(this.current);
- //return this.current = {};
- //}
+ onopentag: function(data, handler) {
+ if (data.tagSpec === 'DAV:/response') {
+ this.stack.push(this.current);
+ return this.current = {};
+ }
- //handler._super.onopentag.call(this, data, handler._super);
- //},
+ handler._super.onopentag.call(this, data, handler._super);
+ },
- //oncomplete: function() {
- //var parent;
+ oncomplete: function() {
+ var parent;
- //if (this.current.href) {
- //parent = this.stack[this.stack.length - 1];
- //parent[this.current.href] = this.current.propstat;
- //}
- //}
+ if (this.current.href) {
+ parent = this.stack[this.stack.length - 1];
+ parent[this.current.href] = this.current.propstat;
+ }
+ }
});