aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webcals
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-19 23:31:02 -0700
committerJames Lal <james@lightsofapollo.com>2012-06-19 23:31:02 -0700
commitd89e5a43dadff8d1b2c42e9bf5ea3bc129706d90 (patch)
tree7fe2e3b4add4daa9f77f6bc01b5fb8375b9b193d /lib/webcals
parent038911be29c875e0fcd24472e815167bb98ce833 (diff)
downloadjsCalDAV-d89e5a43dadff8d1b2c42e9bf5ea3bc129706d90.tar.gz
Basic multi response parser.
Diffstat (limited to 'lib/webcals')
-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;
+ }
+ }
});