Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 ddelon 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
4
 *
5
 * Licensed under the terms of the GNU Lesser General Public License:
6
 * 		http://www.opensource.org/licenses/lgpl-license.php
7
 *
8
 * For further information visit:
9
 * 		http://www.fckeditor.net/
10
 *
11
 * File Name: fckxml.js
12
 * 	Defines the FCKXml object that is used for XML data calls
13
 * 	and XML processing.
14
 * 	This script is shared by almost all pages that compose the
15
 * 	File Browser frameset.
16
 *
17
 * File Authors:
18
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
19
 */
20
 
21
var FCKXml = function()
22
{}
23
 
24
FCKXml.prototype.GetHttpRequest = function()
25
{
26
	if ( window.XMLHttpRequest )		// Gecko
27
		return new XMLHttpRequest() ;
28
	else if ( window.ActiveXObject )	// IE
29
		return new ActiveXObject("MsXml2.XmlHttp") ;
30
}
31
 
32
FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer )
33
{
34
	var oFCKXml = this ;
35
 
36
	var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
37
 
38
	var oXmlHttp = this.GetHttpRequest() ;
39
 
40
	oXmlHttp.open( "GET", urlToCall, bAsync ) ;
41
 
42
	if ( bAsync )
43
	{
44
		oXmlHttp.onreadystatechange = function()
45
		{
46
			if ( oXmlHttp.readyState == 4 )
47
			{
48
				oFCKXml.DOMDocument = oXmlHttp.responseXML ;
49
				if ( oXmlHttp.status == 200 )
50
					asyncFunctionPointer( oFCKXml ) ;
51
				else
52
					alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
53
			}
54
		}
55
	}
56
 
57
	oXmlHttp.send( null ) ;
58
 
59
	if ( ! bAsync )
60
	{
61
		if ( oXmlHttp.status == 200 )
62
			this.DOMDocument = oXmlHttp.responseXML ;
63
		else
64
		{
65
			alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
66
		}
67
	}
68
}
69
 
70
FCKXml.prototype.SelectNodes = function( xpath )
71
{
72
	if ( document.all )		// IE
73
		return this.DOMDocument.selectNodes( xpath ) ;
74
	else					// Gecko
75
	{
76
		var aNodeArray = new Array();
77
 
78
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
79
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
80
		if ( xPathResult )
81
		{
82
			var oNode = xPathResult.iterateNext() ;
83
 			while( oNode )
84
 			{
85
 				aNodeArray[aNodeArray.length] = oNode ;
86
 				oNode = xPathResult.iterateNext();
87
 			}
88
		}
89
		return aNodeArray ;
90
	}
91
}
92
 
93
FCKXml.prototype.SelectSingleNode = function( xpath )
94
{
95
	if ( document.all )		// IE
96
		return this.DOMDocument.selectSingleNode( xpath ) ;
97
	else					// Gecko
98
	{
99
		var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
100
				this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
101
 
102
		if ( xPathResult && xPathResult.singleNodeValue )
103
			return xPathResult.singleNodeValue ;
104
		else
105
			return null ;
106
	}
107
}