1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 
 25 /**
 26  * Represents a SOAP Fault
 27  * @class
 28  * Public attributes:
 29  *
 30  * - faultCode: The SOAP fault code
 31  * - reason: Reason string
 32  * - errorCode: server error code
 33  * 
 34  * @private
 35  */
 36 AjxSoapFault = function(faultEl) {
 37 	if (arguments.length == 0) return;
 38 	var prefix = faultEl.prefix;
 39 	var codeStr = prefix + ":Code";
 40 	var reasonStr = prefix + ":Reason";
 41 	var detailStr = prefix + ":Detail"
 42 	// We will assume a correctly formatted Fault element
 43 	var len = faultEl.childNodes.length;
 44 	for (var i = 0; i < len; i++) {
 45 		var childNode = faultEl.childNodes[i];
 46 		if (childNode.nodeName == codeStr) {
 47 			var faultCode = childNode.firstChild.firstChild.nodeValue;
 48 			if (faultCode == (prefix + ":VersionMismatch"))
 49 				this.faultCode = AjxSoapFault.VERSION_MISMATCH;
 50 			else if (faultCode == (prefix + ":MustUnderstand"))
 51 				this.faultCode = AjxSoapFault.MUST_UNDERSTAND;
 52 			else if (faultCode == (prefix + ":DataEncodingUnknown"))
 53 				this.faultCode = AjxSoapFault.DATA_ENCODING_UNKNOWN;
 54 			else if (faultCode == (prefix + ":Sender"))
 55 				this.faultCode = AjxSoapFault.SENDER;
 56 			else if (faultCode == (prefix + ":Receiver"))
 57 				this.faultCode = AjxSoapFault.RECEIVER;
 58 			else
 59 				this.faultCode = AjxSoapFault.UNKNOWN;		
 60 		} else if (childNode.nodeName == reasonStr) {
 61 			this.reason = childNode.firstChild.firstChild.nodeValue;
 62 		} else if (childNode.nodeName == detailStr) {
 63 			this.errorCode = childNode.firstChild.firstChild.firstChild.nodeValue;
 64 		}
 65 	}
 66 }
 67 
 68 /**
 69  * Returns a string representation of this object.
 70  * 
 71  * @return	{string}	a string representation of this object
 72  */
 73 AjxSoapFault.prototype.toString = 
 74 function() {
 75 	return "AjxSoapFault";
 76 }
 77 
 78 AjxSoapFault.SENDER = -1;
 79 AjxSoapFault.RECEIVER = -2;
 80 AjxSoapFault.VERSION_MISMATCH = -3;
 81 AjxSoapFault.MUST_UNDERSTAND = -4;
 82 AjxSoapFault.DATA_ENCODING_UNKNOWN = -5;
 83 AjxSoapFault.UNKNOWN = -6;
 84