import torrus 1.0.9
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckxml_gecko.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 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  * FCKXml Class: class to load and manipulate XML files.\r
22  */\r
23 \r
24 FCKXml.prototype =\r
25 {\r
26         LoadUrl : function( urlToCall )\r
27         {\r
28                 this.Error = false ;\r
29 \r
30                 var oXml ;\r
31                 var oXmlHttp = FCKTools.CreateXmlObject( 'XmlHttp' ) ;\r
32                 oXmlHttp.open( 'GET', urlToCall, false ) ;\r
33                 oXmlHttp.send( null ) ;\r
34 \r
35                 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 || ( oXmlHttp.status == 0 && oXmlHttp.readyState == 4 ) )\r
36                 {\r
37                         oXml = oXmlHttp.responseXML ;\r
38                         // #1426: Fallback if responseXML isn't set for some\r
39                         // reason (e.g. improperly configured web server)\r
40                         if ( !oXml )\r
41                                 oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;\r
42                 }\r
43                 else\r
44                         oXml = null ;\r
45 \r
46                 if ( oXml )\r
47                 {\r
48                         // Try to access something on it.\r
49                         try\r
50                         {\r
51                                 var test = oXml.firstChild ;\r
52                         }\r
53                         catch (e)\r
54                         {\r
55                                 // If document.domain has been changed (#123), we'll have a security\r
56                                 // error at this point. The workaround here is parsing the responseText:\r
57                                 // http://alexander.kirk.at/2006/07/27/firefox-15-xmlhttprequest-reqresponsexml-and-documentdomain/\r
58                                 oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;\r
59                         }\r
60                 }\r
61 \r
62                 if ( !oXml || !oXml.firstChild )\r
63                 {\r
64                         this.Error = true ;\r
65                         if ( window.confirm( 'Error loading "' + urlToCall + '" (HTTP Status: ' + oXmlHttp.status + ').\r\nDo you want to see the server response dump?' ) )\r
66                                 alert( oXmlHttp.responseText ) ;\r
67                 }\r
68 \r
69                 this.DOMDocument = oXml ;\r
70         },\r
71 \r
72         SelectNodes : function( xpath, contextNode )\r
73         {\r
74                 if ( this.Error )\r
75                         return new Array() ;\r
76 \r
77                 var aNodeArray = new Array();\r
78 \r
79                 var xPathResult = this.DOMDocument.evaluate( xpath, contextNode ? contextNode : this.DOMDocument,\r
80                                 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;\r
81                 if ( xPathResult )\r
82                 {\r
83                         var oNode = xPathResult.iterateNext() ;\r
84                         while( oNode )\r
85                         {\r
86                                 aNodeArray[aNodeArray.length] = oNode ;\r
87                                 oNode = xPathResult.iterateNext();\r
88                         }\r
89                 }\r
90                 return aNodeArray ;\r
91         },\r
92 \r
93         SelectSingleNode : function( xpath, contextNode )\r
94         {\r
95                 if ( this.Error )\r
96                         return null ;\r
97 \r
98                 var xPathResult = this.DOMDocument.evaluate( xpath, contextNode ? contextNode : this.DOMDocument,\r
99                                 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);\r
100 \r
101                 if ( xPathResult && xPathResult.singleNodeValue )\r
102                         return xPathResult.singleNodeValue ;\r
103                 else\r
104                         return null ;\r
105         }\r
106 } ;\r