From richfaces-svn-commits at lists.jboss.org Thu Feb 28 20:13:00 2008 Content-Type: multipart/mixed; boundary="===============6059083703409154184==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r6437 - trunk/framework/impl/src/main/javascript/ajaxjsf. Date: Thu, 28 Feb 2008 20:12:59 -0500 Message-ID: --===============6059083703409154184== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: alexsmirnov Date: 2008-02-28 20:12:59 -0500 (Thu, 28 Feb 2008) New Revision: 6437 Added: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa-table-utils.js Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa.js trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa_ieemu_xpath.js Log: Update Sarissa JS library to version 0.9.9.3 Added: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa-table-utils= .js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa-table-utils.js= (rev 0) +++ trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa-table-utils.js= 2008-02-29 01:12:59 UTC (rev 6437) @@ -0,0 +1,317 @@ +/* + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * About Sarissa: http://dev.abiss.gr/sarissa + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for = native XML APIs. + * The library supports Gecko based browsers like Mozilla and Firefox, + * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and Opera + * @author: @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis= at users full stop sourceforge full stop net + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Licence + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Sarissa is free software distributed under the GNU GPL version 2 (see <= a href=3D"gpl.txt">gpl.txt) or higher, = + * GNU LGPL version 2.1 (see lgpl.txt) or higher = and Apache Software License 2.0 or higher = + * (see asl.txt). This means you can choose one of= the three and use that if you like. If = + * you make modifications under the ASL, i would appreciate it if you subm= itted those. + * In case your copy of Sarissa does not include the license texts, you ma= y find + * them online in various formats at http:/= /www.gnu.org and = + * http://www.apache.org. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY = + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE = + * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE = + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR = + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR = + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE = + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Sort the table data based on the column corresponding to the given TH e= lement (clickedElem). + * @memberOf Sarissa + * @param {Node} clickedElem the table heading (th) initiatin= g the sort. + * @param {Function} iFunc the custom sort function if needed. Default (nu= ll) is case-sensitive sort. + * You can also use Sarissa.SORT_IGNORE_CASE, Sarissa.S= ORT_DATE_US, = + * and Sarissa.SORT_DATE_EU + * @param {boolean} bSkipCache whether to skip the data cache and read tab= le data all over again. Setting this + * to true means the cache for the table, if it exists, will = not be updated either. Defaul is false + * @param {Function} oCallbac a callback function to be executed when the = table is = + * sorted and updated. The callback function may be used for effects for e= xample. The parameters = + * passed to the callback are the table as a DOM node and the sort column = index (zero based int) + * @requires Sarissa sarissa.js + */ +Sarissa.sortHtmlTableData =3D function(clickedElem, iFunc, bSkipCache, oCa= llbac){ + // get the table + var oTbl =3D clickedElem.parentNode.parentNode; + while(oTbl.nodeName.toLowerCase() !=3D "table"){ + oTbl =3D oTbl.parentNode; + } + // we need a table ID for the cache + if(!oTbl.id){ + oTbl.id =3D "SarissaTable"+ (Sarissa.tableIdGenCount++); + } + // the column to sort on + var iColIndex =3D clickedElem.cellIndex; + var matrix; + // use the cache if available and permitted + if(!bSkipCache && Sarissa.tableDataCache[oTbl.id]){ + matrix =3D Sarissa.tableDataCache[oTbl.id]; + } + else{ + // read table, skip any rows containing headings, cache if permitted + matrix =3D this.getArrayFromTableData(oTbl, null, null, "th"); + if(!bSkipCache){ + Sarissa.tableDataCache[oTbl.id] =3D matrix; + } + } + // init state persistence as needed + if(!Sarissa.tableColumnSortStates[oTbl.id]){ + Sarissa.tableColumnSortStates[oTbl.id] =3D []; + } + // build a array to sort from the specific column data, adding = + // original index info as a suffix + var sortedColumn =3D []; + for(var i=3D0; i < matrix.length;i++){ + sortedColumn[i] =3D Sarissa.stripTags(matrix[i][iColIndex]) + "_mbns_" += i; + } + // sort the array + if(iFunc){ + sortedColumn.sort(iFunc); + } + else{ + sortedColumn.sort(); + } + // persist column state + var sortOrder =3D Sarissa.tableColumnSortStates[oTbl.id][iColIndex]; + if(sortOrder !=3D "asc"){ + Sarissa.tableColumnSortStates[oTbl.id][iColIndex] =3D "asc"; + } + else{ + sortedColumn.reverse(); + Sarissa.tableColumnSortStates[oTbl.id][iColIndex] =3D "desc"; + } + // create the sorted matrix based on sortedColumn + var sortedMatrix =3D []; + for(var j=3D0; j < matrix.length; j++){ + var indexItem =3D sortedColumn[j]; + var iRow =3D indexItem.substring(indexItem.indexOf("_mbns_")+6, indexIte= m.length); + sortedMatrix[j] =3D []; + for(var k=3D0; k < matrix[j].length; k++){ + sortedMatrix[j][k] =3D matrix[iRow][k]; + } + } + // update table data, skipping rows with headings + this.updateTableData(oTbl, sortedMatrix, null, null, "th"); + if(oCallbac){ + oCallbac(oTbl, iColIndex); = + } +}; + +/** + * Used for generating table IDs, which are required for the cache and sor= t state persistance = + * @memberOf Sarissa + * @private + */ +Sarissa.tableIdGenCount =3D 0; + +/** + * Used for persisting sort state per table column + * @memberOf Sarissa + * @private + */ +Sarissa.tableColumnSortStates =3D []; + +/** + * Used for caching table data. + * @memberOf Sarissa + */ +Sarissa.tableDataCache =3D []; + +/** + * Keep track of the cache size. The length property is not for associativ= e arrays = + * and I really dont want to add 50 lines and implement a PseudoHashMap ri= ght now :-) + * @memberOf Sarissa + * @private + */ +Sarissa.tableDataCacheSize =3D 0; + +/** + * The table data cache size, used for sorting HTML tables. You can change= it, default is 5 (tables). When a = + * table is cached exceeding the cache size, the oldest entry is disgarded= from the cache. + * @memberOf Sarissa + */ +Sarissa.tableDataCacheMaxSize =3D 5; + +/** + * Updates the cache, discards oldest entry if cache size is exceeded. + * @memberOf Sarissa + * @private + */ +Sarissa.tableDataCachePut =3D function(sTableId, oArr){ + if(Sarissa.tableDataCacheSize.length >=3D Sarissa.tableDataCacheMaxSize){ + Sarissa.tableDataCache.shift(); + Sarissa.tableDataCacheSize--; + } + Sarissa.tableDataCache[sTableId] =3D oArr; + Sarissa.tableDataCacheSize++; +}; +/** + * Updates the cache of a specific table by reposition a column in the cac= hed data. + * This is usefull if you use DHTML to visually reposition columns and nee= d to = + * synchronize the cache. + * @memberOf Sarissa + * @private + */ +Sarissa.tableDataCacheMoveColumn =3D function(sTableId, oldColumnIndex, ne= wColumnIndex){ = + var oldMatrix =3D Sarissa.tableDataCache[sTableId]; + var newMatrix =3D []; + // iterate rows + var oldRow, movedColumn, newRow; + for(var i=3D0; iArray.sort(). + * @memberOf Sarissa + * @param a a string + * @param b a string + * @return -1, 0 or 1 depending on whether a is "less than", = equal or "greater than" b + */ +Sarissa.SORT_IGNORE_CASE =3D function(a, b){ + var strA =3D a.toLowerCase(), + strB =3D b.toLowerCase(); + if(strA < strB) return -1; + else if(strA > strB) return 1; + else return 0; +}; + +/** + * Function for comparing US dates. Can be used as = + * a parameter to Array.sort(). + * @memberOf Sarissa + * @param a a string + * @param b a string + * @return -1, 0 or 1 depending on whether a is "less than", = equal or "greater than" b + */ +Sarissa.SORT_DATE_US =3D function(a, b){ + var datA =3D new Date(a.substring(0, a.lastIndexOf("_mbns_"))), + datB =3D new Date(b.substring(0, b.lastIndexOf("_mbns_"))); + if(datA < datB) return -1; + else if(datA > datB) return 1; + else return 0; + = +}; + +/** + * Function for comparing EU dates. Can be used as = + * a parameter to Array.sort(). + * @memberOf Sarissa + * @param a a string + * @param b a string + * @return -1, 0 or 1 depending on whether a is "less than", = equal or "greater than" b + */ +Sarissa.SORT_DATE_EU =3D function(a, b){ + var strA =3D a.substring(0, a.lastIndexOf("_mbns_")).split("/"), = + strB =3D b.substring(0, b.lastIndexOf("_mbns_")).split("/"), + datA =3D new Date(strA[2], strA[1], strA[0]), = + datB =3D new Date(strB[2], strB[1], strB[0]); + if(datA < datB) return -1; + else if(datA > datB) return 1; + else return 0; +}; + +/** + * Get the data of the given element as a two-dimensional array. The = + * given XML or HTML Element must match the structure of an HTML table, = + * although element names may be different. + * @memberOf Sarissa + * @param oElem an HTML or XML table. The method works out of the box = + * for table, tbody, thead = + * or tfooter elements. For custom XML tables, the = + * sRowName sCellName must be used. + * @param sRowName the row element names. Default is tr + * @param sCellName the row element names. Default is td + * @param sHeadingName the heading element names. If you use this, rows wi= th = + * headings will be skipped. To skip headings when readin= g = + * HTML tables use th + * @param bStripTags whether to strip markup from cell contents. Default i= s false + * @return a two-dimensional array with the data found in the given elemen= t's rows + */ +Sarissa.getArrayFromTableData =3D function(oElem, sRowName, sCellName, sHe= adingName, bStripTags){ + if(!sRowName){ + sRowName =3D "tr" + } + if(!sCellName){ + sCellName =3D "td" + } + if(!sHeadingName){ + sHeadingName =3D "th" + } + var rows =3D oElem.getElementsByTagName(sRowName); + var matrix =3D []; + for(var i=3D0, j=3D0; i < rows.length; i++) { + // skip rows with headings + var row =3D rows[i]; + if((!sHeadingName) || row.getElementsByTagName(sHeadingName).length =3D= =3D 0){ + matrix[j] =3D []; + var cells =3D row.getElementsByTagName(sCellName); + for(var k=3D0; k < cells.length; k++){ + matrix[j][k] =3D bStripTags ? Sarissa.stripTags(cells[k].innerHTML) : = cells[k].innerHTML; + } + j++; + } + } + return matrix; +}; + +/** + * Update the data of the given element using the giventwo-dimensional arr= ay as a source. The = + * given XML or HTML Element must match the structure of an HTML table. + * @memberOf Sarissa + * @param oElem an HTML or XML table. The method works out of the box = + * for table, tbody, thead = + * or tfooter elements. For custom XML tables, the = + * sRowName sCellName must be used. + * @param sRowName the row element names. Default is tr + * @param sCellName the row element names. Default is td + * @param sHeadingName the heading element names. If you use this, rows wi= th = + * headings will be skipped. To skip headings when readin= g = + * HTML tables use th + */ +Sarissa.updateTableData =3D function(oElem, newData, sRowName, sCellName, = sHeadingName){ + if(!sRowName){ + sRowName =3D "tr" + } + if(!sCellName){ + sCellName =3D "td" + } + var rows =3D oElem.getElementsByTagName(sRowName); + for(var i=3D0, j=3D0; i < newData.length && j < rows.length; j++){ + // skip rows with headings + var row =3D rows[j]; + if((!sHeadingName) || row.getElementsByTagName(sHeadingName).length =3D= =3D 0){ + var cells =3D row.getElementsByTagName(sCellName); + for(var k=3D0; k < cells.length; k++){ + cells[k].innerHTML =3D newData[i][k]; + } + i++; + } + } +}; + + Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa.js 2008-02-28 = 19:14:15 UTC (rev 6436) +++ trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa.js 2008-02-29 = 01:12:59 UTC (rev 6437) @@ -1,11 +1,11 @@ -/** +/* * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * About Sarissa: http://dev.abiss.gr/sarissa * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * Sarissa is an ECMAScript library acting as a cross-browser wrapper for = native XML APIs. * The library supports Gecko based browsers like Mozilla and Firefox, * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and Opera - * @author: @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis= at users full stop sourceforge full stop net + * @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users= full stop sourceforge full stop net * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * Licence * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -33,7 +33,7 @@ * @static */ function Sarissa(){} -Sarissa.VERSION =3D "0.9.9"; +Sarissa.VERSION =3D "0.9.9.3"; Sarissa.PARSED_OK =3D "Document contains no parsing errors"; Sarissa.PARSED_EMPTY =3D "Document is empty"; Sarissa.PARSED_UNKNOWN_ERROR =3D "Not well-formed or other error"; @@ -117,18 +117,21 @@ _SARISSA_THREADEDDOM_PROGID =3D null; _SARISSA_XSLTEMPLATE_PROGID =3D null; _SARISSA_XMLHTTP_PROGID =3D null; - if(!window.XMLHttpRequest){ - /** - * Emulate XMLHttpRequest - * @constructor - */ - XMLHttpRequest =3D function() { - if(!_SARISSA_XMLHTTP_PROGID){ - _SARISSA_XMLHTTP_PROGID =3D Sarissa.pickRecentProgID(["Msx= ml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTT= P"]); - } - return new ActiveXObject(_SARISSA_XMLHTTP_PROGID); - }; - } + // commenting the condition out; we need to redefine XMLHttpRequest = + // anyway as IE7 hardcodes it to MSXML3.0 causing version problems = + // between different activex controls = + //if(!window.XMLHttpRequest){ + /** + * Emulate XMLHttpRequest + * @constructor + */ + XMLHttpRequest =3D function() { + if(!_SARISSA_XMLHTTP_PROGID){ + _SARISSA_XMLHTTP_PROGID =3D Sarissa.pickRecentProgID(["Msxml2.= XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]); + } + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID); + }; + //} // we dont need this anymore //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // Factory methods (IE) @@ -164,7 +167,7 @@ // see non-IE version = Sarissa.getParseErrorText =3D function (oDoc) { var parseErrorText =3D Sarissa.PARSED_OK; - if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.pa= rseError.errorCode !=3D=3D 0){ + if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.pa= rseError.errorCode !=3D 0){ parseErrorText =3D "XML Parsing Error: " + oDoc.parseError.rea= son + = "\nLocation: " + oDoc.parseError.url + = "\nLine Number " + oDoc.parseError.line + ", Column " + = @@ -187,8 +190,7 @@ oDoc.setProperty("SelectionNamespaces", sNsSet); }; /** - * An implementation of Mozilla's XSLTProcessor for IE. = - * Reuses the same XSLT stylesheet for multiple transforms + * A class that reuses the same XSLT stylesheet for multiple transform= s. * @constructor */ XSLTProcessor =3D function(){ @@ -219,7 +221,7 @@ catch(e){ // Ignore. "AllowDocumentFunction" is only supported in MSXML = 3.0 SP4 and later. } = - if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() =3D= 'import' or local-name() =3D 'include']") !=3D=3D null){ + if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() =3D= 'import' or local-name() =3D 'include']") !=3D null){ converted.async =3D false; converted.load(xslDoc.url); } = @@ -351,7 +353,7 @@ XSLTProcessor.prototype.clearParameters =3D function(){ for(var nsURI in this.paramsSet){ for(var name in this.paramsSet[nsURI]){ - if(nsURI!=3D=3D""){ + if(nsURI!=3D""){ this.processor.addParameter(name, "", nsURI); }else{ this.processor.addParameter(name, ""); @@ -389,7 +391,7 @@ Sarissa.__setReadyState__ =3D function(oDoc, iReadyState){ oDoc.readyState =3D iReadyState; oDoc.readystate =3D iReadyState; - if (oDoc.onreadystatechange !=3D=3D null && typeof oDoc.onread= ystatechange =3D=3D "function") { + if (oDoc.onreadystatechange !=3D null && typeof oDoc.onreadyst= atechange =3D=3D "function") { oDoc.onreadystatechange(); } }; @@ -535,7 +537,7 @@ } else if(oDoc.getElementsByTagName("parsererror").length > 0){ var parsererror =3D oDoc.getElementsByTagName("parsererror")[0= ]; parseErrorText =3D Sarissa.getText(parsererror, true)+"\n"; - } else if(oDoc.parseError && oDoc.parseError.errorCode !=3D=3D 0){ + } else if(oDoc.parseError && oDoc.parseError.errorCode !=3D 0){ parseErrorText =3D Sarissa.PARSED_UNKNOWN_ERROR; } return parseErrorText; @@ -577,11 +579,12 @@ } = /** - * Strips tags from the given markup string + * Strips tags from the given markup string. If the given string is = + * undefined, null or empty, it is returned as i= s. = * @memberOf Sarissa */ Sarissa.stripTags =3D function (s) { - return s.replace(/<[^>]+>/g,""); + return s?s.replace(/<[^>]+>/g,""):s; }; /** *

Deletes all child nodes of the given node

@@ -605,7 +608,7 @@ */ Sarissa.copyChildNodes =3D function(nodeFrom, nodeTo, bPreserveExisting) { if(Sarissa._SARISSA_IS_SAFARI && nodeTo.nodeType =3D=3D Node.DOCUMENT_= NODE){ // SAFARI_OLD ?? - nodeTo =3D nodeTo.documentElement; //Appearantly there's a bug in saf= ari where you can't appendChild to a document node + nodeTo =3D nodeTo.documentElement; //Apparently there's a bug in safa= ri where you can't appendChild to a document node } = if((!nodeFrom) || (!nodeTo)){ @@ -714,7 +717,7 @@ = /** @private */ Sarissa.updateCursor =3D function(oTargetElement, sValue) { - if(oTargetElement && oTargetElement.style && oTargetElement.style.curs= or !=3D=3D undefined ){ + if(oTargetElement && oTargetElement.style && oTargetElement.style.curs= or !=3D undefined ){ oTargetElement.style.cursor =3D sValue; } }; @@ -729,7 +732,8 @@ * @param oTargetElement the element to update * @param xsltproc (optional) the transformer to use on the returned * content before updating the target element with it - * @param callback (optional) a Function object to execute once the update= is finished successfuly, called as callback(oNode, oTargetElement) + * @param callback (optional) a Function object to execute once the update= is finished successfuly, called as callback(sFromUrl, oTargetElement= ). = + * In case an exception is thrown during execution, the callback is= called as called as callback(sFromUrl, oTargetElement, oException) * @param skipCache (optional) whether to skip any cache */ Sarissa.updateContentFromURI =3D function(sFromUrl, oTargetElement, xsltpr= oc, callback, skipCache) { @@ -737,12 +741,28 @@ Sarissa.updateCursor(oTargetElement, "wait"); var xmlhttp =3D new XMLHttpRequest(); xmlhttp.open("GET", sFromUrl, true); - sarissa_dhtml_loadHandler =3D function() { + xmlhttp.onreadystatechange =3D function() { if (xmlhttp.readyState =3D=3D 4) { - Sarissa.updateContentFromNode(xmlhttp.responseXML, oTarget= Element, xsltproc, callback); + try{ + var oDomDoc =3D xmlhttp.responseXML; + if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) =3D=3D Sari= ssa.PARSED_OK){ + Sarissa.updateContentFromNode(xmlhttp.responseXML, oTarg= etElement, xsltproc); + callback(sFromUrl, oTargetElement); + } + else{ + throw Sarissa.getParseErrorText(oDomDoc); + } + } + catch(e){ + if(callback){ + callback(sFromUrl, oTargetElement, e); + } + else{ + throw e; + } + } } }; - xmlhttp.onreadystatechange =3D sarissa_dhtml_loadHandler; if (skipCache) { var oldage =3D "Sat, 1 Jan 2000 00:00:00 GMT"; xmlhttp.setRequestHeader("If-Modified-Since", oldage); @@ -751,7 +771,12 @@ } catch(e){ Sarissa.updateCursor(oTargetElement, "auto"); - throw e; + if(callback){ + callback(sFromUrl, oTargetElement, e); + } + else{ + throw e; + } } }; = @@ -765,15 +790,14 @@ * @param oTargetElement the element to update * @param xsltproc (optional) the transformer to use on the given = * DOM node before updating the target element with it - * @param callback (optional) a Function object to execute once the update= is finished successfuly, called as callback(oNode, oTargetElement) */ -Sarissa.updateContentFromNode =3D function(oNode, oTargetElement, xsltproc= , callback) { +Sarissa.updateContentFromNode =3D function(oNode, oTargetElement, xsltproc= ) { try { Sarissa.updateCursor(oTargetElement, "wait"); Sarissa.clearChildNodes(oTargetElement); // check for parsing errors var ownerDoc =3D oNode.nodeType =3D=3D Node.DOCUMENT_NODE?oNode:oN= ode.ownerDocument; - if(ownerDoc.parseError && ownerDoc.parseError !=3D=3D 0) { + if(ownerDoc.parseError && ownerDoc.parseError.errorCode !=3D 0) { var pre =3D document.createElement("pre"); pre.appendChild(document.createTextNode(Sarissa.getParseErrorT= ext(ownerDoc))); oTargetElement.appendChild(pre); @@ -797,12 +821,9 @@ } } } - if (callback) { - callback(oNode, oTargetElement); - } } catch(e) { - throw e; + throw e; } finally{ Sarissa.updateCursor(oTargetElement, "auto"); @@ -861,7 +882,9 @@ * You can also pass a callback function to be executed when the update is= finished. The function will be called as = * functionName(oNode, oTargetElement);

*

Here is an example of using this in a form element:

- *
<form action=3D"/my/form/handler" m=
ethod=3D"post" =

+ * 
+ * <div id=3D"targetId"> this content will be updated</div>
+ * <form action=3D"/my/form/handler" method=3D"post" =

  *     onbeforesubmit=3D"return Sarissa.updateContentFromForm(this, docume=
nt.getElementById('targetId'));">
  * 

If JavaScript is supported, the form will not be submitted. Instead,= Sarissa will * scan the form and make an appropriate AJAX request, also adding a param= eter = @@ -874,16 +897,18 @@ * @param oTargetElement the element to update * @param xsltproc (optional) the transformer to use on the returned * content before updating the target element with it - * @param callback (optional) a Function object to execute once the update= is finished successfuly, called as callback(oNode, oTargetElement) - * @param skipCache (optional) whether to skip any cache + * @param callback (optional) a Function object to execute once the update= is finished successfuly, called as callback(oNode, oTargetElement). = + * In case an exception occurs during excecution and a callback fun= ction was provided, the exception is cought and the callback is called as = + * callback(oForm, oTargetElement, exception) */ Sarissa.updateContentFromForm =3D function(oForm, oTargetElement, xsltproc= , callback) { try{ - Sarissa.updateCursor(oTargetElement, "wait"); + Sarissa.updateCursor(oTargetElement, "wait"); // build parameters from form fields var params =3D Sarissa.formToQueryString(oForm) + "&" + Sarissa.RE= MOTE_CALL_FLAG + "=3Dtrue"; var xmlhttp =3D new XMLHttpRequest(); - if(oForm.getAttribute("method") && oForm.getAttribute("method").to= LowerCase() =3D=3D "get") { + var bUseGet =3D oForm.getAttribute("method") && oForm.getAttribute= ("method").toLowerCase() =3D=3D "get"; = + if(bUseGet) { xmlhttp.open("GET", oForm.getAttribute("action")+"?"+params, t= rue); } else{ @@ -892,17 +917,38 @@ xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); } - sarissa_dhtml_loadHandler =3D function() { - if (xmlhttp.readyState =3D=3D 4) { - Sarissa.updateContentFromNode(xmlhttp.responseXML, oTarget= Element, xsltproc, callback); - } + xmlhttp.onreadystatechange =3D function() { + try{ + if (xmlhttp.readyState =3D=3D 4) { + var oDomDoc =3D xmlhttp.responseXML; + if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) =3D=3D Sari= ssa.PARSED_OK){ + Sarissa.updateContentFromNode(xmlhttp.responseXML, oTarg= etElement, xsltproc); + callback(oForm, oTargetElement); + } + else{ + throw Sarissa.getParseErrorText(oDomDoc); + } + } + } + catch(e){ + if(callback){ + callback(oForm, oTargetElement, e); + } + else{ + throw e; + } + } }; - xmlhttp.onreadystatechange =3D sarissa_dhtml_loadHandler; - xmlhttp.send(""); + xmlhttp.send(bUseGet?"":params); } catch(e){ Sarissa.updateCursor(oTargetElement, "auto"); - throw e; + if(callback){ + callback(oForm, oTargetElement, e); + } + else{ + throw e; + } } return false; }; Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa_ieemu_xp= ath.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa_ieemu_xpath.js= 2008-02-28 19:14:15 UTC (rev 6436) +++ trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa_ieemu_xpath.js= 2008-02-29 01:12:59 UTC (rev 6437) @@ -3,7 +3,7 @@ * About * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * Sarissa cross browser XML library - IE XPath Emulation = - * @version 0.9.9 + * @version 0.9.9.3 * @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users= full stop sourceforge full stop net * * This script emulates Internet Explorer's selectNodes and selectSingleNo= de @@ -44,7 +44,7 @@ this.length =3D i; }; /**

Set an Array as the prototype object

*/ - SarissaNodeList.prototype =3D new Array(0); + SarissaNodeList.prototype =3D []; /**

Inherit the Array constructor

*/ SarissaNodeList.prototype.constructor =3D Array; /** @@ -68,7 +68,7 @@ /** dummy, used to accept IE's stuff without throwing errors */ if(window.XMLDocument && (!XMLDocument.prototype.setProperty)){ XMLDocument.prototype.setProperty =3D function(x,y){}; - }; + } /** *

Programmatically control namespace URI/prefix mappings for XPath * queries.

@@ -79,7 +79,7 @@ * are looking for elements in the null namespace. If you need to look * for nodes in the default namespace, you need to map a prefix to it * first like:

- *
Sarissa.setXpathNamespaces(oDoc, "xmlns:myprefix=3D&ap=
oshttp://mynsURI&apos");
+ *
Sarissa.setXpathNamespaces(oDoc, "xmlns:myprefix'http://mynsURI=
'");
*

Note 1 : Use this method only if the source document featu= res * a default namespace (without a prefix), otherwise just use IE's setP= roperty * (moz will rezolve non-default namespaces by itself). You will need t= o map that @@ -96,8 +96,8 @@ Sarissa.setXpathNamespaces =3D function(oDoc, sNsSet) { //oDoc._sarissa_setXpathNamespaces(sNsSet); oDoc._sarissa_useCustomResolver =3D true; - var namespaces =3D sNsSet.indexOf(" ")>-1?sNsSet.split(" "):new Ar= ray(sNsSet); - oDoc._sarissa_xpathNamespaces =3D new Array(namespaces.length); + var namespaces =3D sNsSet.indexOf(" ")>-1?sNsSet.split(" "):[sNsSe= t]; + oDoc._sarissa_xpathNamespaces =3D []; for(var i=3D0;i < namespaces.length;i++){ var ns =3D namespaces[i]; var colonPos =3D ns.indexOf(":"); @@ -108,8 +108,8 @@ oDoc._sarissa_xpathNamespaces[prefix] =3D uri; }else{ throw "Bad format on namespace declaration(s) given"; - }; - }; + } + } }; /** * @private Flag to control whether a custom namespace resolver should @@ -117,7 +117,7 @@ */ XMLDocument.prototype._sarissa_useCustomResolver =3D false; /** @private */ - XMLDocument.prototype._sarissa_xpathNamespaces =3D new Array(); + XMLDocument.prototype._sarissa_xpathNamespaces =3D []; /** *

Extends the XMLDocument to emulate IE's selectNodes.

* @argument sExpr the XPath expression to use @@ -128,13 +128,21 @@ */ XMLDocument.prototype.selectNodes =3D function(sExpr, contextNode, ret= urnSingle){ var nsDoc =3D this; - var nsresolver =3D this._sarissa_useCustomResolver - ? function(prefix){ - var s =3D nsDoc._sarissa_xpathNamespaces[prefix]; - if(s)return s; - else throw "No namespace URI found for prefix: '" + prefix+"'"; - } - : this.createNSResolver(this.documentElement); + var nsresolver; + if(this._sarissa_useCustomResolver){ + nsresolver =3D function(prefix){ + var s =3D nsDoc._sarissa_xpathNamespaces[prefix]; + if(s){ + return s; + } + else { + throw "No namespace URI found for prefix: '" + prefix+= "'"; + } + }; + } + else{ + this.createNSResolver(this.documentElement); + } var result =3D null; if(!returnSingle){ var oResult =3D this.evaluate(sExpr, @@ -143,16 +151,17 @@ XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var nodeList =3D new SarissaNodeList(oResult.snapshotLength); nodeList.expr =3D sExpr; - for(var i=3D0;iExtends the XMLDocument to emulate IE's selectSingleNode.

@@ -190,10 +201,12 @@ */ Element.prototype.selectSingleNode =3D function(sExpr){ var doc =3D this.ownerDocument; - if(doc.selectSingleNode) + if(doc.selectSingleNode){ return doc.selectSingleNode(sExpr, this); - else + } + else{ throw "Method selectNodes is only supported by XML Elements"; + } }; Sarissa.IS_ENABLED_SELECT_NODES =3D true; -}; \ No newline at end of file +} \ No newline at end of file --===============6059083703409154184==--