source: extensions/FCKEditor/editor/_source/classes/fckxml_gecko.js @ 3295

Last change on this file since 3295 was 3295, checked in by patdenice, 15 years ago

New extension added:
FCK Editor (2.0.a)

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