FCKeditor 2.6.6
[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-2010 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         try { return new XMLHttpRequest(); }\r
35         catch(e) {}\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                                 var oXml ;\r
65                                 try\r
66                                 {\r
67                                         // this is the same test for an FF2 bug as in fckxml_gecko.js\r
68                                         // but we've moved the responseXML assignment into the try{}\r
69                                         // so we don't even have to check the return status codes.\r
70                                         var test = oXmlHttp.responseXML.firstChild ;\r
71                                         oXml = oXmlHttp.responseXML ;\r
72                                 }\r
73                                 catch ( e )\r
74                                 {\r
75                                         try\r
76                                         {\r
77                                                 oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;\r
78                                         }\r
79                                         catch ( e ) {}\r
80                                 }\r
81 \r
82                                 if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )\r
83                                 {\r
84                                         alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' +\r
85                                                         'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +\r
86                                                         'Requested URL:\n' + urlToCall + '\n\n' +\r
87                                                         'Response text:\n' + oXmlHttp.responseText ) ;\r
88                                         return ;\r
89                                 }\r
90 \r
91                                 oFCKXml.DOMDocument = oXml ;\r
92                                 asyncFunctionPointer( oFCKXml ) ;\r
93                         }\r
94                 }\r
95         }\r
96 \r
97         oXmlHttp.send( null ) ;\r
98 \r
99         if ( ! bAsync )\r
100         {\r
101                 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )\r
102                         this.DOMDocument = oXmlHttp.responseXML ;\r
103                 else\r
104                 {\r
105                         alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;\r
106                 }\r
107         }\r
108 }\r
109 \r
110 FCKXml.prototype.SelectNodes = function( xpath )\r
111 {\r
112         if ( navigator.userAgent.indexOf('MSIE') >= 0 )         // IE\r
113                 return this.DOMDocument.selectNodes( xpath ) ;\r
114         else                                    // Gecko\r
115         {\r
116                 var aNodeArray = new Array();\r
117 \r
118                 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,\r
119                                 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;\r
120                 if ( xPathResult )\r
121                 {\r
122                         var oNode = xPathResult.iterateNext() ;\r
123                         while( oNode )\r
124                         {\r
125                                 aNodeArray[aNodeArray.length] = oNode ;\r
126                                 oNode = xPathResult.iterateNext();\r
127                         }\r
128                 }\r
129                 return aNodeArray ;\r
130         }\r
131 }\r
132 \r
133 FCKXml.prototype.SelectSingleNode = function( xpath )\r
134 {\r
135         if ( navigator.userAgent.indexOf('MSIE') >= 0 )         // IE\r
136                 return this.DOMDocument.selectSingleNode( xpath ) ;\r
137         else                                    // Gecko\r
138         {\r
139                 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,\r
140                                 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);\r
141 \r
142                 if ( xPathResult && xPathResult.singleNodeValue )\r
143                         return xPathResult.singleNodeValue ;\r
144                 else\r
145                         return null ;\r
146         }\r
147 }\r