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