1.1 --- a/examples/Common/Configurator/Resources/scripts/sarissa.js Sun Jun 10 22:52:12 2007 +0000
1.2 +++ b/examples/Common/Configurator/Resources/scripts/sarissa.js Sat Jul 07 16:17:29 2007 +0000
1.3 @@ -2,72 +2,54 @@
1.4 * ====================================================================
1.5 * About
1.6 * ====================================================================
1.7 - * Sarissa cross browser XML library
1.8 - * @version 0.9.6
1.9 - * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
1.10 - *
1.11 * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
1.12 * The library supports Gecko based browsers like Mozilla and Firefox,
1.13 - * Internet Explorer (5.5+ with MSXML3.0+) and, last but not least, KHTML based browsers like
1.14 - * Konqueror and Safari.
1.15 - *
1.16 + * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera
1.17 + * @version ${project.version}
1.18 + * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
1.19 * ====================================================================
1.20 * Licence
1.21 * ====================================================================
1.22 - * This program is free software; you can redistribute it and/or modify
1.23 - * it under the terms of the GNU General Public License version 2 or
1.24 - * the GNU Lesser General Public License version 2.1 as published by
1.25 - * the Free Software Foundation (your choice of the two).
1.26 - *
1.27 - * This program is distributed in the hope that it will be useful,
1.28 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.29 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.30 - * GNU General Public License or GNU Lesser General Public License for more details.
1.31 - *
1.32 - * You should have received a copy of the GNU General Public License
1.33 - * or GNU Lesser General Public License along with this program; if not,
1.34 - * write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.35 - * or visit http://www.gnu.org
1.36 - *
1.37 + * Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher,
1.38 + * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher
1.39 + * (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.40 + * you make modifications under the ASL, i would appreciate it if you submitted those.
1.41 + * In case your copy of Sarissa does not include the license texts, you may find
1.42 + * them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and
1.43 + * <a href="http://www.apache.org">http://www.apache.org</a>.
1.44 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
1.45 + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
1.46 + * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE
1.47 + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1.48 + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1.49 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1.50 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.51 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.52 */
1.53 /**
1.54 - * <p>Sarissa is a utility class. Provides static methods for DOMDocument and
1.55 - * XMLHTTP objects, DOM Node serializatrion to XML strings and other goodies.</p>
1.56 + * <p>Sarissa is a utility class. Provides "static" methods for DOMDocument,
1.57 + * DOM Node serialization to XML strings and other utility goodies.</p>
1.58 * @constructor
1.59 */
1.60 function Sarissa(){};
1.61 -/** @private */
1.62 +Sarissa.VERSION = "${project.version}";
1.63 Sarissa.PARSED_OK = "Document contains no parsing errors";
1.64 -/**
1.65 - * Tells you whether transformNode and transformNodeToObject are available. This functionality
1.66 - * is contained in sarissa_ieemu_xslt.js and is deprecated. If you want to control XSLT transformations
1.67 - * use the XSLTProcessor
1.68 - * @deprecated
1.69 - * @type boolean
1.70 - */
1.71 +Sarissa.PARSED_EMPTY = "Document is empty";
1.72 +Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error";
1.73 Sarissa.IS_ENABLED_TRANSFORM_NODE = false;
1.74 -/**
1.75 - * tells you whether XMLHttpRequest (or equivalent) is available
1.76 - * @type boolean
1.77 - */
1.78 -Sarissa.IS_ENABLED_XMLHTTP = false;
1.79 -/**
1.80 - * tells you whether selectNodes/selectSingleNode is available
1.81 - * @type boolean
1.82 - */
1.83 -Sarissa.IS_ENABLED_SELECT_NODES = false;
1.84 var _sarissa_iNsCounter = 0;
1.85 var _SARISSA_IEPREFIX4XSLPARAM = "";
1.86 var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
1.87 var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
1.88 var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
1.89 var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;
1.90 -var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1;
1.91 +var _SARISSA_IS_SAFARI = (navigator.userAgent && navigator.vendor && (navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1 || navigator.vendor.indexOf("Apple") != -1));
1.92 var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
1.93 +if(!window.Node || !Node.ELEMENT_NODE){
1.94 + 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.95 +};
1.96
1.97 -if(!window.Node || !window.Node.ELEMENT_NODE){
1.98 - 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.99 -};
1.100 +if(typeof XMLDocument == "undefined" && typeof Document !="undefined"){ XMLDocument = Document; }
1.101
1.102 // IE initialization
1.103 if(_SARISSA_IS_IE){
1.104 @@ -76,13 +58,15 @@
1.105 // used to store the most recent ProgID available out of the above
1.106 var _SARISSA_DOM_PROGID = "";
1.107 var _SARISSA_XMLHTTP_PROGID = "";
1.108 + var _SARISSA_DOM_XMLWRITER = "";
1.109 /**
1.110 * Called when the Sarissa_xx.js file is parsed, to pick most recent
1.111 * ProgIDs for IE, then gets destroyed.
1.112 + * @private
1.113 * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
1.114 * @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.115 */
1.116 - pickRecentProgID = function (idList, enabledList){
1.117 + Sarissa.pickRecentProgID = function (idList){
1.118 // found progID flag
1.119 var bFound = false;
1.120 for(var i=0; i < idList.length && !bFound; i++){
1.121 @@ -90,50 +74,69 @@
1.122 var oDoc = new ActiveXObject(idList[i]);
1.123 o2Store = idList[i];
1.124 bFound = true;
1.125 - for(var j=0;j<enabledList.length;j++)
1.126 - if(i <= enabledList[j][1])
1.127 - Sarissa["IS_ENABLED_"+enabledList[j][0]] = true;
1.128 }catch (objException){
1.129 // trap; try next progID
1.130 };
1.131 };
1.132 - if (!bFound)
1.133 + if (!bFound) {
1.134 throw "Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
1.135 + };
1.136 idList = null;
1.137 return o2Store;
1.138 };
1.139 // pick best available MSXML progIDs
1.140 - _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.141 - _SARISSA_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]);
1.142 - _SARISSA_THREADEDDOM_PROGID = pickRecentProgID(["Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
1.143 - _SARISSA_XSLTEMPLATE_PROGID = pickRecentProgID(["Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0"], [["XSLTPROC", 2]]);
1.144 + _SARISSA_DOM_PROGID = null;
1.145 + _SARISSA_THREADEDDOM_PROGID = null;
1.146 + _SARISSA_XSLTEMPLATE_PROGID = null;
1.147 + _SARISSA_XMLHTTP_PROGID = null;
1.148 + if(!window.XMLHttpRequest){
1.149 + /**
1.150 + * Emulate XMLHttpRequest
1.151 + * @constructor
1.152 + */
1.153 + XMLHttpRequest = function() {
1.154 + if(!_SARISSA_XMLHTTP_PROGID){
1.155 + _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
1.156 + };
1.157 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.158 + };
1.159 + };
1.160 // we dont need this anymore
1.161 - pickRecentProgID = null;
1.162 //============================================
1.163 // Factory methods (IE)
1.164 //============================================
1.165 // see non-IE version
1.166 Sarissa.getDomDocument = function(sUri, sName){
1.167 + if(!_SARISSA_DOM_PROGID){
1.168 + _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]);
1.169 + };
1.170 var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.171 - // if a root tag name was provided, we need to load it in the DOM
1.172 - // object
1.173 + // if a root tag name was provided, we need to load it in the DOM object
1.174 if (sName){
1.175 - // if needed, create an artifical namespace prefix the way Moz
1.176 - // does
1.177 - if (sUri){
1.178 - oDoc.loadXML("<a" + _sarissa_iNsCounter + ":" + sName + " xmlns:a" + _sarissa_iNsCounter + "=\"" + sUri + "\" />");
1.179 - // don't use the same prefix again
1.180 - ++_sarissa_iNsCounter;
1.181 - }
1.182 - else
1.183 - oDoc.loadXML("<" + sName + "/>");
1.184 + // create an artifical namespace prefix
1.185 + // or reuse existing prefix if applicable
1.186 + var prefix = "";
1.187 + if(sUri){
1.188 + if(sName.indexOf(":") > 1){
1.189 + prefix = sName.substring(0, sName.indexOf(":"));
1.190 + sName = sName.substring(sName.indexOf(":")+1);
1.191 + }else{
1.192 + prefix = "a" + (_sarissa_iNsCounter++);
1.193 + };
1.194 + };
1.195 + // use namespaces if a namespace URI exists
1.196 + if(sUri){
1.197 + oDoc.loadXML('<' + prefix+':'+sName + " xmlns:" + prefix + "=\"" + sUri + "\"" + " />");
1.198 + } else {
1.199 + oDoc.loadXML('<' + sName + " />");
1.200 + };
1.201 };
1.202 return oDoc;
1.203 };
1.204 // see non-IE version
1.205 Sarissa.getParseErrorText = function (oDoc) {
1.206 var parseErrorText = Sarissa.PARSED_OK;
1.207 - if(oDoc.parseError != 0){
1.208 + if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.parseError.errorCode != 0){
1.209 parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason +
1.210 "\nLocation: " + oDoc.parseError.url +
1.211 "\nLine Number " + oDoc.parseError.line + ", Column " +
1.212 @@ -144,6 +147,9 @@
1.213 parseErrorText += "-";
1.214 };
1.215 parseErrorText += "^\n";
1.216 + }
1.217 + else if(oDoc.documentElement == null){
1.218 + parseErrorText = Sarissa.PARSED_EMPTY;
1.219 };
1.220 return parseErrorText;
1.221 };
1.222 @@ -158,43 +164,109 @@
1.223 * @constructor
1.224 */
1.225 XSLTProcessor = function(){
1.226 + if(!_SARISSA_XSLTEMPLATE_PROGID){
1.227 + _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID(["Msxml2.XSLTemplate.6.0", "MSXML2.XSLTemplate.3.0"]);
1.228 + };
1.229 this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
1.230 this.processor = null;
1.231 };
1.232 /**
1.233 - * Impoprts the given XSLT DOM and compiles it to a reusable transform
1.234 + * Imports the given XSLT DOM and compiles it to a reusable transform
1.235 + * <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.236 * @argument xslDoc The XSLT DOMDocument to import
1.237 */
1.238 XSLTProcessor.prototype.importStylesheet = function(xslDoc){
1.239 + if(!_SARISSA_THREADEDDOM_PROGID){
1.240 + _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID(["MSXML2.FreeThreadedDOMDocument.6.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
1.241 + };
1.242 + xslDoc.setProperty("SelectionLanguage", "XPath");
1.243 + xslDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
1.244 // convert stylesheet to free threaded
1.245 - var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);
1.246 - converted.loadXML(xslDoc.xml);
1.247 + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);
1.248 + // make included/imported stylesheets work if exist and xsl was originally loaded from url
1.249 + if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() = 'import' or local-name() = 'include']") != null){
1.250 + converted.async = false;
1.251 + if (_SARISSA_THREADEDDOM_PROGID == "MSXML2.FreeThreadedDOMDocument.6.0") {
1.252 + converted.setProperty("AllowDocumentFunction", true);
1.253 + converted.resolveExternals = true;
1.254 + }
1.255 + converted.load(xslDoc.url);
1.256 + } else {
1.257 + converted.loadXML(xslDoc.xml);
1.258 + };
1.259 + converted.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
1.260 + var output = converted.selectSingleNode("//xsl:output");
1.261 + this.outputMethod = output ? output.getAttribute("method") : "html";
1.262 this.template.stylesheet = converted;
1.263 this.processor = this.template.createProcessor();
1.264 - // (re)set default param values
1.265 + // for getParameter and clearParameters
1.266 this.paramsSet = new Array();
1.267 };
1.268 +
1.269 /**
1.270 - * Transform the given XML DOM
1.271 + * Transform the given XML DOM and return the transformation result as a new DOM document
1.272 * @argument sourceDoc The XML DOMDocument to transform
1.273 * @return The transformation result as a DOM Document
1.274 */
1.275 XSLTProcessor.prototype.transformToDocument = function(sourceDoc){
1.276 - this.processor.input = sourceDoc;
1.277 - var outDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.278 - this.processor.output = outDoc;
1.279 - this.processor.transform();
1.280 - return outDoc;
1.281 + // fix for bug 1549749
1.282 + if(_SARISSA_THREADEDDOM_PROGID){
1.283 + this.processor.input=sourceDoc;
1.284 + var outDoc=new ActiveXObject(_SARISSA_DOM_PROGID);
1.285 + this.processor.output=outDoc;
1.286 + this.processor.transform();
1.287 + return outDoc;
1.288 + }
1.289 + else{
1.290 + if(!_SARISSA_DOM_XMLWRITER){
1.291 + _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID(["Msxml2.MXXMLWriter.6.0", "Msxml2.MXXMLWriter.3.0", "MSXML2.MXXMLWriter", "MSXML.MXXMLWriter", "Microsoft.XMLDOM"]);
1.292 + };
1.293 + this.processor.input = sourceDoc;
1.294 + var outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER);
1.295 + this.processor.output = outDoc;
1.296 + this.processor.transform();
1.297 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.298 + oDoc.loadXML(outDoc.output+"");
1.299 + return oDoc;
1.300 + };
1.301 };
1.302 +
1.303 /**
1.304 - * Not sure if this works in IE. Maybe this will allow non-well-formed
1.305 - * transformation results (i.e. with no single root element)
1.306 + * Transform the given XML DOM and return the transformation result as a new DOM fragment.
1.307 + * <b>Note</b>: The xsl:output method must match the nature of the owner document (XML/HTML).
1.308 * @argument sourceDoc The XML DOMDocument to transform
1.309 - * @return The transformation result as a DOM Fragment
1.310 + * @argument ownerDoc The owner of the result fragment
1.311 + * @return The transformation result as a DOM Document
1.312 */
1.313 - XSLTProcessor.prototype.transformToFragment = function(sourceDoc, ownerDocument){
1.314 - return this.transformToDocument(sourceDoc);
1.315 + XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) {
1.316 + this.processor.input = sourceDoc;
1.317 + this.processor.transform();
1.318 + var s = this.processor.output;
1.319 + var f = ownerDoc.createDocumentFragment();
1.320 + if (this.outputMethod == 'text') {
1.321 + f.appendChild(ownerDoc.createTextNode(s));
1.322 + } else if (ownerDoc.body && ownerDoc.body.innerHTML) {
1.323 + var container = ownerDoc.createElement('div');
1.324 + container.innerHTML = s;
1.325 + while (container.hasChildNodes()) {
1.326 + f.appendChild(container.firstChild);
1.327 + }
1.328 + }
1.329 + else {
1.330 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
1.331 + if (s.substring(0, 5) == '<?xml') {
1.332 + s = s.substring(s.indexOf('?>') + 2);
1.333 + }
1.334 + var xml = ''.concat('<my>', s, '</my>');
1.335 + oDoc.loadXML(xml);
1.336 + var container = oDoc.documentElement;
1.337 + while (container.hasChildNodes()) {
1.338 + f.appendChild(container.firstChild);
1.339 + }
1.340 + }
1.341 + return f;
1.342 };
1.343 +
1.344 /**
1.345 * Set global XSLT parameter of the imported stylesheet
1.346 * @argument nsURI The parameter namespace URI
1.347 @@ -202,13 +274,15 @@
1.348 * @argument value The new parameter value
1.349 */
1.350 XSLTProcessor.prototype.setParameter = function(nsURI, name, value){
1.351 - /* nsURI is optional but cannot be null */
1.352 + // make value a zero length string if null to allow clearing
1.353 + value = value ? value : "";
1.354 + // nsURI is optional but cannot be null
1.355 if(nsURI){
1.356 this.processor.addParameter(name, value, nsURI);
1.357 }else{
1.358 this.processor.addParameter(name, value);
1.359 };
1.360 - /* update updated params for getParameter */
1.361 + // update updated params for getParameter
1.362 if(!this.paramsSet[""+nsURI]){
1.363 this.paramsSet[""+nsURI] = new Array();
1.364 };
1.365 @@ -222,102 +296,38 @@
1.366 * @return The parameter value if reviously set by setParameter, null otherwise
1.367 */
1.368 XSLTProcessor.prototype.getParameter = function(nsURI, name){
1.369 - if(this.paramsSet[""+nsURI] && this.paramsSet[""+nsURI][name])
1.370 - return this.paramsSet[""+nsURI][name];
1.371 - else
1.372 + nsURI = "" + nsURI;
1.373 + if(this.paramsSet[nsURI] && this.paramsSet[nsURI][name]){
1.374 + return this.paramsSet[nsURI][name];
1.375 + }else{
1.376 return null;
1.377 + };
1.378 };
1.379 -}
1.380 -else{ /* end IE initialization, try to deal with real browsers now ;-) */
1.381 - if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){
1.382 - if(window.XMLDocument){
1.383 - /**
1.384 - * <p>Emulate IE's onreadystatechange attribute</p>
1.385 - */
1.386 - XMLDocument.prototype.onreadystatechange = null;
1.387 - /**
1.388 - * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
1.389 - * <ul><li>1 == LOADING,</li>
1.390 - * <li>2 == LOADED,</li>
1.391 - * <li>3 == INTERACTIVE,</li>
1.392 - * <li>4 == COMPLETED</li></ul>
1.393 - */
1.394 - XMLDocument.prototype.readyState = 0;
1.395 - /**
1.396 - * <p>Emulate IE's parseError attribute</p>
1.397 - */
1.398 - XMLDocument.prototype.parseError = 0;
1.399 -
1.400 - // NOTE: setting async to false will only work with documents
1.401 - // called over HTTP (meaning a server), not the local file system,
1.402 - // unless you are using Moz 1.4+.
1.403 - // BTW the try>catch block is for 1.4; I haven't found a way to check if
1.404 - // the property is implemented without
1.405 - // causing an error and I dont want to use user agent stuff for that...
1.406 - var _SARISSA_SYNC_NON_IMPLEMENTED = false;
1.407 - try{
1.408 - /**
1.409 - * <p>Emulates IE's async property for Moz versions prior to 1.4.
1.410 - * It controls whether loading of remote XML files works
1.411 - * synchronously or asynchronously.</p>
1.412 - */
1.413 - XMLDocument.prototype.async = true;
1.414 - _SARISSA_SYNC_NON_IMPLEMENTED = true;
1.415 - }catch(e){/* trap */};
1.416 - /**
1.417 - * <p>Keeps a handle to the original load() method. Internal use and only
1.418 - * if Mozilla version is lower than 1.4</p>
1.419 - * @private
1.420 - */
1.421 - XMLDocument.prototype._sarissa_load = XMLDocument.prototype.load;
1.422 -
1.423 - /**
1.424 - * <p>Overrides the original load method to provide synchronous loading for
1.425 - * Mozilla versions prior to 1.4, using an XMLHttpRequest object (if
1.426 - * async is set to false)</p>
1.427 - * @returns the DOM Object as it was before the load() call (may be empty)
1.428 - */
1.429 - XMLDocument.prototype.load = function(sURI) {
1.430 - var oDoc = document.implementation.createDocument("", "", null);
1.431 - Sarissa.copyChildNodes(this, oDoc);
1.432 - this.parseError = 0;
1.433 - Sarissa.__setReadyState__(this, 1);
1.434 - try {
1.435 - if(this.async == false && _SARISSA_SYNC_NON_IMPLEMENTED) {
1.436 - var tmp = new XMLHttpRequest();
1.437 - tmp.open("GET", sURI, false);
1.438 - tmp.send(null);
1.439 - Sarissa.__setReadyState__(this, 2);
1.440 - Sarissa.copyChildNodes(tmp.responseXML, this);
1.441 - Sarissa.__setReadyState__(this, 3);
1.442 - }
1.443 - else {
1.444 - this._sarissa_load(sURI);
1.445 - };
1.446 - }
1.447 - catch (objException) {
1.448 - this.parseError = -1;
1.449 - }
1.450 - finally {
1.451 - if(this.async == false){
1.452 - Sarissa.__handleLoad__(this);
1.453 - };
1.454 + /**
1.455 + * Clear parameters (set them to default values as defined in the stylesheet itself)
1.456 + */
1.457 + XSLTProcessor.prototype.clearParameters = function(){
1.458 + for(var nsURI in this.paramsSet){
1.459 + for(var name in this.paramsSet[nsURI]){
1.460 + if(nsURI){
1.461 + this.processor.addParameter(name, "", nsURI);
1.462 + }else{
1.463 + this.processor.addParameter(name, "");
1.464 };
1.465 - return oDoc;
1.466 };
1.467 - };//if(window.XMLDocument)
1.468 -
1.469 + };
1.470 + this.paramsSet = new Array();
1.471 + };
1.472 +}else{ /* end IE initialization, try to deal with real browsers now ;-) */
1.473 + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){
1.474 /**
1.475 * <p>Ensures the document was loaded correctly, otherwise sets the
1.476 * parseError to -1 to indicate something went wrong. Internal use</p>
1.477 * @private
1.478 */
1.479 Sarissa.__handleLoad__ = function(oDoc){
1.480 - if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror")
1.481 - oDoc.parseError = -1;
1.482 Sarissa.__setReadyState__(oDoc, 4);
1.483 };
1.484 -
1.485 /**
1.486 * <p>Attached by an event handler to the load event. Internal use.</p>
1.487 * @private
1.488 @@ -325,7 +335,6 @@
1.489 _sarissa_XMLDocument_onload = function(){
1.490 Sarissa.__handleLoad__(this);
1.491 };
1.492 -
1.493 /**
1.494 * <p>Sets the readyState property of the given DOM Document object.
1.495 * Internal use.</p>
1.496 @@ -336,80 +345,129 @@
1.497 */
1.498 Sarissa.__setReadyState__ = function(oDoc, iReadyState){
1.499 oDoc.readyState = iReadyState;
1.500 + oDoc.readystate = iReadyState;
1.501 if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function")
1.502 oDoc.onreadystatechange();
1.503 };
1.504 - /**
1.505 - * <p>Factory method to obtain a new DOM Document object</p>
1.506 - * @argument sUri the namespace of the root node (if any)
1.507 - * @argument sUri the local name of the root node (if any)
1.508 - * @returns a new DOM Document
1.509 - */
1.510 Sarissa.getDomDocument = function(sUri, sName){
1.511 - var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null);
1.512 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.513 + if(!oDoc.onreadystatechange){
1.514 +
1.515 + /**
1.516 + * <p>Emulate IE's onreadystatechange attribute</p>
1.517 + */
1.518 + oDoc.onreadystatechange = null;
1.519 + };
1.520 + if(!oDoc.readyState){
1.521 + /**
1.522 + * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
1.523 + * <ul><li>1 == LOADING,</li>
1.524 + * <li>2 == LOADED,</li>
1.525 + * <li>3 == INTERACTIVE,</li>
1.526 + * <li>4 == COMPLETED</li></ul>
1.527 + */
1.528 + oDoc.readyState = 0;
1.529 + };
1.530 oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false);
1.531 return oDoc;
1.532 - };
1.533 + };
1.534 + if(window.XMLDocument){
1.535 + // do nothing
1.536 + }// TODO: check if the new document has content before trying to copynodes, check for error handling in DOM 3 LS
1.537 + else if(_SARISSA_HAS_DOM_FEATURE && window.Document && !Document.prototype.load && document.implementation.hasFeature('LS', '3.0')){
1.538 + //Opera 9 may get the XPath branch which gives creates XMLDocument, therefore it doesn't reach here which is good
1.539 + /**
1.540 + * <p>Factory method to obtain a new DOM Document object</p>
1.541 + * @argument sUri the namespace of the root node (if any)
1.542 + * @argument sUri the local name of the root node (if any)
1.543 + * @returns a new DOM Document
1.544 + */
1.545 + Sarissa.getDomDocument = function(sUri, sName){
1.546 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.547 + return oDoc;
1.548 + };
1.549 + }
1.550 + else {
1.551 + Sarissa.getDomDocument = function(sUri, sName){
1.552 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
1.553 + // looks like safari does not create the root element for some unknown reason
1.554 + if(oDoc && (sUri || sName) && !oDoc.documentElement){
1.555 + oDoc.appendChild(oDoc.createElementNS(sUri, sName));
1.556 + };
1.557 + return oDoc;
1.558 + };
1.559 + };
1.560 };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT)
1.561 };
1.562 //==========================================
1.563 // Common stuff
1.564 //==========================================
1.565 if(!window.DOMParser){
1.566 - /**
1.567 - * DOMParser is a utility class, used to construct DOMDocuments from XML strings
1.568 - * @constructor
1.569 - */
1.570 - DOMParser = function() {
1.571 + if(_SARISSA_IS_SAFARI){
1.572 + /*
1.573 + * DOMParser is a utility class, used to construct DOMDocuments from XML strings
1.574 + * @constructor
1.575 + */
1.576 + DOMParser = function() { };
1.577 + /**
1.578 + * Construct a new DOM Document from the given XMLstring
1.579 + * @param sXml the given XML string
1.580 + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml).
1.581 + * @return a new DOM Document from the given XML string
1.582 + */
1.583 + DOMParser.prototype.parseFromString = function(sXml, contentType){
1.584 + var xmlhttp = new XMLHttpRequest();
1.585 + xmlhttp.open("GET", "data:text/xml;charset=utf-8," + encodeURIComponent(sXml), false);
1.586 + xmlhttp.send(null);
1.587 + return xmlhttp.responseXML;
1.588 + };
1.589 + }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && Sarissa.getDomDocument(null, "bar").xml){
1.590 + DOMParser = function() { };
1.591 + DOMParser.prototype.parseFromString = function(sXml, contentType){
1.592 + var doc = Sarissa.getDomDocument();
1.593 + doc.loadXML(sXml);
1.594 + return doc;
1.595 + };
1.596 };
1.597 - /**
1.598 - * Construct a new DOM Document from the given XMLstring
1.599 - * @param sXml the given XML string
1.600 - * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml).
1.601 - * @return a new DOM Document from the given XML string
1.602 - */
1.603 - DOMParser.prototype.parseFromString = function(sXml, contentType){
1.604 - var doc = Sarissa.getDomDocument();
1.605 - doc.loadXML(sXml);
1.606 - return doc;
1.607 - };
1.608 -
1.609 };
1.610
1.611 -if(window.XMLHttpRequest){
1.612 - Sarissa.IS_ENABLED_XMLHTTP = true;
1.613 -}
1.614 -else if(_SARISSA_IS_IE){
1.615 - /**
1.616 - * Emulate XMLHttpRequest
1.617 - * @constructor
1.618 - */
1.619 - XMLHttpRequest = function() {
1.620 - return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.621 - };
1.622 - Sarissa.IS_ENABLED_XMLHTTP = true;
1.623 -};
1.624 -
1.625 -if(!window.document.importNode && _SARISSA_IS_IE){
1.626 +if((typeof(document.importNode) == "undefined") && _SARISSA_IS_IE){
1.627 try{
1.628 /**
1.629 - * Implements importNode for the current window document in IE using innerHTML.
1.630 - * Testing showed that DOM was multiple times slower than innerHTML for this,
1.631 - * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML)
1.632 - * please gimme a call.
1.633 + * Implementation of importNode for the context window document in IE.
1.634 + * If <code>oNode</code> is a TextNode, <code>bChildren</code> is ignored.
1.635 * @param oNode the Node to import
1.636 * @param bChildren whether to include the children of oNode
1.637 * @returns the imported node for further use
1.638 */
1.639 - window.document.importNode = function(oNode, bChildren){
1.640 - var importNode = document.createElement("div");
1.641 - if(bChildren)
1.642 - importNode.innerHTML = Sarissa.serialize(oNode);
1.643 - else
1.644 - importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false));
1.645 - return importNode.firstChild;
1.646 + document.importNode = function(oNode, bChildren){
1.647 + var tmp;
1.648 + if (oNode.nodeName=='#text') {
1.649 + return document.createTextElement(oNode.data);
1.650 + }
1.651 + else {
1.652 + if(oNode.nodeName == "tbody" || oNode.nodeName == "tr"){
1.653 + tmp = document.createElement("table");
1.654 + }
1.655 + else if(oNode.nodeName == "td"){
1.656 + tmp = document.createElement("tr");
1.657 + }
1.658 + else if(oNode.nodeName == "option"){
1.659 + tmp = document.createElement("select");
1.660 + }
1.661 + else{
1.662 + tmp = document.createElement("div");
1.663 + };
1.664 + if(bChildren){
1.665 + tmp.innerHTML = oNode.xml ? oNode.xml : oNode.outerHTML;
1.666 + }else{
1.667 + tmp.innerHTML = oNode.xml ? oNode.cloneNode(false).xml : oNode.cloneNode(false).outerHTML;
1.668 + };
1.669 + return tmp.getElementsByTagName("*")[0];
1.670 + };
1.671 +
1.672 };
1.673 - }catch(e){};
1.674 + }catch(e){ };
1.675 };
1.676 if(!Sarissa.getParseErrorText){
1.677 /**
1.678 @@ -423,17 +481,16 @@
1.679 */
1.680 Sarissa.getParseErrorText = function (oDoc){
1.681 var parseErrorText = Sarissa.PARSED_OK;
1.682 - if(oDoc.parseError != 0){
1.683 - /*moz*/
1.684 - if(oDoc.documentElement.tagName == "parsererror"){
1.685 - parseErrorText = oDoc.documentElement.firstChild.data;
1.686 - parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data;
1.687 - }/*konq*/
1.688 - else if(oDoc.documentElement.tagName == "html"){
1.689 - parseErrorText = Sarissa.getText(oDoc.documentElement.getElementsByTagName("h1")[0], false) + "\n";
1.690 - parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("body")[0], false) + "\n";
1.691 - parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false);
1.692 - };
1.693 + if(!oDoc.documentElement){
1.694 + parseErrorText = Sarissa.PARSED_EMPTY;
1.695 + } else if(oDoc.documentElement.tagName == "parsererror"){
1.696 + parseErrorText = oDoc.documentElement.firstChild.data;
1.697 + parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data;
1.698 + } else if(oDoc.getElementsByTagName("parsererror").length > 0){
1.699 + var parsererror = oDoc.getElementsByTagName("parsererror")[0];
1.700 + parseErrorText = Sarissa.getText(parsererror, true)+"\n";
1.701 + } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){
1.702 + parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR;
1.703 };
1.704 return parseErrorText;
1.705 };
1.706 @@ -446,8 +503,7 @@
1.707 var nodeType = node.nodeType;
1.708 if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
1.709 s += node.data;
1.710 - }
1.711 - else if(deep == true
1.712 + } else if(deep == true
1.713 && (nodeType == Node.ELEMENT_NODE
1.714 || nodeType == Node.DOCUMENT_NODE
1.715 || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
1.716 @@ -456,33 +512,20 @@
1.717 };
1.718 return s;
1.719 };
1.720 -if(window.XMLSerializer){
1.721 +if(!window.XMLSerializer
1.722 + && Sarissa.getDomDocument
1.723 + && Sarissa.getDomDocument("","foo", null).xml){
1.724 /**
1.725 - * <p>Factory method to obtain the serialization of a DOM Node</p>
1.726 - * @returns the serialized Node as an XML string
1.727 + * Utility class to serialize DOM Node objects to XML strings
1.728 + * @constructor
1.729 */
1.730 - Sarissa.serialize = function(oDoc){
1.731 - return (new XMLSerializer()).serializeToString(oDoc);
1.732 - };
1.733 -}else{
1.734 - if((Sarissa.getDomDocument("","foo", null)).xml){
1.735 - // see non-IE version
1.736 - Sarissa.serialize = function(oDoc) {
1.737 - // TODO: check for HTML document and return innerHTML instead
1.738 - return oDoc.xml;
1.739 - };
1.740 - /**
1.741 - * Utility class to serialize DOM Node objects to XML strings
1.742 - * @constructor
1.743 - */
1.744 - XMLSerializer = function(){};
1.745 - /**
1.746 - * Serialize the given DOM Node to an XML string
1.747 - * @param oNode the DOM Node to serialize
1.748 - */
1.749 - XMLSerializer.prototype.serializeToString = function(oNode) {
1.750 - return oNode.xml;
1.751 - };
1.752 + XMLSerializer = function(){};
1.753 + /**
1.754 + * Serialize the given DOM Node to an XML string
1.755 + * @param oNode the DOM Node to serialize
1.756 + */
1.757 + XMLSerializer.prototype.serializeToString = function(oNode) {
1.758 + return oNode.xml;
1.759 };
1.760 };
1.761
1.762 @@ -497,7 +540,8 @@
1.763 * @argument oNode the Node to empty
1.764 */
1.765 Sarissa.clearChildNodes = function(oNode) {
1.766 - while(oNode.hasChildNodes()){
1.767 + // need to check for firstChild due to opera 8 bug with hasChildNodes
1.768 + while(oNode.firstChild) {
1.769 oNode.removeChild(oNode.firstChild);
1.770 };
1.771 };
1.772 @@ -510,17 +554,19 @@
1.773 * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
1.774 */
1.775 Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.776 + if((!nodeFrom) || (!nodeTo)){
1.777 + throw "Both source and destination nodes must be provided";
1.778 + };
1.779 if(!bPreserveExisting){
1.780 Sarissa.clearChildNodes(nodeTo);
1.781 };
1.782 var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.783 var nodes = nodeFrom.childNodes;
1.784 - if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
1.785 + if(typeof(ownerDoc.importNode) != "undefined") {
1.786 for(var i=0;i < nodes.length;i++) {
1.787 nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.788 };
1.789 - }
1.790 - else{
1.791 + } else {
1.792 for(var i=0;i < nodes.length;i++) {
1.793 nodeTo.appendChild(nodes[i].cloneNode(true));
1.794 };
1.795 @@ -533,32 +579,34 @@
1.796 * the move operation, unless you supply a true third parameter</p>
1.797 * @argument nodeFrom the Node to copy the childNodes from
1.798 * @argument nodeTo the Node to copy the childNodes to
1.799 - * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
1.800 - */
1.801 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is
1.802 + */
1.803 Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.804 + if((!nodeFrom) || (!nodeTo)){
1.805 + throw "Both source and destination nodes must be provided";
1.806 + };
1.807 if(!bPreserveExisting){
1.808 Sarissa.clearChildNodes(nodeTo);
1.809 };
1.810 -
1.811 var nodes = nodeFrom.childNodes;
1.812 // if within the same doc, just move, else copy and delete
1.813 if(nodeFrom.ownerDocument == nodeTo.ownerDocument){
1.814 - nodeTo.appendChild(nodes[i]);
1.815 - }else{
1.816 + while(nodeFrom.firstChild){
1.817 + nodeTo.appendChild(nodeFrom.firstChild);
1.818 + };
1.819 + } else {
1.820 var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.821 - if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
1.822 - for(var i=0;i < nodes.length;i++) {
1.823 - nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.824 - };
1.825 - }
1.826 - else{
1.827 - for(var i=0;i < nodes.length;i++) {
1.828 - nodeTo.appendChild(nodes[i].cloneNode(true));
1.829 - };
1.830 + if(typeof(ownerDoc.importNode) != "undefined") {
1.831 + for(var i=0;i < nodes.length;i++) {
1.832 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.833 + };
1.834 + }else{
1.835 + for(var i=0;i < nodes.length;i++) {
1.836 + nodeTo.appendChild(nodes[i].cloneNode(true));
1.837 + };
1.838 };
1.839 Sarissa.clearChildNodes(nodeFrom);
1.840 };
1.841 -
1.842 };
1.843
1.844 /**