1 /* 2 * Copyright ©2014 SARA bv, The Netherlands 3 * 4 * This file is part of js-webdav-client. 5 * 6 * js-webdav-client is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * js-webdav-client is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with js-webdav-client. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 "use strict"; 20 21 // If nl.sara.webdav.codec.Principal_collection_setCodec is already defined, we have a namespace clash! 22 if (nl.sara.webdav.codec.Principal_collection_setCodec !== undefined) { 23 throw new nl.sara.webdav.Exception('Namespace nl.sara.webdav.codec.Principal_collection_setCodec already taken, could not load JavaScript library for WebDAV connectivity.', nl.sara.webdav.Exception.NAMESPACE_TAKEN); 24 } 25 26 /** 27 * @class Adds a codec that converts DAV: principal-collection-setCodec to an array with the uri's object 28 * @augments nl.sara.webdav.Codec 29 */ 30 nl.sara.webdav.codec.Principal_collection_setCodec = new nl.sara.webdav.Codec(); 31 nl.sara.webdav.codec.Principal_collection_setCodec.namespace = 'DAV:'; 32 nl.sara.webdav.codec.Principal_collection_setCodec.tagname = 'principal-collection-set'; 33 34 nl.sara.webdav.codec.Principal_collection_setCodec.fromXML = function(nodelist) { 35 var collections = []; 36 for ( var key = 0; key < nodelist.length; key++ ) { 37 var node = nodelist.item( key ); 38 if ( ( node.nodeType === 1 ) && ( node.localName === 'href' ) && ( node.namespaceURI === 'DAV:' ) ) { // Only extract data from DAV: href nodes 39 var href = ''; 40 for ( var subkey = 0; subkey < node.childNodes.length; subkey++ ) { 41 var childNode = node.childNodes.item( subkey ); 42 if ( ( childNode.nodeType === 3 ) || ( childNode.nodeType === 4 ) ) { // Make sure text and CDATA content is stored 43 href += childNode.nodeValue; 44 } 45 } 46 collections.push( href ); 47 } 48 } 49 return collections; 50 }; 51 52 nl.sara.webdav.codec.Principal_collection_setCodec.toXML = function(value, xmlDoc){ 53 for ( var key in value ) { 54 var href = xmlDoc.createElementNS( 'DAV:', 'href' ); 55 href.appendChild( xmlDoc.createCDATASection( value[ key ] ) ); 56 xmlDoc.documentElement.appendChild( href ); 57 } 58 return xmlDoc; 59 }; 60 61 nl.sara.webdav.Property.addCodec(nl.sara.webdav.codec.Principal_collection_setCodec); 62 63 // End of file