Project

General

Profile

1
/*
2
 * CKeditor - The text editor for Internet - http://www.ckeditor.net
3
 * Copyright (C) 2003-2010 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

    
28
var FCKXml = function()
29
{}
30

    
31
FCKXml.prototype.GetHttpRequest = function()
32
{
33
    // Gecko / IE7
34
    try { return new XMLHttpRequest(); }
35
    catch(e) {}
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

    
48
FCKXml.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
     try {
59
         oXmlHttp.responseType='msxml-document';
60
     }
61
     catch (e) {}
62

    
63
    if ( bAsync )
64
    {
65
        oXmlHttp.onreadystatechange = function()
66
        {
67
            if ( oXmlHttp.readyState == 4 )
68
            {
69
                var oXml ;
70
                try
71
                {
72
                    // this is the same test for an FF2 bug as in fckxml_gecko.js
73
                    // but we've moved the responseXML assignment into the try{}
74
                    // so we don't even have to check the return status codes.
75
                    var test = oXmlHttp.responseXML.firstChild ;
76
                    oXml = oXmlHttp.responseXML ;
77
                }
78
                catch ( e )
79
                {
80
                    try
81
                    {
82
                        oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;
83
                    }
84
                    catch ( e ) {}
85
                }
86

    
87
                if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )
88
                {
89
                    alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' +
90
                            'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +
91
                            'Requested URL:\n' + urlToCall + '\n\n' +
92
                            'Response text:\n' + oXmlHttp.responseText ) ;
93
                    return ;
94
                }
95

    
96
                oFCKXml.DOMDocument = oXml ;
97
                asyncFunctionPointer( oFCKXml ) ;
98
            }
99
        }
100
    }
101

    
102
    oXmlHttp.send( null ) ;
103

    
104
    if ( ! bAsync )
105
    {
106
        if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
107
            this.DOMDocument = oXmlHttp.responseXML ;
108
        else
109
        {
110
            alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
111
        }
112
    }
113
}
114

    
115
FCKXml.prototype.SelectNodes = function( xpath )
116
{
117
    if ( navigator.userAgent.indexOf('MSIE') >= 0 || !!navigator.userAgent.match(/Trident.*rv.*11\./))        // IE
118
        return this.DOMDocument.selectNodes( xpath ) ;
119
    else                    // Gecko
120
    {
121
        var aNodeArray = new Array();
122

    
123
        var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
124
                this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
125
        if ( xPathResult )
126
        {
127
            var oNode = xPathResult.iterateNext() ;
128
             while( oNode )
129
             {
130
                 aNodeArray[aNodeArray.length] = oNode ;
131
                 oNode = xPathResult.iterateNext();
132
             }
133
        }
134
        return aNodeArray ;
135
    }
136
}
137

    
138
FCKXml.prototype.SelectSingleNode = function( xpath )
139
{
140
    if ( navigator.userAgent.indexOf('MSIE') >= 0 || !!navigator.userAgent.match(/Trident.*rv.*11\./))        // IE
141
        return this.DOMDocument.selectSingleNode( xpath ) ;
142
    else                    // Gecko
143
    {
144
        var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
145
                this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
146

    
147
        if ( xPathResult && xPathResult.singleNodeValue )
148
            return xPathResult.singleNodeValue ;
149
        else
150
            return null ;
151
    }
152
}
(2-2/3)