From a3f59b6298d87c3a72c167142546a816b3f2e73d Mon Sep 17 00:00:00 2001 From: James Lal Date: Sat, 7 Jul 2012 09:00:49 -0700 Subject: More complete parsing of calendar data --- lib/caldav/resources/calendar.js | 13 ++++++++++- lib/caldav/sax/dav_response.js | 45 +++++++++++++++++++++++++++++++----- scripts/connect | 5 ++++ test/caldav/sax/dav_response_test.js | 1 + 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/lib/caldav/resources/calendar.js b/lib/caldav/resources/calendar.js index a5a47c7..fd921cb 100644 --- a/lib/caldav/resources/calendar.js +++ b/lib/caldav/resources/calendar.js @@ -6,10 +6,15 @@ /** * Represents a (Web/Cal)Dav resource type. * + * @param {Caldav.Connection} connection connection details. * @param {Object} options public options on prototype. */ - function Calendar(options) { + function Calendar(connection, options) { + if (typeof(options) === 'undefined') { + options = {}; + } + this.updateFromServer(options); } Calendar.prototype = { @@ -59,6 +64,12 @@ */ privilegeSet: null, + /** + * Updates calendar details from server. + */ + updateFromServer: function() { + }, + /** * Creates a query request for this calendar resource. * diff --git a/lib/caldav/sax/dav_response.js b/lib/caldav/sax/dav_response.js index 0d9fb7c..dddd40b 100644 --- a/lib/caldav/sax/dav_response.js +++ b/lib/caldav/sax/dav_response.js @@ -43,11 +43,6 @@ 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); @@ -90,6 +85,38 @@ } }); + var PrivilegeSet = Base.create({ + name: 'PrivilegeSet', + + name: 'href', + + onopentag: function(data) { + if (this.currentTag.handler === this.handler) { + this.stack.push(this.current); + this.current = []; + } else { + if (data.tagSpec !== 'DAV:/privilege') { + this.current.push(data.local); + } + } + }, + + onclosetag: function(data) { + 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: null + + }); + var ArrayHandler = Base.create({ name: 'array', @@ -124,14 +151,20 @@ handles: { 'DAV:/href': TextHandler, + 'http://calendarserver.org/ns//getctag': TextHandler, 'DAV:/status': HttpStatusHandler, 'DAV:/resourcetype': ArrayHandler, + 'DAV:/current-user-privilege-set': PrivilegeSet, 'DAV:/principal-URL': HrefHandler, 'DAV:/current-user-principal': HrefHandler, 'urn:ietf:params:xml:ns:caldav/calendar-data': CalendarDataHandler, 'DAV:/value': TextHandler, + 'DAV:/owner': HrefHandler, + 'DAV:/displayname': TextHandler, 'urn:ietf:params:xml:ns:caldav/calendar-home-set': HrefHandler, - 'urn:ietf:params:xml:ns:caldav/calendar-user-address-set': HrefHandler + 'urn:ietf:params:xml:ns:caldav/calendar-timezone': TextHandler, + 'http://apple.com/ns/ical//calendar-color': TextHandler, + 'urn:ietf:params:xml:ns:caldav/calendar-description': TextHandler }, onopentag: function(data, handler) { diff --git a/scripts/connect b/scripts/connect index 2807937..050df1b 100755 --- a/scripts/connect +++ b/scripts/connect @@ -41,6 +41,9 @@ function getCalendarDetails(caluri) { var calFind = findProp(caluri); calFind.prop(['ical', 'calendar-color']); calFind.prop('owner'); + calFind.prop('current-user-privilege-set'); + calFind.prop(['caldav', 'calendar-description']); + calFind.prop(['caldav', 'calendar-timezone']); calFind.prop('displayname'); calFind.prop('resourcetype'); calFind.prop(['calserver', 'getctag']); @@ -59,6 +62,8 @@ function getCalendarDetails(caluri) { } console.log('DATA:'); console.log(JSON.stringify(data)); + //console.log('RAW:'); + //console.log(calFind.xhr.xhr.responseText); }); } diff --git a/test/caldav/sax/dav_response_test.js b/test/caldav/sax/dav_response_test.js index f9243e8..45bc788 100644 --- a/test/caldav/sax/dav_response_test.js +++ b/test/caldav/sax/dav_response_test.js @@ -1,3 +1,4 @@ +testSupport.lib('responder'); testSupport.lib('sax'); testSupport.lib('sax/base'); testSupport.lib('sax/dav_response'); -- cgit