Subversion Repositories Applications.papyrus

Rev

Rev 1925 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1925 Rev 2048
1
/*
1
/*
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
3
 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
4
 *
4
 *
5
 * == BEGIN LICENSE ==
5
 * == BEGIN LICENSE ==
6
 *
6
 *
7
 * Licensed under the terms of any of the following licenses at your
7
 * Licensed under the terms of any of the following licenses at your
8
 * choice:
8
 * choice:
9
 *
9
 *
10
 *  - GNU General Public License Version 2 or later (the "GPL")
10
 *  - GNU General Public License Version 2 or later (the "GPL")
11
 *    http://www.gnu.org/licenses/gpl.html
11
 *    http://www.gnu.org/licenses/gpl.html
12
 *
12
 *
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
 *    http://www.gnu.org/licenses/lgpl.html
14
 *    http://www.gnu.org/licenses/lgpl.html
15
 *
15
 *
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
18
 *
18
 *
19
 * == END LICENSE ==
19
 * == END LICENSE ==
20
 *
20
 *
21
 * Defines the FCKXml object that is used for XML data calls
21
 * Defines the FCKXml object that is used for XML data calls
22
 * and XML processing.
22
 * and XML processing.
23
 *
23
 *
24
 * This script is shared by almost all pages that compose the
24
 * This script is shared by almost all pages that compose the
25
 * File Browser frameset.
25
 * File Browser frameset.
26
 */
26
 */
27
 
27
 
28
var FCKXml = function()
28
var FCKXml = function()
29
{}
29
{}
30
 
30
 
31
FCKXml.prototype.GetHttpRequest = function()
31
FCKXml.prototype.GetHttpRequest = function()
32
{
32
{
33
	// Gecko / IE7
33
	// Gecko / IE7
34
	try { return new XMLHttpRequest(); }
34
	try { return new XMLHttpRequest(); }
35
	catch(e) {}
35
	catch(e) {}
36
 
36
 
37
	// IE6
37
	// IE6
38
	try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; }
38
	try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; }
39
	catch(e) {}
39
	catch(e) {}
40
 
40
 
41
	// IE5
41
	// IE5
42
	try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; }
42
	try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; }
43
	catch(e) {}
43
	catch(e) {}
44
 
44
 
45
	return null ;
45
	return null ;
46
}
46
}
47
 
47
 
48
FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer )
48
FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer )
49
{
49
{
50
	var oFCKXml = this ;
50
	var oFCKXml = this ;
51
 
51
 
52
	var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
52
	var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
53
 
53
 
54
	var oXmlHttp = this.GetHttpRequest() ;
54
	var oXmlHttp = this.GetHttpRequest() ;
55
 
55
 
56
	oXmlHttp.open( "GET", urlToCall, bAsync ) ;
56
	oXmlHttp.open( "GET", urlToCall, bAsync ) ;
57
 
57
 
58
	if ( bAsync )
58
	if ( bAsync )
59
	{
59
	{
60
		oXmlHttp.onreadystatechange = function()
60
		oXmlHttp.onreadystatechange = function()
61
		{
61
		{
62
			if ( oXmlHttp.readyState == 4 )
62
			if ( oXmlHttp.readyState == 4 )
63
			{
63
			{
64
				var oXml ;
64
				var oXml ;
65
				try
65
				try
66
				{
66
				{
67
					// this is the same test for an FF2 bug as in fckxml_gecko.js
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{}
68
					// but we've moved the responseXML assignment into the try{}
69
					// so we don't even have to check the return status codes.
69
					// so we don't even have to check the return status codes.
70
					var test = oXmlHttp.responseXML.firstChild ;
70
					var test = oXmlHttp.responseXML.firstChild ;
71
					oXml = oXmlHttp.responseXML ;
71
					oXml = oXmlHttp.responseXML ;
72
				}
72
				}
73
				catch ( e )
73
				catch ( e )
74
				{
74
				{
75
					try
75
					try
76
					{
76
					{
77
						oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;
77
						oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;
78
					}
78
					}
79
					catch ( e ) {}
79
					catch ( e ) {}
80
				}
80
				}
81
 
81
 
82
				if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )
82
				if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )
83
				{
83
				{
84
					alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' +
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' +
85
							'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +
86
							'Requested URL:\n' + urlToCall + '\n\n' +
86
							'Requested URL:\n' + urlToCall + '\n\n' +
87
							'Response text:\n' + oXmlHttp.responseText ) ;
87
							'Response text:\n' + oXmlHttp.responseText ) ;
88
					return ;
88
					return ;
89
				}
89
				}
90
 
90
 
91
				oFCKXml.DOMDocument = oXml ;
91
				oFCKXml.DOMDocument = oXml ;
92
				asyncFunctionPointer( oFCKXml ) ;
92
				asyncFunctionPointer( oFCKXml ) ;
93
			}
93
			}
94
		}
94
		}
95
	}
95
	}
96
 
96
 
97
	oXmlHttp.send( null ) ;
97
	oXmlHttp.send( null ) ;
98
 
98
 
99
	if ( ! bAsync )
99
	if ( ! bAsync )
100
	{
100
	{
101
		if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
101
		if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
102
			this.DOMDocument = oXmlHttp.responseXML ;
102
			this.DOMDocument = oXmlHttp.responseXML ;
103
		else
103
		else
104
		{
104
		{
105
			alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
105
			alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
106
		}
106
		}
107
	}
107
	}
108
}
108
}
109
 
109
 
110
FCKXml.prototype.SelectNodes = function( xpath )
110
FCKXml.prototype.SelectNodes = function( xpath )
111
{
111
{
112
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
112
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
113
		return this.DOMDocument.selectNodes( xpath ) ;
113
		return this.DOMDocument.selectNodes( xpath ) ;
114
	else					// Gecko
114
	else					// Gecko
115
	{
115
	{
116
		var aNodeArray = new Array();
116
		var aNodeArray = new Array();
117
 
117
 
118
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
118
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
119
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
119
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
120
		if ( xPathResult )
120
		if ( xPathResult )
121
		{
121
		{
122
			var oNode = xPathResult.iterateNext() ;
122
			var oNode = xPathResult.iterateNext() ;
123
 			while( oNode )
123
 			while( oNode )
124
 			{
124
 			{
125
 				aNodeArray[aNodeArray.length] = oNode ;
125
 				aNodeArray[aNodeArray.length] = oNode ;
126
 				oNode = xPathResult.iterateNext();
126
 				oNode = xPathResult.iterateNext();
127
 			}
127
 			}
128
		}
128
		}
129
		return aNodeArray ;
129
		return aNodeArray ;
130
	}
130
	}
131
}
131
}
132
 
132
 
133
FCKXml.prototype.SelectSingleNode = function( xpath )
133
FCKXml.prototype.SelectSingleNode = function( xpath )
134
{
134
{
135
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
135
	if ( navigator.userAgent.indexOf('MSIE') >= 0 )		// IE
136
		return this.DOMDocument.selectSingleNode( xpath ) ;
136
		return this.DOMDocument.selectSingleNode( xpath ) ;
137
	else					// Gecko
137
	else					// Gecko
138
	{
138
	{
139
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
139
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
140
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
140
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
141
 
141
 
142
		if ( xPathResult && xPathResult.singleNodeValue )
142
		if ( xPathResult && xPathResult.singleNodeValue )
143
			return xPathResult.singleNodeValue ;
143
			return xPathResult.singleNodeValue ;
144
		else
144
		else
145
			return null ;
145
			return null ;
146
	}
146
	}
147
}
147
}