1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * Defines the FCKXml object that is used for XML data calls 22 * and XML processing. 23 * 24 * This script is shared by almost all pages that compose the 25 * File Browser frameset. 26 */ 27 28var FCKXml = function() 29{} 30 31FCKXml.prototype.GetHttpRequest = function() 32{ 33 // Gecko / IE7 34 if ( typeof(XMLHttpRequest) != 'undefined' ) 35 return new XMLHttpRequest() ; 36 37 // IE6 38 try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; } 39 catch(e) {} 40 41 // IE5 42 try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; } 43 catch(e) {} 44 45 return null ; 46} 47 48FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer ) 49{ 50 var oFCKXml = this ; 51 52 var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ; 53 54 var oXmlHttp = this.GetHttpRequest() ; 55 56 oXmlHttp.open( "GET", urlToCall, bAsync ) ; 57 58 if ( bAsync ) 59 { 60 oXmlHttp.onreadystatechange = function() 61 { 62 if ( oXmlHttp.readyState == 4 ) 63 { 64 if ( ( oXmlHttp.status != 200 && oXmlHttp.status != 304 ) || oXmlHttp.responseXML == null || oXmlHttp.responseXML.firstChild == null ) 65 { 66 alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' + 67 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' + 68 'Requested URL:\n' + urlToCall + '\n\n' + 69 'Response text:\n' + oXmlHttp.responseText ) ; 70 return ; 71 } 72 73 oFCKXml.DOMDocument = oXmlHttp.responseXML ; 74 asyncFunctionPointer( oFCKXml ) ; 75 } 76 } 77 } 78 79 oXmlHttp.send( null ) ; 80 81 if ( ! bAsync ) 82 { 83 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) 84 this.DOMDocument = oXmlHttp.responseXML ; 85 else 86 { 87 alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; 88 } 89 } 90} 91 92FCKXml.prototype.SelectNodes = function( xpath ) 93{ 94 if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE 95 return this.DOMDocument.selectNodes( xpath ) ; 96 else // Gecko 97 { 98 var aNodeArray = new Array(); 99 100 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 101 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ; 102 if ( xPathResult ) 103 { 104 var oNode = xPathResult.iterateNext() ; 105 while( oNode ) 106 { 107 aNodeArray[aNodeArray.length] = oNode ; 108 oNode = xPathResult.iterateNext(); 109 } 110 } 111 return aNodeArray ; 112 } 113} 114 115FCKXml.prototype.SelectSingleNode = function( xpath ) 116{ 117 if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE 118 return this.DOMDocument.selectSingleNode( xpath ) ; 119 else // Gecko 120 { 121 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 122 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null); 123 124 if ( xPathResult && xPathResult.singleNodeValue ) 125 return xPathResult.singleNodeValue ; 126 else 127 return null ; 128 } 129} 130