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 nl.sara.webdav.Codec is already defined, we have a namespace clash!
 22 if (nl.sara.webdav.Codec !== undefined) {
 23   throw new nl.sara.webdav.Exception('Namespace name nl.sara.webdav.Codec already taken, could not load JavaScript library for WebDAV connectivity.', nl.sara.webdav.Exception.NAMESPACE_TAKEN);
 24 }
 25 
 26 /**
 27  * @class A codec transcodes the xml to a custom Javascript object
 28  *
 29  * @param  {String}                    [namespace]  Optional; The namespace of the property to transcode
 30  * @param  {String}                    [tagname]    Optional; The tag name of the property to transcode
 31  * @param  {function(mixed[,xmlDoc])}  [toXML]      Optional; Function which should return a Document with the NodeList of the documentElement as the value of this property
 32  * @param  {function(NodeList)}        [fromXML]    Optional; Functions which should return a representation of xmlvalue
 33  * @property  {String}                    namespace  The namespace of the property to transcode
 34  * @property  {String}                    tagname    The tag name of the property to transcode
 35  * @property  {function(mixed[,xmlDoc])}  toXML      Function which should return a Document with the NodeList of the documentElement as the value of this property
 36  * @property  {function(NodeList)}        fromXML    Functions which should return a representation of xmlvalue
 37  */
 38 nl.sara.webdav.Codec = function(namespace, tagname, toXML, fromXML) {
 39   // First define public attributes
 40   Object.defineProperty(this, 'namespace', {
 41     'value': null,
 42     'enumerable': true,
 43     'configurable': false,
 44     'writable': true
 45   });
 46   Object.defineProperty(this, 'tagname', {
 47     'value': null,
 48     'enumerable': true,
 49     'configurable': false,
 50     'writable': true
 51   });
 52   Object.defineProperty(this, 'toXML', {
 53     'value': undefined,
 54     'enumerable': true,
 55     'configurable': false,
 56     'writable': true
 57   });
 58   // Second define public attributes
 59   Object.defineProperty(this, 'fromXML', {
 60     'value': undefined,
 61     'enumerable': true,
 62     'configurable': false,
 63     'writable': true
 64   });
 65 
 66   // Constructor logic
 67   if (namespace !== undefined) {
 68     this.namespace = namespace;
 69   }
 70   if (tagname !== undefined) {
 71     this.tagname = tagname;
 72   }
 73   if (toXML !== undefined) {
 74     this.toXML = toXML;
 75   }
 76   if (fromXML !== undefined) {
 77     this.fromXML = fromXML;
 78   }
 79 };
 80 
 81 // End of file
 82