/pigeoncms/Plugins/fckeditor/editor/filemanager/browser/default/js/fckxml.js

http://pigeoncms.googlecode.com/ · JavaScript · 147 lines · 97 code · 18 blank · 32 comment · 18 complexity · c3c3d324f47f125fcd036797699795c2 MD5 · raw file

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