1 /* 2 * Copyright ©2012 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 it isn't done yet: create a namespace for all the default codecs 22 if (nl.sara.webdav.codec === undefined) { 23 nl.sara.webdav.codec = {}; 24 } 25 26 // If nl.sara.webdav.codec.ResourcetypeCodec is already defined, we have a namespace clash! 27 if (nl.sara.webdav.codec.ResourcetypeCodec !== undefined) { 28 throw new nl.sara.webdav.Exception('Namespace nl.sara.webdav.codec.ResourcetypeCodec already taken, could not load JavaScript library for WebDAV connectivity.', nl.sara.webdav.Exception.NAMESPACE_TAKEN); 29 } 30 31 /** 32 * @class Adds a codec that converts DAV: resourcetype to a Date object 33 * @augments nl.sara.webdav.Codec 34 */ 35 nl.sara.webdav.codec.ResourcetypeCodec = new nl.sara.webdav.Codec(); 36 nl.sara.webdav.codec.ResourcetypeCodec.namespace = 'DAV:'; 37 nl.sara.webdav.codec.ResourcetypeCodec.tagname = 'resourcetype'; 38 39 /** 40 * Class constants are a way to specify what the resource type is 41 */ 42 nl.sara.webdav.codec.ResourcetypeCodec.COLLECTION = 1; 43 nl.sara.webdav.codec.ResourcetypeCodec.UNSPECIFIED = 2; 44 nl.sara.webdav.codec.ResourcetypeCodec.PRINCIPAL = 4; 45 46 nl.sara.webdav.codec.ResourcetypeCodec.fromXML = function(nodelist) { 47 for (var i = 0; i < nodelist.length; i++) { 48 var node = nodelist.item(i); 49 if (node.namespaceURI === 'DAV:') { 50 switch (nl.sara.webdav.Ie.getLocalName(node)) { 51 case 'collection': 52 return nl.sara.webdav.codec.ResourcetypeCodec.COLLECTION; 53 case 'principal': 54 return nl.sara.webdav.codec.ResourcetypeCodec.PRINCIPAL; 55 } 56 } 57 } 58 return nl.sara.webdav.codec.ResourcetypeCodec.UNSPECIFIED; 59 }; 60 61 nl.sara.webdav.codec.ResourcetypeCodec.toXML = function(value, xmlDoc){ 62 switch(value) { 63 case nl.sara.webdav.codec.ResourcetypeCodec.COLLECTION: 64 var collection = xmlDoc.createElementNS('DAV:', 'collection'); 65 xmlDoc.documentElement.appendChild(collection); 66 case nl.sara.webdav.codec.ResourcetypeCodec.PRINCIPAL: 67 var collection = xmlDoc.createElementNS('DAV:', 'principal'); 68 xmlDoc.documentElement.appendChild(collection); 69 break; 70 } 71 return xmlDoc; 72 }; 73 74 nl.sara.webdav.Property.addCodec(nl.sara.webdav.codec.ResourcetypeCodec); 75 76 // End of file 77