-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathparser.js
More file actions
644 lines (562 loc) · 22.3 KB
/
Copy pathparser.js
File metadata and controls
644 lines (562 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/**
* CDAV Library
*
* This library is part of the Nextcloud project
*
* @author Georg Ehrke
* @author Richard Steinmetz <richard@steinmetz.cloud>
* @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
*
*/
export default class Parser {
/**
*
*/
constructor() {
/**
* Key Value Map of propertyName => parser
* @type {Object}
* @private
*/
this._parser = {};
// initialize default parsers shipped with this lib
this._registerDefaultParsers();
}
/**
* checks if a parser exists for a given property name
*
* @param {String} propertyName
* @returns {boolean}
*/
canParse(propertyName) {
return Object.prototype.hasOwnProperty.call(this._parser, propertyName);
}
/**
* parses a single prop Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @return {*}
*/
parse(document, node, resolver) {
const propertyName = `{${node.namespaceURI}}${node.localName}`;
if (!this.canParse(propertyName)) {
throw new Error(`Unable to parse unknown property "${propertyName}"`);
}
return this._parser[propertyName](document, node, resolver);
}
/**
* registers a parser for propertyName
*
* @param {String} propertyName
* @param {Function} parser
*/
registerParser(propertyName, parser) {
this._parser[propertyName] = parser;
}
/**
* unregisters a parser for propertyName
*
* @param {String} propertyName
*/
unregisterParser(propertyName) {
delete this._parser[propertyName];
}
/**
* registers the predefined parsers
*
* @private
*/
_registerDefaultParsers() {
// RFC 4918 - HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)
this.registerParser('{DAV:}displayname', Parser.text);
this.registerParser('{DAV:}creationdate', Parser.text);
this.registerParser('{DAV:}getcontentlength', Parser.decInt);
this.registerParser('{DAV:}getcontenttype', Parser.text);
this.registerParser('{DAV:}getcontentlanguage', Parser.text);
this.registerParser('{DAV:}getlastmodified', Parser.rfc1123Date);
this.registerParser('{DAV:}getetag', Parser.text);
this.registerParser('{DAV:}resourcetype', Parser.resourceType);
// RFC 3744 - Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol
this.registerParser('{DAV:}inherited-acl-set', Parser.hrefs);
this.registerParser('{DAV:}group', Parser.href);
this.registerParser('{DAV:}owner', Parser.href);
this.registerParser('{DAV:}current-user-privilege-set', Parser.privileges);
this.registerParser('{DAV:}principal-collection-set', Parser.hrefs);
this.registerParser('{DAV:}principal-URL', Parser.href);
this.registerParser('{DAV:}alternate-URI-set', Parser.hrefs);
this.registerParser('{DAV:}group-member-set', Parser.hrefs);
this.registerParser('{DAV:}group-membership', Parser.hrefs);
// RFC 5397 - WebDAV Current Principal Extension
this.registerParser('{DAV:}current-user-principal', Parser.currentUserPrincipal);
// RFC 6578 - Collection Synchronization for Web Distributed Authoring and Versioning (WebDAV)
this.registerParser('{DAV:}sync-token', Parser.text);
// RFC 6352 - CardDAV: vCard Extensions to Web Distributed Authoring and Versioning (WebDAV)
this.registerParser('{urn:ietf:params:xml:ns:carddav}address-data', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:carddav}addressbook-description', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:carddav}supported-address-data', Parser.addressDataTypes);
this.registerParser('{urn:ietf:params:xml:ns:carddav}max-resource-size', Parser.decInt);
this.registerParser('{urn:ietf:params:xml:ns:carddav}addressbook-home-set', Parser.hrefs);
this.registerParser('{urn:ietf:params:xml:ns:carddav}principal-address', Parser.href);
this.registerParser('{urn:ietf:params:xml:ns:carddav}supported-collation-set', Parser.supportedCardDAVCollations);
// RFC 4791 - Calendaring Extensions to WebDAV (CalDAV)
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-data', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-home-set', Parser.hrefs);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-description', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-timezone', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set', Parser.calendarComps);
this.registerParser('{urn:ietf:params:xml:ns:caldav}supported-calendar-data', Parser.calendarDatas);
this.registerParser('{urn:ietf:params:xml:ns:caldav}max-resource-size', Parser.decInt);
this.registerParser('{urn:ietf:params:xml:ns:caldav}min-date-time', Parser.iCalendarTimestamp);
this.registerParser('{urn:ietf:params:xml:ns:caldav}max-date-time', Parser.iCalendarTimestamp);
this.registerParser('{urn:ietf:params:xml:ns:caldav}max-instances', Parser.decInt);
this.registerParser('{urn:ietf:params:xml:ns:caldav}max-attendees-per-instance', Parser.decInt);
this.registerParser('{urn:ietf:params:xml:ns:caldav}supported-collation-set', Parser.supportedCalDAVCollations);
// RFC 6638 - Scheduling Extensions to CalDAV
this.registerParser('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', Parser.href);
this.registerParser('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', Parser.href);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', Parser.hrefs);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-user-type', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', Parser.scheduleCalendarTransp);
this.registerParser('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', Parser.href);
this.registerParser('{urn:ietf:params:xml:ns:caldav}schedule-tag', Parser.text);
// RFC 7809 - Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference
this.registerParser('{urn:ietf:params:xml:ns:caldav}timezone-service-set', Parser.hrefs);
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-timezone-id', Parser.text);
// RFC 7953 - Calendar Availability
this.registerParser('{urn:ietf:params:xml:ns:caldav}calendar-availability', Parser.text);
// Apple
this.registerParser('{http://apple.com/ns/ical/}calendar-order', Parser.decInt);
this.registerParser('{http://apple.com/ns/ical/}calendar-color', Parser.color);
this.registerParser('{http://calendarserver.org/ns/}source', Parser.href);
// https://tools.ietf.org/html/draft-daboo-valarm-extensions-04#section-11.1
this.registerParser('{urn:ietf:params:xml:ns:caldav}default-alarm-vevent-datetime', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}default-alarm-vevent-date', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}default-alarm-vtodo-datetime', Parser.text);
this.registerParser('{urn:ietf:params:xml:ns:caldav}default-alarm-vtodo-date', Parser.text);
// https://github.com/apple/ccs-calendarserver/blob/master/doc/Extensions/caldav-ctag.txt
this.registerParser('{http://calendarserver.org/ns/}getctag', Parser.text);
// https://github.com/apple/ccs-calendarserver/blob/master/doc/Extensions/caldav-proxy.txt
this.registerParser('{http://calendarserver.org/ns/}calendar-proxy-read-for', Parser.hrefs);
this.registerParser('{http://calendarserver.org/ns/}calendar-proxy-write-for', Parser.hrefs);
// https://github.com/apple/ccs-calendarserver/blob/master/doc/Extensions/caldav-sharing.txt
this.registerParser('{http://calendarserver.org/ns/}allowed-sharing-modes', Parser.allowedSharingModes);
this.registerParser('{http://calendarserver.org/ns/}shared-url', Parser.href);
this.registerParser('{http://sabredav.org/ns}owner-principal', Parser.href);
this.registerParser('{http://sabredav.org/ns}read-only', Parser.bool);
this.registerParser('{http://calendarserver.org/ns/}pre-publish-url', Parser.href);
this.registerParser('{http://calendarserver.org/ns/}publish-url', Parser.href);
// Nextcloud custom sharing
this.registerParser('{http://owncloud.org/ns}invite', Parser.ocInvite);
// Nextcloud specific
this.registerParser('{http://owncloud.org/ns}calendar-enabled', Parser.bool);
this.registerParser('{http://owncloud.org/ns}enabled', Parser.bool);
this.registerParser('{http://owncloud.org/ns}read-only', Parser.bool);
this.registerParser('{http://nextcloud.com/ns}owner-displayname', Parser.text);
this.registerParser('{http://nextcloud.com/ns}deleted-at', Parser.iso8601DateTime);
this.registerParser('{http://nextcloud.com/ns}calendar-pattern', Parser.text);
this.registerParser('{http://nextcloud.com/ns}calendar-uri', Parser.text);
this.registerParser('{http://nextcloud.com/ns}has-photo', Parser.bool);
this.registerParser('{http://nextcloud.com/ns}trash-bin-retention-duration', Parser.decInt);
this.registerParser('{http://nextcloud.com/ns}language', Parser.text);
this.registerParser('{http://nextcloud.com/ns}room-type', Parser.text);
this.registerParser('{http://nextcloud.com/ns}room-seating-capacity', Parser.decInt);
this.registerParser('{http://nextcloud.com/ns}room-building-address', Parser.text);
this.registerParser('{http://nextcloud.com/ns}room-building-story', Parser.text);
this.registerParser('{http://nextcloud.com/ns}room-building-room-number', Parser.text);
this.registerParser('{http://nextcloud.com/ns}room-features', Parser.text);
// Sabre/Dav specific
this.registerParser('{http://sabredav.org/ns}email-address', Parser.text);
}
/**
* returns text value of Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String}
*/
static text(document, node, resolver) {
return document.evaluate('string(.)', node, resolver, XPathResult.ANY_TYPE, null).stringValue;
}
/**
* returns boolean value of Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Boolean}
*/
static bool(document, node, resolver) {
return Parser.text(document, node, resolver) === '1';
}
/**
* returns decimal integer value of Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Number}
*/
static decInt(document, node, resolver) {
return parseInt(Parser.text(document, node, resolver), 10);
}
/**
* returns Date value of Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Date}
*/
static rfc1123Date(document, node, resolver) {
const text = Parser.text(document, node, resolver);
// TODO this might not work in every browser
return new Date(text);
}
/**
* returns Date from an ISO8601 string
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Date}
*/
static iso8601DateTime(document, node, resolver) {
const text = Parser.text(document, node, resolver);
return new Date(text);
}
/**
* returns Date value of Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Date}
*/
static iCalendarTimestamp(document, node, resolver) {
const text = Parser.text(document, node, resolver);
const year = parseInt(text.slice(0, 4), 10);
const month = parseInt(text.slice(4, 6), 10) - 1;
const date = parseInt(text.slice(6, 8), 10);
const hour = parseInt(text.slice(9, 11), 10);
const minute = parseInt(text.slice(11, 13), 10);
const second = parseInt(text.slice(13, 15), 10);
const dateObj = new Date();
dateObj.setUTCFullYear(year, month, date);
dateObj.setUTCHours(hour, minute, second, 0);
return dateObj;
}
/**
* parses a {DAV:}resourcetype Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static resourceType(document, node, resolver) {
const result = [];
const children = document.evaluate('*', node, resolver, XPathResult.ANY_TYPE, null);
let childNode;
while ((childNode = children.iterateNext()) !== null) {
const ns = document.evaluate('namespace-uri(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
const local = document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
result.push(`{${ns}}${local}`);
}
return result;
}
/**
* parses a node with one href nodes as child
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String}
*/
static href(document, node, resolver) {
return document.evaluate('string(d:href)', node, resolver, XPathResult.ANY_TYPE, null).stringValue;
}
/**
* parses a node with multiple href nodes as children
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static hrefs(document, node, resolver) {
const result = [];
const hrefs = document.evaluate('d:href', node, resolver, XPathResult.ANY_TYPE, null);
let hrefNode;
while ((hrefNode = hrefs.iterateNext()) !== null) {
result.push(document.evaluate('string(.)', hrefNode, resolver, XPathResult.ANY_TYPE, null).stringValue);
}
return result;
}
/**
* Parses a set of {DAV:}privilege Nodes
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static privileges(document, node, resolver) {
const result = [];
const privileges = document.evaluate('d:privilege/*', node, resolver, XPathResult.ANY_TYPE, null);
let privilegeNode;
while ((privilegeNode = privileges.iterateNext()) !== null) {
const ns = document.evaluate('namespace-uri(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
const local = document.evaluate('local-name(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
result.push(`{${ns}}${local}`);
}
return result;
}
/**
* parses the {DAV:}current-user-principal Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {Object}
* @property {String} type
* @property {String} href
*/
static currentUserPrincipal(document, node, resolver) {
const unauthenticatedCount
= document.evaluate('count(d:unauthenticated)', node, resolver, XPathResult.ANY_TYPE, null).numberValue;
if (unauthenticatedCount !== 0) {
return {
type: 'unauthenticated',
href: null
};
} else {
return {
type: 'href',
href: Parser.href(...arguments)
};
}
}
/**
* Parses a {urn:ietf:params:xml:ns:carddav}supported-address-data Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {*}
*/
static addressDataTypes(document, node, resolver) {
const result = [];
const addressDatas = document.evaluate('cr:address-data-type', node, resolver, XPathResult.ANY_TYPE, null);
let addressDataNode;
while ((addressDataNode = addressDatas.iterateNext()) !== null) {
result.push({
'content-type': document.evaluate('string(@content-type)', addressDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
version: document.evaluate('string(@version)', addressDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue
});
}
return result;
}
/**
* Parses a {urn:ietf:params:xml:ns:carddav}supported-collation-set Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {*}
*/
static supportedCardDAVCollations(document, node, resolver) {
const result = [];
const collations = document.evaluate('cr:supported-collation', node, resolver, XPathResult.ANY_TYPE, null);
let collationNode;
while ((collationNode = collations.iterateNext()) !== null) {
result.push(document.evaluate('string(.)', collationNode, resolver, XPathResult.ANY_TYPE, null).stringValue);
}
return result;
}
/**
* Parses a {urn:ietf:params:xml:ns:caldav}supported-collation-set Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {*}
*/
static supportedCalDAVCollations(document, node, resolver) {
const result = [];
const collations = document.evaluate('cl:supported-collation', node, resolver, XPathResult.ANY_TYPE, null);
let collationNode;
while ((collationNode = collations.iterateNext()) !== null) {
result.push(document.evaluate('string(.)', collationNode, resolver, XPathResult.ANY_TYPE, null).stringValue);
}
return result;
}
/**
* Parses a {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static calendarComps(document, node, resolver) {
const result = [];
const comps = document.evaluate('cl:comp', node, resolver, XPathResult.ANY_TYPE, null);
let compNode;
while ((compNode = comps.iterateNext()) !== null) {
result.push(document.evaluate('string(@name)', compNode, resolver, XPathResult.ANY_TYPE, null).stringValue);
}
return result;
}
/**
* Parses a {urn:ietf:params:xml:ns:caldav}supported-calendar-data Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {*}
*/
static calendarDatas(document, node, resolver) {
const result = [];
const calendarDatas = document.evaluate('cl:calendar-data', node, resolver, XPathResult.ANY_TYPE, null);
let calendarDataNode;
while ((calendarDataNode = calendarDatas.iterateNext()) !== null) {
result.push({
'content-type': document.evaluate('string(@content-type)', calendarDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
version: document.evaluate('string(@version)', calendarDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue
});
}
return result;
}
/**
* Parses a {urn:ietf:params:xml:ns:caldav}schedule-calendar-transp Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String}
*/
static scheduleCalendarTransp(document, node, resolver) {
const children = document.evaluate('cl:opaque | cl:transparent', node, resolver, XPathResult.ANY_TYPE, null);
const childNode = children.iterateNext();
if (childNode) {
return document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
}
}
/**
* Parses a {http://apple.com/ns/ical/}calendar-color Node
* strips the alpha value of RGB values
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String}
*/
static color(document, node, resolver) {
const text = Parser.text(document, node, resolver);
// some stupid clients store an alpha value in the rgb hash (like #rrggbbaa) *cough cough* Apple Calendar *cough cough*
// but some browsers can't parse that *cough cough* Safari 9 *cough cough*
// Safari 10 seems to support this though
if (text.length === 9) {
return text.slice(0, 7);
}
return text;
}
/**
* Parses a {http://apple.com/ns/ical/}calendar-color Node
* strips the alpha value of RGB values
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String}
*/
static pattern(document, node, resolver) {
const text = Parser.text(document, node, resolver);
// some stupid clients store an alpha value in the rgb hash (like #rrggbbaa) *cough cough* Apple Calendar *cough cough*
// but some browsers can't parse that *cough cough* Safari 9 *cough cough*
// Safari 10 seems to support this though
// if (text.length === 9) {
// return text.slice(0, 7);
// }
return text;
}
/**
* Parses a {http://calendarserver.org/ns/}allowed-sharing-modes Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static allowedSharingModes(document, node, resolver) {
const result = [];
const children = document.evaluate('cs:can-be-shared | cs:can-be-published', node, resolver, XPathResult.ANY_TYPE, null);
let childNode;
while ((childNode = children.iterateNext()) !== null) {
const ns = document.evaluate('namespace-uri(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
const local = document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
result.push(`{${ns}}${local}`);
}
return result;
}
/**
* Parses a {http://owncloud.org/ns}invite Node
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {*}
*/
static ocInvite(document, node, resolver) {
const result = [];
const users = document.evaluate('oc:user', node, resolver, XPathResult.ANY_TYPE, null);
let userNode;
while ((userNode = users.iterateNext()) !== null) {
result.push({
href: Parser.href(document, userNode, resolver),
'common-name': document.evaluate('string(oc:common-name)', userNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
'invite-accepted': document.evaluate('count(oc:invite-accepted)', userNode, resolver, XPathResult.ANY_TYPE, null).numberValue === 1,
access: Parser.ocAccess(document, userNode, resolver)
});
}
return result;
}
/**
* Parses a set of {http://owncloud.org/ns}access Nodes
*
* @param {Document} document
* @param {Node} node
* @param {XPathNSResolver} resolver
* @returns {String[]}
*/
static ocAccess(document, node, resolver) {
const result = [];
const privileges = document.evaluate('oc:access/*', node, resolver, XPathResult.ANY_TYPE, null);
let privilegeNode;
while ((privilegeNode = privileges.iterateNext()) !== null) {
const ns = document.evaluate('namespace-uri(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
const local = document.evaluate('local-name(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue;
result.push(`{${ns}}${local}`);
}
return result;
}
}