1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Configurator/Resources/scripts/sarissa.js Mon May 02 22:52:00 2005 +0000
1.3 @@ -0,0 +1,589 @@
1.4 +/**
1.5 + * ====================================================================
1.6 + * About
1.7 + * ====================================================================
1.8 + * Sarissa cross browser XML library
1.9 + * @version 0.9.5.2
1.10 + * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
1.11 + *
1.12 + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
1.13 + * The library supports Gecko based browsers like Mozilla and Firefox,
1.14 + * Internet Explorer (5.5+ with MSXML3.0+) and, last but not least, KHTML based browsers like
1.15 + * Konqueror and Safari.
1.16 + *
1.17 + * ====================================================================
1.18 + * Licence
1.19 + * ====================================================================
1.20 + * This program is free software; you can redistribute it and/or modify
1.21 + * it under the terms of the GNU General Public License version 2 or
1.22 + * the GNU Lesser General Public License version 2.1 as published by
1.23 + * the Free Software Foundation (your choice of the two).
1.24 + *
1.25 + * This program is distributed in the hope that it will be useful,
1.26 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.27 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.28 + * GNU General Public License or GNU Lesser General Public License for more details.
1.29 + *
1.30 + * You should have received a copy of the GNU General Public License
1.31 + * or GNU Lesser General Public License along with this program; if not,
1.32 + * write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.33 + * or visit http://www.gnu.org
1.34 + *
1.35 + */
1.36 +/**
1.37 + * <p>Sarissa is a utility class. Provides static methods for DOMDocument and
1.38 + * XMLHTTP objects, DOM Node serializatrion to XML strings and other goodies.</p>
1.39 + * @constructor
1.40 + */
1.41 +function Sarissa(){};
1.42 +/** @private */
1.43 +Sarissa.PARSED_OK = "Document contains no parsing errors";
1.44 +/**
1.45 + * Tells you whether transformNode and transformNodeToObject are available. This functionality
1.46 + * is contained in sarissa_ieemu_xslt.js and is deprecated. If you want to control XSLT transformations
1.47 + * use the XSLTProcessor
1.48 + * @deprecated
1.49 + * @type boolean
1.50 + */
1.51 +Sarissa.IS_ENABLED_TRANSFORM_NODE = false;
1.52 +/**
1.53 + * tells you whether XMLHttpRequest (or equivalent) is available
1.54 + * @type boolean
1.55 + */
1.56 +Sarissa.IS_ENABLED_XMLHTTP = false;
1.57 +/**
1.58 + * <b>Deprecated, will be removed in 0.9.6</b>. Check for
1.59 + * <code>window.XSLTProcessor</code> instead to see if
1.60 + * XSLTProcessor is available.
1.61 + * @type boolean
1.62 + */
1.63 +Sarissa.IS_ENABLED_XSLTPROC = false;
1.64 +/**
1.65 + * tells you whether selectNodes/selectSingleNode is available
1.66 + * @type boolean
1.67 + */
1.68 +Sarissa.IS_ENABLED_SELECT_NODES = false;
1.69 +var _sarissa_iNsCounter = 0;
1.70 +var _SARISSA_IEPREFIX4XSLPARAM = "";
1.71 +var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
1.72 +var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
1.73 +var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
1.74 +/** <b>Deprecated, will be removed in 0.9.6</b>. @deprecated */
1.75 +var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;
1.76 +/** <b>Deprecated, will be removed in 0.9.6</b>. @deprecated */
1.77 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && (navigator.userAgent.toLowerCase().indexOf("msie") > -1);
1.78 +//==========================================
1.79 +// Implement Node constants if not available
1.80 +//==========================================
1.81 +if(!window.Node || !window.Node.ELEMENT_NODE){
1.82 + var Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12};
1.83 +};
1.84 +// IE initialization
1.85 +if(_SARISSA_IS_IE){
1.86 + // for XSLT parameter names, prefix needed by IE
1.87 + _SARISSA_IEPREFIX4XSLPARAM = "xsl:";
1.88 + // used to store the most recent ProgID available out of the above
1.89 + var _SARISSA_DOM_PROGID = "";
1.90 + var _SARISSA_XMLHTTP_PROGID = "";
1.91 + /**
1.92 + * Called when the Sarissa_xx.js file is parsed, to pick most recent
1.93 + * ProgIDs for IE, then gets destroyed.
1.94 + * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
1.95 + * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled
1.96 + */
1.97 + function pickRecentProgID(idList, enabledList){
1.98 + // found progID flag
1.99 + var bFound = false;
1.100 + for(var i=0; i < idList.length && !bFound; i++){
1.101 + try{
1.102 + var oDoc = new ActiveXObject(idList[i]);
1.103 + o2Store = idList[i];
1.104 + bFound = true;
1.105 + for(var j=0;j<enabledList.length;j++)
1.106 + if(i <= enabledList[j][1])
1.107 + Sarissa["IS_ENABLED_"+enabledList[j][0]] = true;
1.108 + }catch (objException){
1.109 + // trap; try next progID
1.110 + };
1.111 + };
1.112 + if (!bFound)
1.113 + throw "Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
1.114 + idList = null;
1.115 + return o2Store;
1.116 + };
1.117 + // pick best available MSXML progIDs
1.118 + _SARISSA_DOM_PROGID = pickRecentProgID(["Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"], [["SELECT_NODES", 2],["TRANSFORM_NODE", 2]]);
1.119 + _SARISSA_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]);
1.120 + _SARISSA_THREADEDDOM_PROGID = pickRecentProgID(["Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
1.121 + _SARISSA_XSLTEMPLATE_PROGID = pickRecentProgID(["Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0"], [["XSLTPROC", 2]]);
1.122 + // we dont need this anymore
1.123 + pickRecentProgID = null;
1.124 + //============================================
1.125 + // Factory methods (IE)
1.126 + //============================================
1.127 + // see non-IE version
1.128 + Sarissa.getDomDocument = function(sUri, sName){
1.129 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.130 + // if a root tag name was provided, we need to load it in the DOM
1.131 + // object
1.132 + if (sName){
1.133 + // if needed, create an artifical namespace prefix the way Moz
1.134 + // does
1.135 + if (sUri){
1.136 + oDoc.loadXML("<a" + _sarissa_iNsCounter + ":" + sName + " xmlns:a" + _sarissa_iNsCounter + "=\"" + sUri + "\" />");
1.137 + // don't use the same prefix again
1.138 + ++_sarissa_iNsCounter;
1.139 + }
1.140 + else
1.141 + oDoc.loadXML("<" + sName + "/>");
1.142 + };
1.143 + return oDoc;
1.144 + };
1.145 + if(!window.XMLHttpRequest){
1.146 + /**
1.147 + * Emulate XMLHttpRequest
1.148 + * @constructor
1.149 + */
1.150 + function XMLHttpRequest(){
1.151 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.152 + };
1.153 + };
1.154 + // see non-IE version
1.155 + Sarissa.getParseErrorText = function (oDoc) {
1.156 + var parseErrorText = Sarissa.PARSED_OK;
1.157 + if(oDoc.parseError != 0){
1.158 + parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason +
1.159 + "\nLocation: " + oDoc.parseError.url +
1.160 + "\nLine Number " + oDoc.parseError.line + ", Column " +
1.161 + oDoc.parseError.linepos +
1.162 + ":\n" + oDoc.parseError.srcText +
1.163 + "\n";
1.164 + for(var i = 0; i < oDoc.parseError.linepos;i++){
1.165 + parseErrorText += "-";
1.166 + };
1.167 + parseErrorText += "^\n";
1.168 + };
1.169 + return parseErrorText;
1.170 + };
1.171 + // see non-IE version
1.172 + Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {
1.173 + oDoc.setProperty("SelectionLanguage", "XPath");
1.174 + oDoc.setProperty("SelectionNamespaces", sNsSet);
1.175 + };
1.176 + /**
1.177 + * Basic implementation of Mozilla's XSLTProcessor for IE.
1.178 + * Reuses the same XSLT stylesheet for multiple transforms
1.179 + * @constructor
1.180 + */
1.181 + function XSLTProcessor(){
1.182 + this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
1.183 + this.processor = null;
1.184 + };
1.185 + /**
1.186 + * Impoprts the given XSLT DOM and compiles it to a reusable transform
1.187 + * @argument xslDoc The XSLT DOMDocument to import
1.188 + */
1.189 + XSLTProcessor.prototype.importStylesheet = function(xslDoc){
1.190 + // convert stylesheet to free threaded
1.191 + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);
1.192 + converted.loadXML(xslDoc.xml);
1.193 + this.template.stylesheet = converted;
1.194 + this.processor = this.template.createProcessor();
1.195 + // (re)set default param values
1.196 + this.paramsSet = new Array();
1.197 + };
1.198 + /**
1.199 + * Transform the given XML DOM
1.200 + * @argument sourceDoc The XML DOMDocument to transform
1.201 + * @return The transformation result as a DOM Document
1.202 + */
1.203 + XSLTProcessor.prototype.transformToDocument = function(sourceDoc){
1.204 + this.processor.input = sourceDoc;
1.205 + var outDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.206 + this.processor.output = outDoc;
1.207 + this.processor.transform();
1.208 + return outDoc;
1.209 + };
1.210 + /**
1.211 + * Not sure if this works in IE. Maybe this will allow non-well-formed
1.212 + * transformation results (i.e. with no single root element)
1.213 + * @argument sourceDoc The XML DOMDocument to transform
1.214 + * @return The transformation result as a DOM Fragment
1.215 + */
1.216 + XSLTProcessor.prototype.transformToFragment = function(sourceDoc, ownerDocument){
1.217 + return this.transformToDocument(sourceDoc);
1.218 + };
1.219 + /**
1.220 + * Set global XSLT parameter of the imported stylesheet
1.221 + * @argument nsURI The parameter namespace URI
1.222 + * @argument name The parameter base name
1.223 + * @argument value The new parameter value
1.224 + */
1.225 + XSLTProcessor.prototype.setParameter = function(nsURI, name, value){
1.226 + /* nsURI is optional but cannot be null */
1.227 + if(nsURI){
1.228 + this.processor.addParameter(name, value, nsURI);
1.229 + }else{
1.230 + this.processor.addParameter(name, value);
1.231 + };
1.232 + /* update updated params for getParameter */
1.233 + if(!this.paramsSet[""+nsURI]){
1.234 + this.paramsSet[""+nsURI] = new Array();
1.235 + };
1.236 + this.paramsSet[""+nsURI][name] = value;
1.237 + };
1.238 + /**
1.239 + * Gets a parameter if previously set by setParameter. Returns null
1.240 + * otherwise
1.241 + * @argument name The parameter base name
1.242 + * @argument value The new parameter value
1.243 + * @return The parameter value if reviously set by setParameter, null otherwise
1.244 + */
1.245 + XSLTProcessor.prototype.getParameter = function(nsURI, name){
1.246 + if(this.paramsSet[""+nsURI] && this.paramsSet[""+nsURI][name])
1.247 + return this.paramsSet[""+nsURI][name];
1.248 + else
1.249 + return null;
1.250 + };
1.251 +}
1.252 +else{ /* end IE initialization, try to deal with real browsers now ;-) */
1.253 + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){
1.254 + if(window.XMLDocument){
1.255 + /**
1.256 + * <p>Emulate IE's onreadystatechange attribute</p>
1.257 + */
1.258 + XMLDocument.prototype.onreadystatechange = null;
1.259 + /**
1.260 + * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
1.261 + * <ul><li>1 == LOADING,</li>
1.262 + * <li>2 == LOADED,</li>
1.263 + * <li>3 == INTERACTIVE,</li>
1.264 + * <li>4 == COMPLETED</li></ul>
1.265 + */
1.266 + XMLDocument.prototype.readyState = 0;
1.267 + /**
1.268 + * <p>Emulate IE's parseError attribute</p>
1.269 + */
1.270 + XMLDocument.prototype.parseError = 0;
1.271 +
1.272 + // NOTE: setting async to false will only work with documents
1.273 + // called over HTTP (meaning a server), not the local file system,
1.274 + // unless you are using Moz 1.4+.
1.275 + // BTW the try>catch block is for 1.4; I haven't found a way to check if
1.276 + // the property is implemented without
1.277 + // causing an error and I dont want to use user agent stuff for that...
1.278 + var _SARISSA_SYNC_NON_IMPLEMENTED = false;
1.279 + try{
1.280 + /**
1.281 + * <p>Emulates IE's async property for Moz versions prior to 1.4.
1.282 + * It controls whether loading of remote XML files works
1.283 + * synchronously or asynchronously.</p>
1.284 + */
1.285 + XMLDocument.prototype.async = true;
1.286 + _SARISSA_SYNC_NON_IMPLEMENTED = true;
1.287 + }catch(e){/* trap */};
1.288 + /**
1.289 + * <p>Keeps a handle to the original load() method. Internal use and only
1.290 + * if Mozilla version is lower than 1.4</p>
1.291 + * @private
1.292 + */
1.293 + XMLDocument.prototype._sarissa_load = XMLDocument.prototype.load;
1.294 +
1.295 + /**
1.296 + * <p>Overrides the original load method to provide synchronous loading for
1.297 + * Mozilla versions prior to 1.4, using an XMLHttpRequest object (if
1.298 + * async is set to false)</p>
1.299 + * @returns the DOM Object as it was before the load() call (may be empty)
1.300 + */
1.301 + XMLDocument.prototype.load = function(sURI) {
1.302 + var oDoc = document.implementation.createDocument("", "", null);
1.303 + Sarissa.copyChildNodes(this, oDoc);
1.304 + this.parseError = 0;
1.305 + Sarissa.__setReadyState__(this, 1);
1.306 + try {
1.307 + if(this.async == false && _SARISSA_SYNC_NON_IMPLEMENTED) {
1.308 + var tmp = new XMLHttpRequest();
1.309 + tmp.open("GET", sURI, false);
1.310 + tmp.send(null);
1.311 + Sarissa.__setReadyState__(this, 2);
1.312 + Sarissa.copyChildNodes(tmp.responseXML, this);
1.313 + Sarissa.__setReadyState__(this, 3);
1.314 + }
1.315 + else {
1.316 + this._sarissa_load(sURI);
1.317 + };
1.318 + }
1.319 + catch (objException) {
1.320 + this.parseError = -1;
1.321 + }
1.322 + finally {
1.323 + if(this.async == false){
1.324 + Sarissa.__handleLoad__(this);
1.325 + };
1.326 + };
1.327 + return oDoc;
1.328 + };
1.329 +
1.330 + if(window.DOMParser && !XMLDocument.loadXML){
1.331 + /**
1.332 + * <p>Parses the String given as parameter to build the document content
1.333 + * for the object, exactly like IE's loadXML()</p>
1.334 + * @argument strXML The XML String to load as the Document's childNodes
1.335 + * @returns the old Document structure serialized as an XML String
1.336 + */
1.337 + XMLDocument.prototype.loadXML = function(strXML){
1.338 + Sarissa.__setReadyState__(this, 1);
1.339 + var sOldXML = this.xml;
1.340 + var oDoc = (new DOMParser()).parseFromString(strXML, "text/xml");
1.341 + Sarissa.__setReadyState__(this, 2);
1.342 + Sarissa.copyChildNodes(oDoc, this);
1.343 + Sarissa.__setReadyState__(this, 3);
1.344 + Sarissa.__handleLoad__(this);
1.345 + return sOldXML;
1.346 + };
1.347 + };//if(window.DOMParser && !XMLDocument.loadXML)
1.348 + };//if(window.XMLDocument)
1.349 +
1.350 + /**
1.351 + * <p>Ensures the document was loaded correctly, otherwise sets the
1.352 + * parseError to -1 to indicate something went wrong. Internal use</p>
1.353 + * @private
1.354 + */
1.355 + Sarissa.__handleLoad__ = function(oDoc){
1.356 + if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror")
1.357 + oDoc.parseError = -1;
1.358 + Sarissa.__setReadyState__(oDoc, 4);
1.359 + };
1.360 + /**
1.361 + * <p>Attached by an event handler to the load event. Internal use.</p>
1.362 + * @private
1.363 + */
1.364 + function _sarissa_XMLDocument_onload() {
1.365 + Sarissa.__handleLoad__(this);
1.366 + };
1.367 + /**
1.368 + * <p>Sets the readyState property of the given DOM Document object.
1.369 + * Internal use.</p>
1.370 + * @private
1.371 + * @argument oDoc the DOM Document object to fire the
1.372 + * readystatechange event
1.373 + * @argument iReadyState the number to change the readystate property to
1.374 + */
1.375 + Sarissa.__setReadyState__ = function(oDoc, iReadyState){
1.376 + oDoc.readyState = iReadyState;
1.377 + if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function")
1.378 + oDoc.onreadystatechange();
1.379 + };
1.380 + /**
1.381 + * <p>Factory method to obtain a new DOM Document object</p>
1.382 + * @argument sUri the namespace of the root node (if any)
1.383 + * @argument sUri the local name of the root node (if any)
1.384 + * @returns a new DOM Document
1.385 + */
1.386 + Sarissa.getDomDocument = function(sUri, sName){
1.387 + var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null);
1.388 + oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false);
1.389 + return oDoc;
1.390 + };
1.391 + };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT)
1.392 +};
1.393 +//==========================================
1.394 +// Common stuff
1.395 +//==========================================
1.396 +if(window.XMLHttpRequest){
1.397 + /**
1.398 + * <p><b>Deprecated, will be removed in 0.9.6</b>. Factory method to obtain a new XMLHTTP Request object</p>
1.399 + * @returns a new XMLHTTP Request object
1.400 + * @deprecated
1.401 + */
1.402 + Sarissa.getXmlHttpRequest = function() {
1.403 + return new XMLHttpRequest();
1.404 + };
1.405 + Sarissa.IS_ENABLED_XMLHTTP = true;
1.406 +};
1.407 +if(!window.document.importNode){
1.408 + /**
1.409 + * Implements importNode for the current window document in IE using innerHTML.
1.410 + * Testing showed that DOM was multiple times slower than innerHTML for this,
1.411 + * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML)
1.412 + * please gimme a call.
1.413 + * @param oNode the Node to import
1.414 + * @param bChildren whether to include the children of oNode
1.415 + * @returns the imported node for further use
1.416 + */
1.417 + window.document.importNode = function(oNode, bChildren){
1.418 + var importNode = document.createElement("div");
1.419 + if(bChildren)
1.420 + importNode.innerHTML = Sarissa.serialize(oNode);
1.421 + else
1.422 + importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false));
1.423 + return importNode.firstChild;
1.424 + };
1.425 +};
1.426 +if(!Sarissa.getParseErrorText){
1.427 + /**
1.428 + * <p>Returns a human readable description of the parsing error. Usefull
1.429 + * for debugging. Tip: append the returned error string in a <pre>
1.430 + * element if you want to render it.</p>
1.431 + * <p>Many thanks to Christian Stocker for the initial patch.</p>
1.432 + * @argument oDoc The target DOM document
1.433 + * @returns The parsing error description of the target Document in
1.434 + * human readable form (preformated text)
1.435 + */
1.436 + Sarissa.getParseErrorText = function (oDoc){
1.437 + var parseErrorText = Sarissa.PARSED_OK;
1.438 + if(oDoc.parseError != 0){
1.439 + /*moz*/
1.440 + if(oDoc.documentElement.tagName == "parsererror"){
1.441 + parseErrorText = oDoc.documentElement.firstChild.data;
1.442 + parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data;
1.443 + }/*konq*/
1.444 + else if(oDoc.documentElement.tagName == "html"){
1.445 + parseErrorText = Sarissa.getText(oDoc.documentElement.getElementsByTagName("h1")[0], false) + "\n";
1.446 + parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("body")[0], false) + "\n";
1.447 + parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false);
1.448 + };
1.449 + };
1.450 + return parseErrorText;
1.451 + };
1.452 +};
1.453 +Sarissa.getText = function(oNode, deep){
1.454 + var s = "";
1.455 + var nodes = oNode.childNodes;
1.456 + for(var i=0; i < nodes.length; i++){
1.457 + var node = nodes[i];
1.458 + if(node.nodeType == Node.TEXT_NODE){
1.459 + s += node.data;
1.460 + }else if(deep == true
1.461 + && (node.nodeType == Node.ELEMENT_NODE
1.462 + || node.nodeType == Node.DOCUMENT_NODE
1.463 + || node.nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
1.464 +
1.465 + s += Sarissa.getText(node, true);
1.466 + };
1.467 + };
1.468 + return s;
1.469 +};
1.470 +if(window.XMLSerializer){
1.471 + /**
1.472 + * <p>Factory method to obtain the serialization of a DOM Node</p>
1.473 + * @returns the serialized Node as an XML string
1.474 + */
1.475 + Sarissa.serialize = function(oDoc){
1.476 + return (new XMLSerializer()).serializeToString(oDoc);
1.477 + };
1.478 +}else{
1.479 + if((Sarissa.getDomDocument("","foo", null)).xml){
1.480 + // see non-IE version
1.481 + Sarissa.serialize = function(oDoc) {
1.482 + // TODO: check for HTML document and return innerHTML instead
1.483 + return oDoc.xml;
1.484 + };
1.485 + /**
1.486 + * Utility class to serialize DOM Node objects to XML strings
1.487 + * @constructor
1.488 + */
1.489 + XMLSerializer = function(){};
1.490 + /**
1.491 + * Serialize the given DOM Node to an XML string
1.492 + * @param oNode the DOM Node to serialize
1.493 + */
1.494 + XMLSerializer.prototype.serializeToString = function(oNode) {
1.495 + return oNode.xml;
1.496 + };
1.497 + };
1.498 +};
1.499 +if(window.XSLTProcessor){
1.500 + Sarissa.IS_ENABLED_XSLTPROC = true;
1.501 +};
1.502 +/**
1.503 + * strips tags from a markup string
1.504 + */
1.505 +Sarissa.stripTags = function (s) {
1.506 + return s.replace(/<[^>]+>/g,"");
1.507 +};
1.508 +/**
1.509 + * <p>Deletes all child nodes of the given node</p>
1.510 + * @argument oNode the Node to empty
1.511 + */
1.512 +Sarissa.clearChildNodes = function(oNode) {
1.513 + while(oNode.hasChildNodes()){
1.514 + oNode.removeChild(oNode.firstChild);
1.515 + };
1.516 +};
1.517 +/**
1.518 + * <p> Replaces the childNodes of the toDoc object with the childNodes of
1.519 + * the fromDoc object</p>
1.520 + * <p> <b>Note:</b> The second object's original content is deleted before the copy operation</p>
1.521 + * @argument nodeFrom the Node to copy the childNodes from
1.522 + * @argument nodeTo the Node to copy the childNodes to
1.523 + */
1.524 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo) {
1.525 + Sarissa.clearChildNodes(nodeTo);
1.526 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.527 + var nodes = nodeFrom.childNodes;
1.528 + if(typeof(ownerDoc.importNode) == "function"){
1.529 + for(var i=0;i < nodes.length;i++) {
1.530 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.531 + };
1.532 + }
1.533 + else{
1.534 + for(var i=0;i < nodes.length;i++) {
1.535 + nodeTo.appendChild(nodes[i].cloneNode(true));
1.536 + };
1.537 + };
1.538 +};
1.539 +
1.540 +/**
1.541 + * <p>Serialize any object to an XML string. All properties are serialized using the property name
1.542 + * as the XML element name. Array elements are rendered as <code>array-item</code> elements,
1.543 + * using their index/key as the value of the <code>key</code> attribute.</p>
1.544 + * @argument anyObject the object to serialize
1.545 + * @argument objectName a name for that object
1.546 + * @return the XML serializationj of the given object as a string
1.547 + */
1.548 +Sarissa.xmlize = function(anyObject, objectName, indentSpace){
1.549 + indentSpace = indentSpace?indentSpace:'';
1.550 + var s = indentSpace + '<' + objectName + '>';
1.551 + var isLeaf = false;
1.552 + if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String
1.553 + || anyObject instanceof Boolean || anyObject instanceof Date){
1.554 + s += Sarissa.escape(""+anyObject);
1.555 + isLeaf = true;
1.556 + }else{
1.557 + s += "\n";
1.558 + var itemKey = '';
1.559 + var isArrayItem = anyObject instanceof Array;
1.560 + for(var name in anyObject){
1.561 + s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " ");
1.562 + };
1.563 + s += indentSpace;
1.564 + };
1.565 + return s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n");
1.566 +};
1.567 +
1.568 +/**
1.569 + * Escape the given string chacters that correspond to the five predefined XML entities
1.570 + * @param sXml the string to escape
1.571 + */
1.572 +Sarissa.escape = function(sXml){
1.573 + return sXml.replace(/&/g, "&")
1.574 + .replace(/</g, "<")
1.575 + .replace(/>/g, ">")
1.576 + .replace(/"/g, """)
1.577 + .replace(/'/g, "'");
1.578 +};
1.579 +
1.580 +/**
1.581 + * Unescape the given string. This turns the occurences of the predefined XML
1.582 + * entities to become the characters they represent correspond to the five predefined XML entities
1.583 + * @param sXml the string to unescape
1.584 + */
1.585 +Sarissa.unescape = function(sXml){
1.586 + return sXml.replace(/'/g,"'")
1.587 + .replace(/"/g,"\"")
1.588 + .replace(/>/g,">")
1.589 + .replace(/</g,"<")
1.590 + .replace(/&/g,"&");
1.591 +};
1.592 +// EOF