Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1075 ddelon 1
/*
1921 jp_milcent 2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2008 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.
1075 ddelon 26
 */
27
 
28
var FCKXml = function()
29
{}
30
 
31
FCKXml.prototype.GetHttpRequest = function()
32
{
33
	// Gecko / IE7
1921 jp_milcent 34
	try { return new XMLHttpRequest(); }
35
	catch(e) {}
1075 ddelon 36
 
37
	// IE6
1921 jp_milcent 38
	try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; }
1075 ddelon 39
	catch(e) {}
40
 
41
	// IE5
1921 jp_milcent 42
	try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; }
1075 ddelon 43
	catch(e) {}
1921 jp_milcent 44
 
45
	return null ;
1075 ddelon 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() ;
1921 jp_milcent 55
 
1075 ddelon 56
	oXmlHttp.open( "GET", urlToCall, bAsync ) ;
1921 jp_milcent 57
 
1075 ddelon 58
	if ( bAsync )
1921 jp_milcent 59
	{
60
		oXmlHttp.onreadystatechange = function()
1075 ddelon 61
		{
62
			if ( oXmlHttp.readyState == 4 )
63
			{
1921 jp_milcent 64
				var oXml ;
65
				try
66
				{
67
					// this is the same test for an FF2 bug as in fckxml_gecko.js
68
					// but we've moved the responseXML assignment into the try{}
69
					// so we don't even have to check the return status codes.
70
					var test = oXmlHttp.responseXML.firstChild ;
71
					oXml = oXmlHttp.responseXML ;
72
				}
73
				catch ( e )
74
				{
75
					try
76
					{
77
						oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;
78
					}
79
					catch ( e ) {}
80
				}
81
 
82
				if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )
83
				{
84
					alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' +
85
							'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +
86
							'Requested URL:\n' + urlToCall + '\n\n' +
87
							'Response text:\n' + oXmlHttp.responseText ) ;
88
					return ;
89
				}
90
 
91
				oFCKXml.DOMDocument = oXml ;
92
				asyncFunctionPointer( oFCKXml ) ;
1075 ddelon 93
			}
94
		}
95
	}
1921 jp_milcent 96
 
1075 ddelon 97
	oXmlHttp.send( null ) ;
1921 jp_milcent 98
 
1075 ddelon 99
	if ( ! bAsync )
100
	{
101
		if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
102
			this.DOMDocument = oXmlHttp.responseXML ;
103
		else
104
		{
105
			alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
106
		}
107
	}
108
}
109
 
110
FCKXml.prototype.SelectNodes = function( xpath )
111
{
112
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
113
		return this.DOMDocument.selectNodes( xpath ) ;
114
	else					// Gecko
115
	{
116
		var aNodeArray = new Array();
117
 
1921 jp_milcent 118
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
1075 ddelon 119
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
1921 jp_milcent 120
		if ( xPathResult )
1075 ddelon 121
		{
122
			var oNode = xPathResult.iterateNext() ;
123
 			while( oNode )
124
 			{
125
 				aNodeArray[aNodeArray.length] = oNode ;
126
 				oNode = xPathResult.iterateNext();
127
 			}
1921 jp_milcent 128
		}
1075 ddelon 129
		return aNodeArray ;
130
	}
131
}
132
 
1921 jp_milcent 133
FCKXml.prototype.SelectSingleNode = function( xpath )
1075 ddelon 134
{
135
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
136
		return this.DOMDocument.selectSingleNode( xpath ) ;
137
	else					// Gecko
138
	{
139
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
140
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
141
 
142
		if ( xPathResult && xPathResult.singleNodeValue )
143
			return xPathResult.singleNodeValue ;
1921 jp_milcent 144
		else
1075 ddelon 145
			return null ;
146
	}
147
}