XSLTools

Changeset

311:8c94e168109e
2005-10-12 paulb raw files shortlog changelog graph [project @ 2005-10-12 17:15:40 by paulb] Added missing scripts.
examples/Common/PEP241/Resources/scripts/XSLForms.js (file) examples/Common/PEP241/Resources/scripts/sarissa.js (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/Common/PEP241/Resources/scripts/XSLForms.js	Wed Oct 12 17:15:40 2005 +0000
     1.3 @@ -0,0 +1,139 @@
     1.4 +function requestUpdate(url, fieldNames, targetName, targetFieldNames, elementPath) {
     1.5 +
     1.6 +    // Note that XMLHttpRequest access may be denied if Mozilla believes that
     1.7 +    // this resource's URL and the supplied URL are different.
     1.8 +
     1.9 +    var xmlhttp = new XMLHttpRequest();
    1.10 +    xmlhttp.open("POST", url, false);
    1.11 +
    1.12 +    // Add the element path specification.
    1.13 +
    1.14 +    var requestBody = ("element-path=" + elementPath);
    1.15 +
    1.16 +    // Send the controlling field value.
    1.17 +
    1.18 +    requestBody += addFields(fieldNames, false);
    1.19 +    requestBody += addFields(targetFieldNames, true);
    1.20 +
    1.21 +    // Load the remote document with the given parameters sent as text in the request body.
    1.22 +
    1.23 +    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    1.24 +    xmlhttp.send(requestBody);
    1.25 +
    1.26 +    // Parse the result document.
    1.27 +
    1.28 +    var newDocument = Sarissa.getDomDocument();
    1.29 +    newDocument = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
    1.30 +
    1.31 +    // Find the definition of the affected field in the result document.
    1.32 +
    1.33 +    var newElement = newDocument.getElementById(targetName);
    1.34 +    var targetElement = document.getElementById(targetName);
    1.35 +
    1.36 +    // Insert the new definition into the current document.
    1.37 +
    1.38 +    if (newElement != null && targetElement != null) {
    1.39 +        var importedElement = document.importNode(newElement, true);
    1.40 +        targetElement.parentNode.replaceChild(importedElement, targetElement);
    1.41 +        //importedElement.setAttribute("style", "background-color:red;");
    1.42 +    }
    1.43 +
    1.44 +    // NOTE: Test Konqueror bug.
    1.45 +
    1.46 +    //showMismatch(targetFieldNameArray);
    1.47 +
    1.48 +    return false;
    1.49 +}
    1.50 +
    1.51 +function addFields(fieldNames, disable) {
    1.52 +
    1.53 +    // If no field names exist do not attempt to collect their values.
    1.54 +
    1.55 +    if (fieldNames == "") {
    1.56 +        return "";
    1.57 +    }
    1.58 +
    1.59 +    var requestBody = "";
    1.60 +
    1.61 +    // Process each target field name.
    1.62 +
    1.63 +    var fieldNameArray = fieldNames.split(",");
    1.64 +
    1.65 +    // Add the values of the dependent fields.
    1.66 +
    1.67 +    for (var i = 0; i < fieldNameArray.length; i++) {
    1.68 +        var fieldName = fieldNameArray[i];
    1.69 +
    1.70 +        // Skip empty field names (arising through empty elements in the CSV list).
    1.71 +
    1.72 +        if (fieldName == "") {
    1.73 +            continue;
    1.74 +        }
    1.75 +
    1.76 +        // Find the values of the target field.
    1.77 +
    1.78 +        var fieldValue;
    1.79 +        var fieldNodes = document.getElementsByName(fieldName);
    1.80 +        for (var v = 0; v < fieldNodes.length; v++) {
    1.81 +
    1.82 +            // Test for different field types.
    1.83 +
    1.84 +            if (fieldNodes[v].options) {
    1.85 +                for (var opt = 0; opt < fieldNodes[v].options.length; opt++) {
    1.86 +                    if (fieldNodes[v].options[opt].selected) {
    1.87 +                        fieldValue = fieldNodes[v].options[opt].value;
    1.88 +                        requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue));
    1.89 +                    }
    1.90 +                }
    1.91 +            } else {
    1.92 +                fieldValue = fieldNodes[v].value;
    1.93 +                requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue));
    1.94 +            }
    1.95 +        }
    1.96 +
    1.97 +        // NOTE: Konqueror hack: disable fields.
    1.98 +
    1.99 +        if (disable) {
   1.100 +            disableFields(fieldName);
   1.101 +        }
   1.102 +    }
   1.103 +
   1.104 +    return requestBody;
   1.105 +}
   1.106 +
   1.107 +function disableFields(targetFieldName) {
   1.108 +
   1.109 +    for (var i = 0; i < document.forms.length; i++) {
   1.110 +        var form = document.forms[i];
   1.111 +        for (var j = 0; j < form.elements.length; j++) {
   1.112 +            if (form.elements[j].name == targetFieldName) {
   1.113 +                form.elements[j].name = "";
   1.114 +            }
   1.115 +        }
   1.116 +    }
   1.117 +}
   1.118 +
   1.119 +function showMismatch(targetFieldNameArray) {
   1.120 +
   1.121 +    // Show how the number of field elements with a given name can be different
   1.122 +    // from the number known to the DOM Level 0 part of the API.
   1.123 +
   1.124 +    for (var h = 0; h < targetFieldNameArray.length; h++) {
   1.125 +        var targetFieldName = targetFieldNameArray[h];
   1.126 +        var targetFieldNodes = document.getElementsByName(targetFieldName);
   1.127 +        alert("Nodes for " + targetFieldName + ": " + targetFieldNodes.length);
   1.128 +
   1.129 +        var count = 0;
   1.130 +        for (var i = 0; i < document.forms.length; i++) {
   1.131 +            var form = document.forms[i];
   1.132 +            for (var j = 0; j < form.elements.length; j++) {
   1.133 +                if (form.elements[j].name == targetFieldName) {
   1.134 +                    count++;
   1.135 +                }
   1.136 +            }
   1.137 +        }
   1.138 +        alert("Fields for " + targetFieldName + ": " + count);
   1.139 +    }
   1.140 +}
   1.141 +
   1.142 +// vim: tabstop=4 expandtab shiftwidth=4
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/examples/Common/PEP241/Resources/scripts/sarissa.js	Wed Oct 12 17:15:40 2005 +0000
     2.3 @@ -0,0 +1,616 @@
     2.4 +/**
     2.5 + * ====================================================================
     2.6 + * About
     2.7 + * ====================================================================
     2.8 + * Sarissa cross browser XML library 
     2.9 + * @version 0.9.6
    2.10 + * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
    2.11 + *
    2.12 + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
    2.13 + * The library supports Gecko based browsers like Mozilla and Firefox,
    2.14 + * Internet Explorer (5.5+ with MSXML3.0+) and, last but not least, KHTML based browsers like
    2.15 + * Konqueror and Safari.
    2.16 + *
    2.17 + * ====================================================================
    2.18 + * Licence
    2.19 + * ====================================================================
    2.20 + * This program is free software; you can redistribute it and/or modify
    2.21 + * it under the terms of the GNU General Public License version 2 or
    2.22 + * the GNU Lesser General Public License version 2.1 as published by
    2.23 + * the Free Software Foundation (your choice of the two).
    2.24 + *
    2.25 + * This program is distributed in the hope that it will be useful,
    2.26 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.27 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.28 + * GNU General Public License or GNU Lesser General Public License for more details.
    2.29 + *
    2.30 + * You should have received a copy of the GNU General Public License
    2.31 + * or GNU Lesser General Public License along with this program; if not,
    2.32 + * write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2.33 + * or visit http://www.gnu.org
    2.34 + *
    2.35 + */
    2.36 +/**
    2.37 + * <p>Sarissa is a utility class. Provides static methods for DOMDocument and 
    2.38 + * XMLHTTP objects, DOM Node serializatrion to XML strings and other goodies.</p>
    2.39 + * @constructor
    2.40 + */
    2.41 +function Sarissa(){};
    2.42 +/** @private */
    2.43 +Sarissa.PARSED_OK = "Document contains no parsing errors";
    2.44 +/**
    2.45 + * Tells you whether transformNode and transformNodeToObject are available. This functionality
    2.46 + * is contained in sarissa_ieemu_xslt.js and is deprecated. If you want to control XSLT transformations
    2.47 + * use the XSLTProcessor
    2.48 + * @deprecated
    2.49 + * @type boolean
    2.50 + */
    2.51 +Sarissa.IS_ENABLED_TRANSFORM_NODE = false;
    2.52 +/**
    2.53 + * tells you whether XMLHttpRequest (or equivalent) is available
    2.54 + * @type boolean
    2.55 + */
    2.56 +Sarissa.IS_ENABLED_XMLHTTP = false;
    2.57 +/**
    2.58 + * tells you whether selectNodes/selectSingleNode is available
    2.59 + * @type boolean
    2.60 + */
    2.61 +Sarissa.IS_ENABLED_SELECT_NODES = false;
    2.62 +var _sarissa_iNsCounter = 0;
    2.63 +var _SARISSA_IEPREFIX4XSLPARAM = "";
    2.64 +var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
    2.65 +var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
    2.66 +var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
    2.67 +var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;
    2.68 +var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1;
    2.69 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
    2.70 +
    2.71 +if(!window.Node || !window.Node.ELEMENT_NODE){
    2.72 +    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};
    2.73 +};
    2.74 +
    2.75 +// IE initialization
    2.76 +if(_SARISSA_IS_IE){
    2.77 +    // for XSLT parameter names, prefix needed by IE
    2.78 +    _SARISSA_IEPREFIX4XSLPARAM = "xsl:";
    2.79 +    // used to store the most recent ProgID available out of the above
    2.80 +    var _SARISSA_DOM_PROGID = "";
    2.81 +    var _SARISSA_XMLHTTP_PROGID = "";
    2.82 +    /**
    2.83 +     * Called when the Sarissa_xx.js file is parsed, to pick most recent
    2.84 +     * ProgIDs for IE, then gets destroyed.
    2.85 +     * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
    2.86 +     * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled
    2.87 +     */
    2.88 +    pickRecentProgID = function (idList, enabledList){
    2.89 +        // found progID flag
    2.90 +        var bFound = false;
    2.91 +        for(var i=0; i < idList.length && !bFound; i++){
    2.92 +            try{
    2.93 +                var oDoc = new ActiveXObject(idList[i]);
    2.94 +                o2Store = idList[i];
    2.95 +                bFound = true;
    2.96 +                for(var j=0;j<enabledList.length;j++)
    2.97 +                    if(i <= enabledList[j][1])
    2.98 +                        Sarissa["IS_ENABLED_"+enabledList[j][0]] = true;
    2.99 +            }catch (objException){
   2.100 +                // trap; try next progID
   2.101 +            };
   2.102 +        };
   2.103 +        if (!bFound)
   2.104 +            throw "Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
   2.105 +        idList = null;
   2.106 +        return o2Store;
   2.107 +    };
   2.108 +    // pick best available MSXML progIDs
   2.109 +    _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]]);
   2.110 +    _SARISSA_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]);
   2.111 +    _SARISSA_THREADEDDOM_PROGID = pickRecentProgID(["Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
   2.112 +    _SARISSA_XSLTEMPLATE_PROGID = pickRecentProgID(["Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0"], [["XSLTPROC", 2]]);
   2.113 +    // we dont need this anymore
   2.114 +    pickRecentProgID = null;
   2.115 +    //============================================
   2.116 +    // Factory methods (IE)
   2.117 +    //============================================
   2.118 +    // see non-IE version
   2.119 +    Sarissa.getDomDocument = function(sUri, sName){
   2.120 +        var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
   2.121 +        // if a root tag name was provided, we need to load it in the DOM
   2.122 +        // object
   2.123 +        if (sName){
   2.124 +            // if needed, create an artifical namespace prefix the way Moz
   2.125 +            // does
   2.126 +            if (sUri){
   2.127 +                oDoc.loadXML("<a" + _sarissa_iNsCounter + ":" + sName + " xmlns:a" + _sarissa_iNsCounter + "=\"" + sUri + "\" />");
   2.128 +                // don't use the same prefix again
   2.129 +                ++_sarissa_iNsCounter;
   2.130 +            }
   2.131 +            else
   2.132 +                oDoc.loadXML("<" + sName + "/>");
   2.133 +        };
   2.134 +        return oDoc;
   2.135 +    };
   2.136 +    // see non-IE version   
   2.137 +    Sarissa.getParseErrorText = function (oDoc) {
   2.138 +        var parseErrorText = Sarissa.PARSED_OK;
   2.139 +        if(oDoc.parseError != 0){
   2.140 +            parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason + 
   2.141 +                "\nLocation: " + oDoc.parseError.url + 
   2.142 +                "\nLine Number " + oDoc.parseError.line + ", Column " + 
   2.143 +                oDoc.parseError.linepos + 
   2.144 +                ":\n" + oDoc.parseError.srcText +
   2.145 +                "\n";
   2.146 +            for(var i = 0;  i < oDoc.parseError.linepos;i++){
   2.147 +                parseErrorText += "-";
   2.148 +            };
   2.149 +            parseErrorText +=  "^\n";
   2.150 +        };
   2.151 +        return parseErrorText;
   2.152 +    };
   2.153 +    // see non-IE version
   2.154 +    Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {
   2.155 +        oDoc.setProperty("SelectionLanguage", "XPath");
   2.156 +        oDoc.setProperty("SelectionNamespaces", sNsSet);
   2.157 +    };   
   2.158 +    /**
   2.159 +     * Basic implementation of Mozilla's XSLTProcessor for IE. 
   2.160 +     * Reuses the same XSLT stylesheet for multiple transforms
   2.161 +     * @constructor
   2.162 +     */
   2.163 +    XSLTProcessor = function(){
   2.164 +        this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
   2.165 +        this.processor = null;
   2.166 +    };
   2.167 +    /**
   2.168 +     * Impoprts the given XSLT DOM and compiles it to a reusable transform
   2.169 +     * @argument xslDoc The XSLT DOMDocument to import
   2.170 +     */
   2.171 +    XSLTProcessor.prototype.importStylesheet = function(xslDoc){
   2.172 +        // convert stylesheet to free threaded
   2.173 +        var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID); 
   2.174 +        converted.loadXML(xslDoc.xml);
   2.175 +        this.template.stylesheet = converted;
   2.176 +        this.processor = this.template.createProcessor();
   2.177 +        // (re)set default param values
   2.178 +        this.paramsSet = new Array();
   2.179 +    };
   2.180 +    /**
   2.181 +     * Transform the given XML DOM
   2.182 +     * @argument sourceDoc The XML DOMDocument to transform
   2.183 +     * @return The transformation result as a DOM Document
   2.184 +     */
   2.185 +    XSLTProcessor.prototype.transformToDocument = function(sourceDoc){
   2.186 +        this.processor.input = sourceDoc;
   2.187 +        var outDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
   2.188 +        this.processor.output = outDoc; 
   2.189 +        this.processor.transform();
   2.190 +        return outDoc;
   2.191 +    };
   2.192 +    /**
   2.193 +     * Not sure if this works in IE. Maybe this will allow non-well-formed
   2.194 +     * transformation results (i.e. with no single root element)
   2.195 +     * @argument sourceDoc The XML DOMDocument to transform
   2.196 +     * @return The transformation result as a DOM Fragment
   2.197 +     */
   2.198 +    XSLTProcessor.prototype.transformToFragment = function(sourceDoc, ownerDocument){
   2.199 +        return this.transformToDocument(sourceDoc);
   2.200 +    };
   2.201 +    /**
   2.202 +     * Set global XSLT parameter of the imported stylesheet
   2.203 +     * @argument nsURI The parameter namespace URI
   2.204 +     * @argument name The parameter base name
   2.205 +     * @argument value The new parameter value
   2.206 +     */
   2.207 +    XSLTProcessor.prototype.setParameter = function(nsURI, name, value){
   2.208 +        /* nsURI is optional but cannot be null */
   2.209 +        if(nsURI){
   2.210 +            this.processor.addParameter(name, value, nsURI);
   2.211 +        }else{
   2.212 +            this.processor.addParameter(name, value);
   2.213 +        };
   2.214 +        /* update updated params for getParameter */
   2.215 +        if(!this.paramsSet[""+nsURI]){
   2.216 +            this.paramsSet[""+nsURI] = new Array();
   2.217 +        };
   2.218 +        this.paramsSet[""+nsURI][name] = value;
   2.219 +    };
   2.220 +    /**
   2.221 +     * Gets a parameter if previously set by setParameter. Returns null
   2.222 +     * otherwise
   2.223 +     * @argument name The parameter base name
   2.224 +     * @argument value The new parameter value
   2.225 +     * @return The parameter value if reviously set by setParameter, null otherwise
   2.226 +     */
   2.227 +    XSLTProcessor.prototype.getParameter = function(nsURI, name){
   2.228 +        if(this.paramsSet[""+nsURI] && this.paramsSet[""+nsURI][name])
   2.229 +            return this.paramsSet[""+nsURI][name];
   2.230 +        else
   2.231 +            return null;
   2.232 +    };
   2.233 +}
   2.234 +else{ /* end IE initialization, try to deal with real browsers now ;-) */
   2.235 +   if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){
   2.236 +        if(window.XMLDocument){
   2.237 +            /**
   2.238 +            * <p>Emulate IE's onreadystatechange attribute</p>
   2.239 +            */
   2.240 +            XMLDocument.prototype.onreadystatechange = null;
   2.241 +            /**
   2.242 +            * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
   2.243 +            * <ul><li>1 == LOADING,</li>
   2.244 +            * <li>2 == LOADED,</li>
   2.245 +            * <li>3 == INTERACTIVE,</li>
   2.246 +            * <li>4 == COMPLETED</li></ul>
   2.247 +            */
   2.248 +            XMLDocument.prototype.readyState = 0;
   2.249 +            /**
   2.250 +            * <p>Emulate IE's parseError attribute</p>
   2.251 +            */
   2.252 +            XMLDocument.prototype.parseError = 0;
   2.253 +
   2.254 +            // NOTE: setting async to false will only work with documents
   2.255 +            // called over HTTP (meaning a server), not the local file system,
   2.256 +            // unless you are using Moz 1.4+.
   2.257 +            // BTW the try>catch block is for 1.4; I haven't found a way to check if
   2.258 +            // the property is implemented without
   2.259 +            // causing an error and I dont want to use user agent stuff for that...
   2.260 +            var _SARISSA_SYNC_NON_IMPLEMENTED = false;
   2.261 +            try{
   2.262 +                /**
   2.263 +                * <p>Emulates IE's async property for Moz versions prior to 1.4.
   2.264 +                * It controls whether loading of remote XML files works
   2.265 +                * synchronously or asynchronously.</p>
   2.266 +                */
   2.267 +                XMLDocument.prototype.async = true;
   2.268 +                _SARISSA_SYNC_NON_IMPLEMENTED = true;
   2.269 +            }catch(e){/* trap */};
   2.270 +            /**
   2.271 +            * <p>Keeps a handle to the original load() method. Internal use and only
   2.272 +            * if Mozilla version is lower than 1.4</p>
   2.273 +            * @private
   2.274 +            */
   2.275 +            XMLDocument.prototype._sarissa_load = XMLDocument.prototype.load;
   2.276 +
   2.277 +            /**
   2.278 +            * <p>Overrides the original load method to provide synchronous loading for
   2.279 +            * Mozilla versions prior to 1.4, using an XMLHttpRequest object (if
   2.280 +            * async is set to false)</p>
   2.281 +            * @returns the DOM Object as it was before the load() call (may be  empty)
   2.282 +            */
   2.283 +            XMLDocument.prototype.load = function(sURI) {
   2.284 +                var oDoc = document.implementation.createDocument("", "", null);
   2.285 +                Sarissa.copyChildNodes(this, oDoc);
   2.286 +                this.parseError = 0;
   2.287 +                Sarissa.__setReadyState__(this, 1);
   2.288 +                try {
   2.289 +                    if(this.async == false && _SARISSA_SYNC_NON_IMPLEMENTED) {
   2.290 +                        var tmp = new XMLHttpRequest();
   2.291 +                        tmp.open("GET", sURI, false);
   2.292 +                        tmp.send(null);
   2.293 +                        Sarissa.__setReadyState__(this, 2);
   2.294 +                        Sarissa.copyChildNodes(tmp.responseXML, this);
   2.295 +                        Sarissa.__setReadyState__(this, 3);
   2.296 +                    }
   2.297 +                    else {
   2.298 +                        this._sarissa_load(sURI);
   2.299 +                    };
   2.300 +                }
   2.301 +                catch (objException) {
   2.302 +                    this.parseError = -1;
   2.303 +                }
   2.304 +                finally {
   2.305 +                    if(this.async == false){
   2.306 +                        Sarissa.__handleLoad__(this);
   2.307 +                    };
   2.308 +                };
   2.309 +                return oDoc;
   2.310 +            };
   2.311 +        };//if(window.XMLDocument)
   2.312 +
   2.313 +        /**
   2.314 +         * <p>Ensures the document was loaded correctly, otherwise sets the
   2.315 +         * parseError to -1 to indicate something went wrong. Internal use</p>
   2.316 +         * @private
   2.317 +         */
   2.318 +        Sarissa.__handleLoad__ = function(oDoc){
   2.319 +            if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror")
   2.320 +                oDoc.parseError = -1;
   2.321 +            Sarissa.__setReadyState__(oDoc, 4);
   2.322 +        };
   2.323 +        
   2.324 +        /**
   2.325 +        * <p>Attached by an event handler to the load event. Internal use.</p>
   2.326 +        * @private
   2.327 +        */
   2.328 +        _sarissa_XMLDocument_onload = function(){
   2.329 +            Sarissa.__handleLoad__(this);
   2.330 +        };
   2.331 +        
   2.332 +        /**
   2.333 +         * <p>Sets the readyState property of the given DOM Document object.
   2.334 +         * Internal use.</p>
   2.335 +         * @private
   2.336 +         * @argument oDoc the DOM Document object to fire the
   2.337 +         *          readystatechange event
   2.338 +         * @argument iReadyState the number to change the readystate property to
   2.339 +         */
   2.340 +        Sarissa.__setReadyState__ = function(oDoc, iReadyState){
   2.341 +            oDoc.readyState = iReadyState;
   2.342 +            if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function")
   2.343 +                oDoc.onreadystatechange();
   2.344 +        };
   2.345 +        /**
   2.346 +        * <p>Factory method to obtain a new DOM Document object</p>
   2.347 +        * @argument sUri the namespace of the root node (if any)
   2.348 +        * @argument sUri the local name of the root node (if any)
   2.349 +        * @returns a new DOM Document
   2.350 +        */
   2.351 +        Sarissa.getDomDocument = function(sUri, sName){
   2.352 +            var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null);
   2.353 +            oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false);
   2.354 +            return oDoc;
   2.355 +        };        
   2.356 +    };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT)
   2.357 +};
   2.358 +//==========================================
   2.359 +// Common stuff
   2.360 +//==========================================
   2.361 +if(!window.DOMParser){
   2.362 +    /** 
   2.363 +    * DOMParser is a utility class, used to construct DOMDocuments from XML strings
   2.364 +    * @constructor
   2.365 +    */
   2.366 +    DOMParser = function() {
   2.367 +    };
   2.368 +    /** 
   2.369 +    * Construct a new DOM Document from the given XMLstring
   2.370 +    * @param sXml the given XML string
   2.371 +    * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). 
   2.372 +    * @return a new DOM Document from the given XML string
   2.373 +    */
   2.374 +    DOMParser.prototype.parseFromString = function(sXml, contentType){
   2.375 +        var doc = Sarissa.getDomDocument();
   2.376 +        doc.loadXML(sXml);
   2.377 +        return doc;
   2.378 +    };
   2.379 +    
   2.380 +};
   2.381 +
   2.382 +if(window.XMLHttpRequest){
   2.383 +    Sarissa.IS_ENABLED_XMLHTTP = true;
   2.384 +}
   2.385 +else if(_SARISSA_IS_IE){
   2.386 +    /**
   2.387 +     * Emulate XMLHttpRequest
   2.388 +     * @constructor
   2.389 +     */
   2.390 +    XMLHttpRequest = function() {
   2.391 +        return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
   2.392 +    };
   2.393 +    Sarissa.IS_ENABLED_XMLHTTP = true;
   2.394 +};
   2.395 +
   2.396 +if(!window.document.importNode && _SARISSA_IS_IE){
   2.397 +    try{
   2.398 +        /**
   2.399 +        * Implements importNode for the current window document in IE using innerHTML.
   2.400 +        * Testing showed that DOM was multiple times slower than innerHTML for this,
   2.401 +        * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML)
   2.402 +        * please gimme a call.
   2.403 +        * @param oNode the Node to import
   2.404 +        * @param bChildren whether to include the children of oNode
   2.405 +        * @returns the imported node for further use
   2.406 +        */
   2.407 +        window.document.importNode = function(oNode, bChildren){
   2.408 +            var importNode = document.createElement("div");
   2.409 +            if(bChildren)
   2.410 +                importNode.innerHTML = Sarissa.serialize(oNode);
   2.411 +            else
   2.412 +                importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false));
   2.413 +            return importNode.firstChild;
   2.414 +        };
   2.415 +        }catch(e){};
   2.416 +};
   2.417 +if(!Sarissa.getParseErrorText){
   2.418 +    /**
   2.419 +     * <p>Returns a human readable description of the parsing error. Usefull
   2.420 +     * for debugging. Tip: append the returned error string in a &lt;pre&gt;
   2.421 +     * element if you want to render it.</p>
   2.422 +     * <p>Many thanks to Christian Stocker for the initial patch.</p>
   2.423 +     * @argument oDoc The target DOM document
   2.424 +     * @returns The parsing error description of the target Document in
   2.425 +     *          human readable form (preformated text)
   2.426 +     */
   2.427 +    Sarissa.getParseErrorText = function (oDoc){
   2.428 +        var parseErrorText = Sarissa.PARSED_OK;
   2.429 +        if(oDoc.parseError != 0){
   2.430 +            /*moz*/
   2.431 +            if(oDoc.documentElement.tagName == "parsererror"){
   2.432 +                parseErrorText = oDoc.documentElement.firstChild.data;
   2.433 +                parseErrorText += "\n" +  oDoc.documentElement.firstChild.nextSibling.firstChild.data;
   2.434 +            }/*konq*/
   2.435 +            else if(oDoc.documentElement.tagName == "html"){
   2.436 +                parseErrorText = Sarissa.getText(oDoc.documentElement.getElementsByTagName("h1")[0], false) + "\n";
   2.437 +                parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("body")[0], false) + "\n";
   2.438 +                parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false);
   2.439 +            };
   2.440 +        };
   2.441 +        return parseErrorText;
   2.442 +    };
   2.443 +};
   2.444 +Sarissa.getText = function(oNode, deep){
   2.445 +    var s = "";
   2.446 +    var nodes = oNode.childNodes;
   2.447 +    for(var i=0; i < nodes.length; i++){
   2.448 +        var node = nodes[i];
   2.449 +        var nodeType = node.nodeType;
   2.450 +        if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
   2.451 +            s += node.data;
   2.452 +        }
   2.453 +        else if(deep == true
   2.454 +                    && (nodeType == Node.ELEMENT_NODE
   2.455 +                        || nodeType == Node.DOCUMENT_NODE
   2.456 +                        || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
   2.457 +            s += Sarissa.getText(node, true);
   2.458 +        };
   2.459 +    };
   2.460 +    return s;
   2.461 +};
   2.462 +if(window.XMLSerializer){
   2.463 +    /**
   2.464 +     * <p>Factory method to obtain the serialization of a DOM Node</p>
   2.465 +     * @returns the serialized Node as an XML string
   2.466 +     */
   2.467 +    Sarissa.serialize = function(oDoc){
   2.468 +        return (new XMLSerializer()).serializeToString(oDoc);
   2.469 +    };
   2.470 +}else{
   2.471 +    if((Sarissa.getDomDocument("","foo", null)).xml){
   2.472 +        // see non-IE version
   2.473 +        Sarissa.serialize = function(oDoc) {
   2.474 +            // TODO: check for HTML document and return innerHTML instead
   2.475 +            return oDoc.xml;
   2.476 +        };
   2.477 +        /**
   2.478 +         * Utility class to serialize DOM Node objects to XML strings
   2.479 +         * @constructor
   2.480 +         */
   2.481 +        XMLSerializer = function(){};
   2.482 +        /**
   2.483 +         * Serialize the given DOM Node to an XML string
   2.484 +         * @param oNode the DOM Node to serialize
   2.485 +         */
   2.486 +        XMLSerializer.prototype.serializeToString = function(oNode) {
   2.487 +            return oNode.xml;
   2.488 +        };
   2.489 +    };
   2.490 +};
   2.491 +
   2.492 +/**
   2.493 + * strips tags from a markup string
   2.494 + */
   2.495 +Sarissa.stripTags = function (s) {
   2.496 +    return s.replace(/<[^>]+>/g,"");
   2.497 +};
   2.498 +/**
   2.499 + * <p>Deletes all child nodes of the given node</p>
   2.500 + * @argument oNode the Node to empty
   2.501 + */
   2.502 +Sarissa.clearChildNodes = function(oNode) {
   2.503 +    while(oNode.hasChildNodes()){
   2.504 +        oNode.removeChild(oNode.firstChild);
   2.505 +    };
   2.506 +};
   2.507 +/**
   2.508 + * <p> Copies the childNodes of nodeFrom to nodeTo</p>
   2.509 + * <p> <b>Note:</b> The second object's original content is deleted before 
   2.510 + * the copy operation, unless you supply a true third parameter</p>
   2.511 + * @argument nodeFrom the Node to copy the childNodes from
   2.512 + * @argument nodeTo the Node to copy the childNodes to
   2.513 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
   2.514 + */
   2.515 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
   2.516 +    if(!bPreserveExisting){
   2.517 +        Sarissa.clearChildNodes(nodeTo);
   2.518 +    };
   2.519 +    var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
   2.520 +    var nodes = nodeFrom.childNodes;
   2.521 +    if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
   2.522 +        for(var i=0;i < nodes.length;i++) {
   2.523 +            nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
   2.524 +        };
   2.525 +    }
   2.526 +    else{
   2.527 +        for(var i=0;i < nodes.length;i++) {
   2.528 +            nodeTo.appendChild(nodes[i].cloneNode(true));
   2.529 +        };
   2.530 +    };
   2.531 +};
   2.532 +
   2.533 +/**
   2.534 + * <p> Moves the childNodes of nodeFrom to nodeTo</p>
   2.535 + * <p> <b>Note:</b> The second object's original content is deleted before 
   2.536 + * the move operation, unless you supply a true third parameter</p>
   2.537 + * @argument nodeFrom the Node to copy the childNodes from
   2.538 + * @argument nodeTo the Node to copy the childNodes to
   2.539 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
   2.540 + */
   2.541 +Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
   2.542 +    if(!bPreserveExisting){
   2.543 +        Sarissa.clearChildNodes(nodeTo);
   2.544 +    };
   2.545 +    
   2.546 +    var nodes = nodeFrom.childNodes;
   2.547 +    // if within the same doc, just move, else copy and delete
   2.548 +    if(nodeFrom.ownerDocument == nodeTo.ownerDocument){
   2.549 +        nodeTo.appendChild(nodes[i]);
   2.550 +    }else{
   2.551 +        var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
   2.552 +         if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
   2.553 +            for(var i=0;i < nodes.length;i++) {
   2.554 +                nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
   2.555 +            };
   2.556 +        }
   2.557 +        else{
   2.558 +            for(var i=0;i < nodes.length;i++) {
   2.559 +                nodeTo.appendChild(nodes[i].cloneNode(true));
   2.560 +            };
   2.561 +        };
   2.562 +        Sarissa.clearChildNodes(nodeFrom);
   2.563 +    };
   2.564 +    
   2.565 +};
   2.566 +
   2.567 +/** 
   2.568 + * <p>Serialize any object to an XML string. All properties are serialized using the property name
   2.569 + * as the XML element name. Array elements are rendered as <code>array-item</code> elements, 
   2.570 + * using their index/key as the value of the <code>key</code> attribute.</p>
   2.571 + * @argument anyObject the object to serialize
   2.572 + * @argument objectName a name for that object
   2.573 + * @return the XML serializationj of the given object as a string
   2.574 + */
   2.575 +Sarissa.xmlize = function(anyObject, objectName, indentSpace){
   2.576 +    indentSpace = indentSpace?indentSpace:'';
   2.577 +    var s = indentSpace  + '<' + objectName + '>';
   2.578 +    var isLeaf = false;
   2.579 +    if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String 
   2.580 +        || anyObject instanceof Boolean || anyObject instanceof Date){
   2.581 +        s += Sarissa.escape(""+anyObject);
   2.582 +        isLeaf = true;
   2.583 +    }else{
   2.584 +        s += "\n";
   2.585 +        var itemKey = '';
   2.586 +        var isArrayItem = anyObject instanceof Array;
   2.587 +        for(var name in anyObject){
   2.588 +            s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + "   ");
   2.589 +        };
   2.590 +        s += indentSpace;
   2.591 +    };
   2.592 +    return s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n");
   2.593 +};
   2.594 +
   2.595 +/** 
   2.596 + * Escape the given string chacters that correspond to the five predefined XML entities
   2.597 + * @param sXml the string to escape
   2.598 + */
   2.599 +Sarissa.escape = function(sXml){
   2.600 +    return sXml.replace(/&/g, "&amp;")
   2.601 +        .replace(/</g, "&lt;")
   2.602 +        .replace(/>/g, "&gt;")
   2.603 +        .replace(/"/g, "&quot;")
   2.604 +        .replace(/'/g, "&apos;");
   2.605 +};
   2.606 +
   2.607 +/** 
   2.608 + * Unescape the given string. This turns the occurences of the predefined XML 
   2.609 + * entities to become the characters they represent correspond to the five predefined XML entities
   2.610 + * @param sXml the string to unescape
   2.611 + */
   2.612 +Sarissa.unescape = function(sXml){
   2.613 +    return sXml.replace(/&apos;/g,"'")
   2.614 +        .replace(/&quot;/g,"\"")
   2.615 +        .replace(/&gt;/g,">")
   2.616 +        .replace(/&lt;/g,"<")
   2.617 +        .replace(/&amp;/g,"&");
   2.618 +};
   2.619 +//   EOF