1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/scripts/sarissa.js Sun Feb 03 20:05:15 2008 +0000
1.3 @@ -0,0 +1,688 @@
1.4 +/**
1.5 + * ====================================================================
1.6 + * About
1.7 + * ====================================================================
1.8 + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
1.9 + * The library supports Gecko based browsers like Mozilla and Firefox,
1.10 + * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera
1.11 + * @version ${project.version}
1.12 + * @author: @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net
1.13 + *
1.14 + * ====================================================================
1.15 + * Licence
1.16 + * ====================================================================
1.17 + * Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher,
1.18 + * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher
1.19 + * (see <a href="asl.txt">asl.txt</a>). This means you can choose one of the three and use that if you like. If
1.20 + * you make modifications under the ASL, i would appreciate it if you submitted those.
1.21 + * In case your copy of Sarissa does not include the license texts, you may find
1.22 + * them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and
1.23 + * <a href="http://www.apache.org">http://www.apache.org</a>.
1.24 + *
1.25 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
1.26 + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
1.27 + * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE
1.28 + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1.29 + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1.30 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1.31 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.32 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.33 + */
1.34 +/**
1.35 + * <p>Sarissa is a utility class. Provides "static" methods for DOMDocument,
1.36 + * DOM Node serialization to XML strings and other utility goodies.</p>
1.37 + * @constructor
1.38 + */
1.39 +function Sarissa(){};
1.40 +Sarissa.VERSION = "${project.version}";
1.41 +Sarissa.PARSED_OK = "Document contains no parsing errors";
1.42 +Sarissa.PARSED_EMPTY = "Document is empty";
1.43 +Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error";
1.44 +Sarissa.IS_ENABLED_TRANSFORM_NODE = false;
1.45 +var _sarissa_iNsCounter = 0;
1.46 +var _SARISSA_IEPREFIX4XSLPARAM = "";
1.47 +var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
1.48 +var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
1.49 +var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
1.50 +var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;
1.51 +var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("safari") != -1 || navigator.userAgent.toLowerCase().indexOf("konqueror") != -1;
1.52 +var _SARISSA_IS_SAFARI_OLD = _SARISSA_IS_SAFARI && parseInt((navigator.userAgent.match(/AppleWebKit\/(\d+)/)||{})[1]) < 420;
1.53 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
1.54 +var _SARISSA_IS_OPERA = navigator.userAgent.toLowerCase().indexOf("opera") != -1;
1.55 +if(!window.Node || !Node.ELEMENT_NODE){
1.56 + 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.57 +};
1.58 +
1.59 +//This breaks for(x in o) loops in the old Safari
1.60 +if(_SARISSA_IS_SAFARI_OLD){
1.61 + HTMLHtmlElement = document.createElement("html").constructor;
1.62 + Node = HTMLElement = {};
1.63 + HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
1.64 + HTMLDocument = Document = document.constructor;
1.65 + var x = new DOMParser();
1.66 + XMLDocument = x.constructor;
1.67 + Element = x.parseFromString("<Single />", "text/xml").documentElement.constructor;
1.68 + x = null;
1.69 +}
1.70 +if(typeof XMLDocument == "undefined" && typeof Document !="undefined"){ XMLDocument = Document; }
1.71 +
1.72 +// IE initialization
1.73 +if(_SARISSA_IS_IE){
1.74 + // for XSLT parameter names, prefix needed by IE
1.75 + _SARISSA_IEPREFIX4XSLPARAM = "xsl:";
1.76 + // used to store the most recent ProgID available out of the above
1.77 + var _SARISSA_DOM_PROGID = "";
1.78 + var _SARISSA_XMLHTTP_PROGID = "";
1.79 + var _SARISSA_DOM_XMLWRITER = "";
1.80 + /**
1.81 + * Called when the Sarissa_xx.js file is parsed, to pick most recent
1.82 + * ProgIDs for IE, then gets destroyed.
1.83 + * @private
1.84 + * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
1.85 + * @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.86 + */
1.87 + Sarissa.pickRecentProgID = function (idList){
1.88 + // found progID flag
1.89 + var bFound = false, e;
1.90 + for(var i=0; i < idList.length && !bFound; i++){
1.91 + try{
1.92 + var oDoc = new ActiveXObject(idList[i]);
1.93 + var o2Store = idList[i];
1.94 + bFound = true;
1.95 + }catch (objException){
1.96 + // trap; try next progID
1.97 + e = objException;
1.98 + };
1.99 + };
1.100 + if (!bFound) {
1.101 + throw "Could not retrieve a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
1.102 + };
1.103 + idList = null;
1.104 + return o2Store;
1.105 + };
1.106 + // pick best available MSXML progIDs
1.107 + _SARISSA_DOM_PROGID = null;
1.108 + _SARISSA_THREADEDDOM_PROGID = null;
1.109 + _SARISSA_XSLTEMPLATE_PROGID = null;
1.110 + _SARISSA_XMLHTTP_PROGID = null;
1.111 + if(!window.XMLHttpRequest){
1.112 + /**
1.113 + * Emulate XMLHttpRequest
1.114 + * @constructor
1.115 + */
1.116 + XMLHttpRequest = function() {
1.117 + if(!_SARISSA_XMLHTTP_PROGID){
1.118 + _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
1.119 + };
1.120 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.121 + };
1.122 + };
1.123 + // we dont need this anymore
1.124 + //============================================
1.125 + // Factory methods (IE)
1.126 + //============================================
1.127 + // see non-IE version
1.128 + Sarissa.getDomDocument = function(sUri, sName){
1.129 + if(!_SARISSA_DOM_PROGID){
1.130 + _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]);
1.131 + };
1.132 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.133 + // if a root tag name was provided, we need to load it in the DOM object
1.134 + if (sName){
1.135 + // create an artifical namespace prefix
1.136 + // or reuse existing prefix if applicable
1.137 + var prefix = "";
1.138 + if(sUri){
1.139 + if(sName.indexOf(":") > 1){
1.140 + prefix = sName.substring(0, sName.indexOf(":"));
1.141 + sName = sName.substring(sName.indexOf(":")+1);
1.142 + }else{
1.143 + prefix = "a" + (_sarissa_iNsCounter++);
1.144 + };
1.145 + };
1.146 + // use namespaces if a namespace URI exists
1.147 + if(sUri){
1.148 + oDoc.loadXML('<' + prefix+':'+sName + " xmlns:" + prefix + "=\"" + sUri + "\"" + " />");
1.149 + } else {
1.150 + oDoc.loadXML('<' + sName + " />");
1.151 + };
1.152 + };
1.153 + return oDoc;
1.154 + };
1.155 + // see non-IE version
1.156 + Sarissa.getParseErrorText = function (oDoc) {
1.157 + var parseErrorText = Sarissa.PARSED_OK;
1.158 + if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.parseError.errorCode != 0){
1.159 + parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason +
1.160 + "\nLocation: " + oDoc.parseError.url +
1.161 + "\nLine Number " + oDoc.parseError.line + ", Column " +
1.162 + oDoc.parseError.linepos +
1.163 + ":\n" + oDoc.parseError.srcText +
1.164 + "\n";
1.165 + for(var i = 0; i < oDoc.parseError.linepos;i++){
1.166 + parseErrorText += "-";
1.167 + };
1.168 + parseErrorText += "^\n";
1.169 + }
1.170 + else if(oDoc.documentElement == null){
1.171 + parseErrorText = Sarissa.PARSED_EMPTY;
1.172 + };
1.173 + return parseErrorText;
1.174 + };
1.175 + // see non-IE version
1.176 + Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {
1.177 + oDoc.setProperty("SelectionLanguage", "XPath");
1.178 + oDoc.setProperty("SelectionNamespaces", sNsSet);
1.179 + };
1.180 + /**
1.181 + * Basic implementation of Mozilla's XSLTProcessor for IE.
1.182 + * Reuses the same XSLT stylesheet for multiple transforms
1.183 + * @constructor
1.184 + */
1.185 + XSLTProcessor = function(){
1.186 + if(!_SARISSA_XSLTEMPLATE_PROGID){
1.187 + _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID(["Msxml2.XSLTemplate.6.0", "MSXML2.XSLTemplate.3.0"]);
1.188 + };
1.189 + this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
1.190 + this.processor = null;
1.191 + };
1.192 + /**
1.193 + * Imports the given XSLT DOM and compiles it to a reusable transform
1.194 + * <b>Note:</b> If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those
1.195 + * @argument xslDoc The XSLT DOMDocument to import
1.196 + */
1.197 + XSLTProcessor.prototype.importStylesheet = function(xslDoc){
1.198 + if(!_SARISSA_THREADEDDOM_PROGID){
1.199 + _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID(["MSXML2.FreeThreadedDOMDocument.6.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
1.200 + };
1.201 + xslDoc.setProperty("SelectionLanguage", "XPath");
1.202 + xslDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
1.203 + // convert stylesheet to free threaded
1.204 + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);
1.205 + // make included/imported stylesheets work if exist and xsl was originally loaded from url
1.206 + try{
1.207 + converted.resolveExternals = true;
1.208 + converted.setProperty("AllowDocumentFunction", true);
1.209 + }
1.210 + catch(e){
1.211 + // Ignore. "AllowDocumentFunction" is only supported in MSXML 3.0 SP4 and later.
1.212 + };
1.213 + if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() = 'import' or local-name() = 'include']") != null){
1.214 + converted.async = false;
1.215 + converted.load(xslDoc.url);
1.216 + } else {
1.217 + converted.loadXML(xslDoc.xml);
1.218 + };
1.219 + converted.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
1.220 + var output = converted.selectSingleNode("//xsl:output");
1.221 + this.outputMethod = output ? output.getAttribute("method") : "html";
1.222 + this.template.stylesheet = converted;
1.223 + this.processor = this.template.createProcessor();
1.224 + // for getParameter and clearParameters
1.225 + this.paramsSet = [];
1.226 + };
1.227 +
1.228 + /**
1.229 + * Transform the given XML DOM and return the transformation result as a new DOM document
1.230 + * @argument sourceDoc The XML DOMDocument to transform
1.231 + * @return The transformation result as a DOM Document
1.232 + */
1.233 + XSLTProcessor.prototype.transformToDocument = function(sourceDoc){
1.234 + // fix for bug 1549749
1.235 + if(_SARISSA_THREADEDDOM_PROGID){
1.236 + this.processor.input=sourceDoc;
1.237 + var outDoc=new ActiveXObject(_SARISSA_DOM_PROGID);
1.238 + this.processor.output=outDoc;
1.239 + this.processor.transform();
1.240 + return outDoc;
1.241 + }
1.242 + else{
1.243 + if(!_SARISSA_DOM_XMLWRITER){
1.244 + _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID(["Msxml2.MXXMLWriter.6.0", "Msxml2.MXXMLWriter.3.0", "MSXML2.MXXMLWriter", "MSXML.MXXMLWriter", "Microsoft.XMLDOM"]);
1.245 + };
1.246 + this.processor.input = sourceDoc;
1.247 + var outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER);
1.248 + this.processor.output = outDoc;
1.249 + this.processor.transform();
1.250 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.251 + oDoc.loadXML(outDoc.output+"");
1.252 + return oDoc;
1.253 + };
1.254 + };
1.255 +
1.256 + /**
1.257 + * Transform the given XML DOM and return the transformation result as a new DOM fragment.
1.258 + * <b>Note</b>: The xsl:output method must match the nature of the owner document (XML/HTML).
1.259 + * @argument sourceDoc The XML DOMDocument to transform
1.260 + * @argument ownerDoc The owner of the result fragment
1.261 + * @return The transformation result as a DOM Document
1.262 + */
1.263 + XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) {
1.264 + this.processor.input = sourceDoc;
1.265 + this.processor.transform();
1.266 + var s = this.processor.output;
1.267 + var f = ownerDoc.createDocumentFragment();
1.268 + if (this.outputMethod == 'text') {
1.269 + f.appendChild(ownerDoc.createTextNode(s));
1.270 + } else if (ownerDoc.body && ownerDoc.body.innerHTML) {
1.271 + var container = ownerDoc.createElement('div');
1.272 + container.innerHTML = s;
1.273 + while (container.hasChildNodes()) {
1.274 + f.appendChild(container.firstChild);
1.275 + }
1.276 + }
1.277 + else {
1.278 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.279 + if (s.substring(0, 5) == '<?xml') {
1.280 + s = s.substring(s.indexOf('?>') + 2);
1.281 + }
1.282 + var xml = ''.concat('<my>', s, '</my>');
1.283 + oDoc.loadXML(xml);
1.284 + var container = oDoc.documentElement;
1.285 + while (container.hasChildNodes()) {
1.286 + f.appendChild(container.firstChild);
1.287 + }
1.288 + }
1.289 + return f;
1.290 + };
1.291 +
1.292 + /**
1.293 + * Set global XSLT parameter of the imported stylesheet
1.294 + * @argument nsURI The parameter namespace URI
1.295 + * @argument name The parameter base name
1.296 + * @argument value The new parameter value
1.297 + */
1.298 + XSLTProcessor.prototype.setParameter = function(nsURI, name, value){
1.299 + // make value a zero length string if null to allow clearing
1.300 + value = value ? value : "";
1.301 + // nsURI is optional but cannot be null
1.302 + if(nsURI){
1.303 + this.processor.addParameter(name, value, nsURI);
1.304 + }else{
1.305 + this.processor.addParameter(name, value);
1.306 + };
1.307 + // update updated params for getParameter
1.308 + nsURI = "" + (nsURI || "");
1.309 + if(!this.paramsSet[nsURI]){
1.310 + this.paramsSet[nsURI] = new Array();
1.311 + };
1.312 + this.paramsSet[nsURI][name] = value;
1.313 + };
1.314 + /**
1.315 + * Gets a parameter if previously set by setParameter. Returns null
1.316 + * otherwise
1.317 + * @argument name The parameter base name
1.318 + * @argument value The new parameter value
1.319 + * @return The parameter value if reviously set by setParameter, null otherwise
1.320 + */
1.321 + XSLTProcessor.prototype.getParameter = function(nsURI, name){
1.322 + nsURI = "" + (nsURI || "");
1.323 + if(this.paramsSet[nsURI] && this.paramsSet[nsURI][name]){
1.324 + return this.paramsSet[nsURI][name];
1.325 + }else{
1.326 + return null;
1.327 + };
1.328 + };
1.329 + /**
1.330 + * Clear parameters (set them to default values as defined in the stylesheet itself)
1.331 + */
1.332 + XSLTProcessor.prototype.clearParameters = function(){
1.333 + for(var nsURI in this.paramsSet){
1.334 + for(var name in this.paramsSet[nsURI]){
1.335 + if(nsURI!=""){
1.336 + this.processor.addParameter(name, "", nsURI);
1.337 + }else{
1.338 + this.processor.addParameter(name, "");
1.339 + };
1.340 + };
1.341 + };
1.342 + this.paramsSet = new Array();
1.343 + };
1.344 +}else{ /* end IE initialization, try to deal with real browsers now ;-) */
1.345 + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){
1.346 + /**
1.347 + * <p>Ensures the document was loaded correctly, otherwise sets the
1.348 + * parseError to -1 to indicate something went wrong. Internal use</p>
1.349 + * @private
1.350 + */
1.351 + Sarissa.__handleLoad__ = function(oDoc){
1.352 + Sarissa.__setReadyState__(oDoc, 4);
1.353 + };
1.354 + /**
1.355 + * <p>Attached by an event handler to the load event. Internal use.</p>
1.356 + * @private
1.357 + */
1.358 + _sarissa_XMLDocument_onload = function(){
1.359 + Sarissa.__handleLoad__(this);
1.360 + };
1.361 + /**
1.362 + * <p>Sets the readyState property of the given DOM Document object.
1.363 + * Internal use.</p>
1.364 + * @private
1.365 + * @argument oDoc the DOM Document object to fire the
1.366 + * readystatechange event
1.367 + * @argument iReadyState the number to change the readystate property to
1.368 + */
1.369 + Sarissa.__setReadyState__ = function(oDoc, iReadyState){
1.370 + oDoc.readyState = iReadyState;
1.371 + oDoc.readystate = iReadyState;
1.372 + if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") {
1.373 + oDoc.onreadystatechange();
1.374 + }
1.375 + };
1.376 + Sarissa.getDomDocument = function(sUri, sName){
1.377 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.378 + if(!oDoc.onreadystatechange){
1.379 +
1.380 + /**
1.381 + * <p>Emulate IE's onreadystatechange attribute</p>
1.382 + */
1.383 + oDoc.onreadystatechange = null;
1.384 + };
1.385 + if(!oDoc.readyState){
1.386 + /**
1.387 + * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
1.388 + * <ul><li>1 == LOADING,</li>
1.389 + * <li>2 == LOADED,</li>
1.390 + * <li>3 == INTERACTIVE,</li>
1.391 + * <li>4 == COMPLETED</li></ul>
1.392 + */
1.393 + oDoc.readyState = 0;
1.394 + };
1.395 + oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false);
1.396 + return oDoc;
1.397 + };
1.398 + if(window.XMLDocument){
1.399 + // do nothing
1.400 + }// TODO: check if the new document has content before trying to copynodes, check for error handling in DOM 3 LS
1.401 + else if(_SARISSA_HAS_DOM_FEATURE && window.Document && !Document.prototype.load && document.implementation.hasFeature('LS', '3.0')){
1.402 + //Opera 9 may get the XPath branch which gives creates XMLDocument, therefore it doesn't reach here which is good
1.403 + /**
1.404 + * <p>Factory method to obtain a new DOM Document object</p>
1.405 + * @argument sUri the namespace of the root node (if any)
1.406 + * @argument sUri the local name of the root node (if any)
1.407 + * @returns a new DOM Document
1.408 + */
1.409 + Sarissa.getDomDocument = function(sUri, sName){
1.410 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.411 + return oDoc;
1.412 + };
1.413 + }
1.414 + else {
1.415 + Sarissa.getDomDocument = function(sUri, sName){
1.416 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.417 + // looks like safari does not create the root element for some unknown reason
1.418 + if(oDoc && (sUri || sName) && !oDoc.documentElement){
1.419 + oDoc.appendChild(oDoc.createElementNS(sUri, sName));
1.420 + };
1.421 + return oDoc;
1.422 + };
1.423 + };
1.424 + };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT)
1.425 +};
1.426 +//==========================================
1.427 +// Common stuff
1.428 +//==========================================
1.429 +if(!window.DOMParser){
1.430 + if(_SARISSA_IS_SAFARI){
1.431 + /*
1.432 + * DOMParser is a utility class, used to construct DOMDocuments from XML strings
1.433 + * @constructor
1.434 + */
1.435 + DOMParser = function() { };
1.436 + /**
1.437 + * Construct a new DOM Document from the given XMLstring
1.438 + * @param sXml the given XML string
1.439 + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml).
1.440 + * @return a new DOM Document from the given XML string
1.441 + */
1.442 + DOMParser.prototype.parseFromString = function(sXml, contentType){
1.443 + var xmlhttp = new XMLHttpRequest();
1.444 + xmlhttp.open("GET", "data:text/xml;charset=utf-8," + encodeURIComponent(sXml), false);
1.445 + xmlhttp.send(null);
1.446 + return xmlhttp.responseXML;
1.447 + };
1.448 + }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && Sarissa.getDomDocument(null, "bar").xml){
1.449 + DOMParser = function() { };
1.450 + DOMParser.prototype.parseFromString = function(sXml, contentType){
1.451 + var doc = Sarissa.getDomDocument();
1.452 + doc.loadXML(sXml);
1.453 + return doc;
1.454 + };
1.455 + };
1.456 +};
1.457 +
1.458 +if((typeof(document.importNode) == "undefined") && _SARISSA_IS_IE){
1.459 + try{
1.460 + /**
1.461 + * Implementation of importNode for the context window document in IE.
1.462 + * If <code>oNode</code> is a TextNode, <code>bChildren</code> is ignored.
1.463 + * @param oNode the Node to import
1.464 + * @param bChildren whether to include the children of oNode
1.465 + * @returns the imported node for further use
1.466 + */
1.467 + document.importNode = function(oNode, bChildren){
1.468 + var tmp;
1.469 + if (oNode.nodeName=='#text') {
1.470 + return document.createTextElement(oNode.data);
1.471 + }
1.472 + else {
1.473 + if(oNode.nodeName == "tbody" || oNode.nodeName == "tr"){
1.474 + tmp = document.createElement("table");
1.475 + }
1.476 + else if(oNode.nodeName == "td"){
1.477 + tmp = document.createElement("tr");
1.478 + }
1.479 + else if(oNode.nodeName == "option"){
1.480 + tmp = document.createElement("select");
1.481 + }
1.482 + else{
1.483 + tmp = document.createElement("div");
1.484 + };
1.485 + if(bChildren){
1.486 + tmp.innerHTML = oNode.xml ? oNode.xml : oNode.outerHTML;
1.487 + }else{
1.488 + tmp.innerHTML = oNode.xml ? oNode.cloneNode(false).xml : oNode.cloneNode(false).outerHTML;
1.489 + };
1.490 + return tmp.getElementsByTagName("*")[0];
1.491 + };
1.492 +
1.493 + };
1.494 + }catch(e){ };
1.495 +};
1.496 +if(!Sarissa.getParseErrorText){
1.497 + /**
1.498 + * <p>Returns a human readable description of the parsing error. Usefull
1.499 + * for debugging. Tip: append the returned error string in a <pre>
1.500 + * element if you want to render it.</p>
1.501 + * <p>Many thanks to Christian Stocker for the initial patch.</p>
1.502 + * @argument oDoc The target DOM document
1.503 + * @returns The parsing error description of the target Document in
1.504 + * human readable form (preformated text)
1.505 + */
1.506 + Sarissa.getParseErrorText = function (oDoc){
1.507 + var parseErrorText = Sarissa.PARSED_OK;
1.508 + if(!oDoc.documentElement){
1.509 + parseErrorText = Sarissa.PARSED_EMPTY;
1.510 + } else if(oDoc.documentElement.tagName == "parsererror"){
1.511 + parseErrorText = oDoc.documentElement.firstChild.data;
1.512 + parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data;
1.513 + } else if(oDoc.getElementsByTagName("parsererror").length > 0){
1.514 + var parsererror = oDoc.getElementsByTagName("parsererror")[0];
1.515 + parseErrorText = Sarissa.getText(parsererror, true)+"\n";
1.516 + } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){
1.517 + parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR;
1.518 + };
1.519 + return parseErrorText;
1.520 + };
1.521 +};
1.522 +Sarissa.getText = function(oNode, deep){
1.523 + var s = "";
1.524 + var nodes = oNode.childNodes;
1.525 + for(var i=0; i < nodes.length; i++){
1.526 + var node = nodes[i];
1.527 + var nodeType = node.nodeType;
1.528 + if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
1.529 + s += node.data;
1.530 + } else if(deep == true
1.531 + && (nodeType == Node.ELEMENT_NODE
1.532 + || nodeType == Node.DOCUMENT_NODE
1.533 + || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
1.534 + s += Sarissa.getText(node, true);
1.535 + };
1.536 + };
1.537 + return s;
1.538 +};
1.539 +if(!window.XMLSerializer
1.540 + && Sarissa.getDomDocument
1.541 + && Sarissa.getDomDocument("","foo", null).xml){
1.542 + /**
1.543 + * Utility class to serialize DOM Node objects to XML strings
1.544 + * @constructor
1.545 + */
1.546 + XMLSerializer = function(){};
1.547 + /**
1.548 + * Serialize the given DOM Node to an XML string
1.549 + * @param oNode the DOM Node to serialize
1.550 + */
1.551 + XMLSerializer.prototype.serializeToString = function(oNode) {
1.552 + return oNode.xml;
1.553 + };
1.554 +};
1.555 +
1.556 +/**
1.557 + * strips tags from a markup string
1.558 + */
1.559 +Sarissa.stripTags = function (s) {
1.560 + return s.replace(/<[^>]+>/g,"");
1.561 +};
1.562 +/**
1.563 + * <p>Deletes all child nodes of the given node</p>
1.564 + * @argument oNode the Node to empty
1.565 + */
1.566 +Sarissa.clearChildNodes = function(oNode) {
1.567 + // need to check for firstChild due to opera 8 bug with hasChildNodes
1.568 + while(oNode.firstChild) {
1.569 + oNode.removeChild(oNode.firstChild);
1.570 + };
1.571 +};
1.572 +/**
1.573 + * <p> Copies the childNodes of nodeFrom to nodeTo</p>
1.574 + * <p> <b>Note:</b> The second object's original content is deleted before
1.575 + * the copy operation, unless you supply a true third parameter</p>
1.576 + * @argument nodeFrom the Node to copy the childNodes from
1.577 + * @argument nodeTo the Node to copy the childNodes to
1.578 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
1.579 + */
1.580 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.581 + if(_SARISSA_IS_SAFARI && nodeTo.nodeType == Node.DOCUMENT_NODE){ // SAFARI_OLD ??
1.582 + nodeTo = nodeTo.documentElement; //Appearantly there's a bug in safari where you can't appendChild to a document node
1.583 + }
1.584 +
1.585 + if((!nodeFrom) || (!nodeTo)){
1.586 + throw "Both source and destination nodes must be provided";
1.587 + };
1.588 + if(!bPreserveExisting){
1.589 + Sarissa.clearChildNodes(nodeTo);
1.590 + };
1.591 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.592 + var nodes = nodeFrom.childNodes;
1.593 + if(typeof(ownerDoc.importNode) != "undefined") {
1.594 + for(var i=0;i < nodes.length;i++) {
1.595 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.596 + };
1.597 + } else {
1.598 + for(var i=0;i < nodes.length;i++) {
1.599 + nodeTo.appendChild(nodes[i].cloneNode(true));
1.600 + };
1.601 + };
1.602 +};
1.603 +
1.604 +/**
1.605 + * <p> Moves the childNodes of nodeFrom to nodeTo</p>
1.606 + * <p> <b>Note:</b> The second object's original content is deleted before
1.607 + * the move operation, unless you supply a true third parameter</p>
1.608 + * @argument nodeFrom the Node to copy the childNodes from
1.609 + * @argument nodeTo the Node to copy the childNodes to
1.610 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is
1.611 + */
1.612 +Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.613 + if((!nodeFrom) || (!nodeTo)){
1.614 + throw "Both source and destination nodes must be provided";
1.615 + };
1.616 + if(!bPreserveExisting){
1.617 + Sarissa.clearChildNodes(nodeTo);
1.618 + };
1.619 + var nodes = nodeFrom.childNodes;
1.620 + // if within the same doc, just move, else copy and delete
1.621 + if(nodeFrom.ownerDocument == nodeTo.ownerDocument){
1.622 + while(nodeFrom.firstChild){
1.623 + nodeTo.appendChild(nodeFrom.firstChild);
1.624 + };
1.625 + } else {
1.626 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.627 + if(typeof(ownerDoc.importNode) != "undefined") {
1.628 + for(var i=0;i < nodes.length;i++) {
1.629 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.630 + };
1.631 + }else{
1.632 + for(var i=0;i < nodes.length;i++) {
1.633 + nodeTo.appendChild(nodes[i].cloneNode(true));
1.634 + };
1.635 + };
1.636 + Sarissa.clearChildNodes(nodeFrom);
1.637 + };
1.638 +};
1.639 +
1.640 +/**
1.641 + * <p>Serialize any <strong>non</strong> DOM object to an XML string. All properties are serialized using the property name
1.642 + * as the XML element name. Array elements are rendered as <code>array-item</code> elements,
1.643 + * using their index/key as the value of the <code>key</code> attribute.</p>
1.644 + * @argument anyObject the object to serialize
1.645 + * @argument objectName a name for that object
1.646 + * @return the XML serialization of the given object as a string
1.647 + */
1.648 +Sarissa.xmlize = function(anyObject, objectName, indentSpace){
1.649 + indentSpace = indentSpace?indentSpace:'';
1.650 + var s = indentSpace + '<' + objectName + '>';
1.651 + var isLeaf = false;
1.652 + if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String
1.653 + || anyObject instanceof Boolean || anyObject instanceof Date){
1.654 + s += Sarissa.escape(""+anyObject);
1.655 + isLeaf = true;
1.656 + }else{
1.657 + s += "\n";
1.658 + var isArrayItem = anyObject instanceof Array;
1.659 + for(var name in anyObject){
1.660 + s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " ");
1.661 + };
1.662 + s += indentSpace;
1.663 + };
1.664 + return (s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n"));
1.665 +};
1.666 +
1.667 +/**
1.668 + * Escape the given string chacters that correspond to the five predefined XML entities
1.669 + * @param sXml the string to escape
1.670 + */
1.671 +Sarissa.escape = function(sXml){
1.672 + return sXml.replace(/&/g, "&")
1.673 + .replace(/</g, "<")
1.674 + .replace(/>/g, ">")
1.675 + .replace(/"/g, """)
1.676 + .replace(/'/g, "'");
1.677 +};
1.678 +
1.679 +/**
1.680 + * Unescape the given string. This turns the occurences of the predefined XML
1.681 + * entities to become the characters they represent correspond to the five predefined XML entities
1.682 + * @param sXml the string to unescape
1.683 + */
1.684 +Sarissa.unescape = function(sXml){
1.685 + return sXml.replace(/'/g,"'")
1.686 + .replace(/"/g,"\"")
1.687 + .replace(/>/g,">")
1.688 + .replace(/</g,"<")
1.689 + .replace(/&/g,"&");
1.690 +};
1.691 +// EOF