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
===================================================================
--- 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 @@
+/*
+ * ====================================================================
+ * About Sarissa:
http://dev.abiss.gr/sarissa
+ * ====================================================================
+ * 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
+ * ====================================================================
+ * Licence
+ * ====================================================================
+ * Sarissa is free software distributed under the GNU GPL version 2 (see <a
href="gpl.txt">gpl.txt</a>) or higher,
+ * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or
higher and Apache Software License 2.0 or higher
+ * (see <a href="asl.txt">asl.txt</a>). 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 submitted those.
+ * In case your copy of Sarissa does not include the license texts, you may find
+ * them online in various formats at <a
href="http://www.gnu.org">http://www.gnu.org</a> and
+ * <a href="http://www.apache.org">http://www.apache.org</a>.
+ *
+ * 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 element
(clickedElem).
+ * @memberOf Sarissa
+ * @param {Node} clickedElem the table heading (<code>th</code>) initiating
the sort.
+ * @param {Function} iFunc the custom sort function if needed. Default (null) is
case-sensitive sort.
+ * You can also use <code>Sarissa.SORT_IGNORE_CASE</code>,
<code>Sarissa.SORT_DATE_US</code>,
+ * and <code>Sarissa.SORT_DATE_EU</code>
+ * @param {boolean} bSkipCache whether to skip the data cache and read table data all
over again. Setting this
+ * to <code>true</code> means the cache for the table, if it exists, will not
be updated either. Defaul is <code>false</code>
+ * @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 example. The
parameters
+ * passed to the callback are the table as a DOM node and the sort column index (zero
based <code>int</code>)
+ * @requires Sarissa sarissa.js
+ */
+Sarissa.sortHtmlTableData = function(clickedElem, iFunc, bSkipCache, oCallbac){
+ // get the table
+ var oTbl = clickedElem.parentNode.parentNode;
+ while(oTbl.nodeName.toLowerCase() != "table"){
+ oTbl = oTbl.parentNode;
+ }
+ // we need a table ID for the cache
+ if(!oTbl.id){
+ oTbl.id = "SarissaTable"+ (Sarissa.tableIdGenCount++);
+ }
+ // the column to sort on
+ var iColIndex = clickedElem.cellIndex;
+ var matrix;
+ // use the cache if available and permitted
+ if(!bSkipCache && Sarissa.tableDataCache[oTbl.id]){
+ matrix = Sarissa.tableDataCache[oTbl.id];
+ }
+ else{
+ // read table, skip any rows containing headings, cache if permitted
+ matrix = this.getArrayFromTableData(oTbl, null, null, "th");
+ if(!bSkipCache){
+ Sarissa.tableDataCache[oTbl.id] = matrix;
+ }
+ }
+ // init state persistence as needed
+ if(!Sarissa.tableColumnSortStates[oTbl.id]){
+ Sarissa.tableColumnSortStates[oTbl.id] = [];
+ }
+ // build a array to sort from the specific column data, adding
+ // original index info as a suffix
+ var sortedColumn = [];
+ for(var i=0; i < matrix.length;i++){
+ sortedColumn[i] = Sarissa.stripTags(matrix[i][iColIndex]) + "_mbns_" + i;
+ }
+ // sort the array
+ if(iFunc){
+ sortedColumn.sort(iFunc);
+ }
+ else{
+ sortedColumn.sort();
+ }
+ // persist column state
+ var sortOrder = Sarissa.tableColumnSortStates[oTbl.id][iColIndex];
+ if(sortOrder != "asc"){
+ Sarissa.tableColumnSortStates[oTbl.id][iColIndex] = "asc";
+ }
+ else{
+ sortedColumn.reverse();
+ Sarissa.tableColumnSortStates[oTbl.id][iColIndex] = "desc";
+ }
+ // create the sorted matrix based on sortedColumn
+ var sortedMatrix = [];
+ for(var j=0; j < matrix.length; j++){
+ var indexItem = sortedColumn[j];
+ var iRow = indexItem.substring(indexItem.indexOf("_mbns_")+6,
indexItem.length);
+ sortedMatrix[j] = [];
+ for(var k=0; k < matrix[j].length; k++){
+ sortedMatrix[j][k] = 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 sort state
persistance
+ * @memberOf Sarissa
+ * @private
+ */
+Sarissa.tableIdGenCount = 0;
+
+/**
+ * Used for persisting sort state per table column
+ * @memberOf Sarissa
+ * @private
+ */
+Sarissa.tableColumnSortStates = [];
+
+/**
+ * Used for caching table data.
+ * @memberOf Sarissa
+ */
+Sarissa.tableDataCache = [];
+
+/**
+ * Keep track of the cache size. The length property is not for associative arrays
+ * and I really dont want to add 50 lines and implement a PseudoHashMap right now :-)
+ * @memberOf Sarissa
+ * @private
+ */
+Sarissa.tableDataCacheSize = 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 = 5;
+
+/**
+ * Updates the cache, discards oldest entry if cache size is exceeded.
+ * @memberOf Sarissa
+ * @private
+ */
+Sarissa.tableDataCachePut = function(sTableId, oArr){
+ if(Sarissa.tableDataCacheSize.length >= Sarissa.tableDataCacheMaxSize){
+ Sarissa.tableDataCache.shift();
+ Sarissa.tableDataCacheSize--;
+ }
+ Sarissa.tableDataCache[sTableId] = oArr;
+ Sarissa.tableDataCacheSize++;
+};
+/**
+ * Updates the cache of a specific table by reposition a column in the cached data.
+ * This is usefull if you use DHTML to visually reposition columns and need to
+ * synchronize the cache.
+ * @memberOf Sarissa
+ * @private
+ */
+Sarissa.tableDataCacheMoveColumn = function(sTableId, oldColumnIndex, newColumnIndex){
+ var oldMatrix = Sarissa.tableDataCache[sTableId];
+ var newMatrix = [];
+ // iterate rows
+ var oldRow, movedColumn, newRow;
+ for(var i=0; i<oldMatrix.length; i++){
+ oldRow = oldMatrix[i];
+ movedColumn = oldRow.splice(oldColumnIndex, 1);
+ newRow = [];
+ // reposition column value
+ for(var j=0;j<oldArr.length;J++){
+ if(j == newColumnIndex){
+ newRow.put(movedColumn);
+ }
+ newRow.put(oldRow[j]);
+ }
+ newMatrix[i] = newRow;
+ }
+ Sarissa.tableDataCache[sTableId] = newMatrix;
+};
+
+/**
+ * Function for case-insensitive sorting or simple comparison. Can be used as
+ * a parameter to <code>Array.sort()</code>.
+ * @memberOf Sarissa
+ * @param a a string
+ * @param b a string
+ * @return -1, 0 or 1 depending on whether <code>a</code> is "less
than", equal or "greater than" <code>b</code>
+ */
+Sarissa.SORT_IGNORE_CASE = function(a, b){
+ var strA = a.toLowerCase(),
+ strB = 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 <code>Array.sort()</code>.
+ * @memberOf Sarissa
+ * @param a a string
+ * @param b a string
+ * @return -1, 0 or 1 depending on whether <code>a</code> is "less
than", equal or "greater than" <code>b</code>
+ */
+Sarissa.SORT_DATE_US = function(a, b){
+ var datA = new Date(a.substring(0, a.lastIndexOf("_mbns_"))),
+ datB = 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 <code>Array.sort()</code>.
+ * @memberOf Sarissa
+ * @param a a string
+ * @param b a string
+ * @return -1, 0 or 1 depending on whether <code>a</code> is "less
than", equal or "greater than" <code>b</code>
+ */
+Sarissa.SORT_DATE_EU = function(a, b){
+ var strA = a.substring(0, a.lastIndexOf("_mbns_")).split("/"),
+ strB = b.substring(0, b.lastIndexOf("_mbns_")).split("/"),
+ datA = new Date(strA[2], strA[1], strA[0]),
+ datB = 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 <code>table</code>, <code>tbody</code>,
<code>thead</code>
+ * or <code>tfooter</code> elements. For custom XML tables, the
+ * <code>sRowName</code> <code>sCellName</code> must be used.
+ * @param sRowName the row element names. Default is <code>tr</code>
+ * @param sCellName the row element names. Default is <code>td</code>
+ * @param sHeadingName the heading element names. If you use this, rows with
+ * headings will be <strong>skipped</strong>. To skip headings when reading
+ * HTML tables use <code>th</code>
+ * @param bStripTags whether to strip markup from cell contents. Default is
<code>false</code>
+ * @return a two-dimensional array with the data found in the given element's rows
+ */
+Sarissa.getArrayFromTableData = function(oElem, sRowName, sCellName, sHeadingName,
bStripTags){
+ if(!sRowName){
+ sRowName = "tr"
+ }
+ if(!sCellName){
+ sCellName = "td"
+ }
+ if(!sHeadingName){
+ sHeadingName = "th"
+ }
+ var rows = oElem.getElementsByTagName(sRowName);
+ var matrix = [];
+ for(var i=0, j=0; i < rows.length; i++) {
+ // skip rows with headings
+ var row = rows[i];
+ if((!sHeadingName) || row.getElementsByTagName(sHeadingName).length == 0){
+ matrix[j] = [];
+ var cells = row.getElementsByTagName(sCellName);
+ for(var k=0; k < cells.length; k++){
+ matrix[j][k] = bStripTags ? Sarissa.stripTags(cells[k].innerHTML) :
cells[k].innerHTML;
+ }
+ j++;
+ }
+ }
+ return matrix;
+};
+
+/**
+ * Update the data of the given element using the giventwo-dimensional array 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 <code>table</code>, <code>tbody</code>,
<code>thead</code>
+ * or <code>tfooter</code> elements. For custom XML tables, the
+ * <code>sRowName</code> <code>sCellName</code> must be used.
+ * @param sRowName the row element names. Default is <code>tr</code>
+ * @param sCellName the row element names. Default is <code>td</code>
+ * @param sHeadingName the heading element names. If you use this, rows with
+ * headings will be <strong>skipped</strong>. To skip headings when reading
+ * HTML tables use <code>th</code>
+ */
+Sarissa.updateTableData = function(oElem, newData, sRowName, sCellName, sHeadingName){
+ if(!sRowName){
+ sRowName = "tr"
+ }
+ if(!sCellName){
+ sCellName = "td"
+ }
+ var rows = oElem.getElementsByTagName(sRowName);
+ for(var i=0, j=0; i < newData.length && j < rows.length; j++){
+ // skip rows with headings
+ var row = rows[j];
+ if((!sHeadingName) || row.getElementsByTagName(sHeadingName).length == 0){
+ var cells = row.getElementsByTagName(sCellName);
+ for(var k=0; k < cells.length; k++){
+ cells[k].innerHTML = newData[i][k];
+ }
+ i++;
+ }
+ }
+};
+
+
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/sarissa.js
===================================================================
--- 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 @@
-/**
+/*
* ====================================================================
* About Sarissa:
http://dev.abiss.gr/sarissa
* ====================================================================
* 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
* ====================================================================
* Licence
* ====================================================================
@@ -33,7 +33,7 @@
* @static
*/
function Sarissa(){}
-Sarissa.VERSION = "0.9.9";
+Sarissa.VERSION = "0.9.9.3";
Sarissa.PARSED_OK = "Document contains no parsing errors";
Sarissa.PARSED_EMPTY = "Document is empty";
Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error";
@@ -117,18 +117,21 @@
_SARISSA_THREADEDDOM_PROGID = null;
_SARISSA_XSLTEMPLATE_PROGID = null;
_SARISSA_XMLHTTP_PROGID = null;
- if(!window.XMLHttpRequest){
- /**
- * Emulate XMLHttpRequest
- * @constructor
- */
- XMLHttpRequest = function() {
- if(!_SARISSA_XMLHTTP_PROGID){
- _SARISSA_XMLHTTP_PROGID =
Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
- }
- 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 = function() {
+ if(!_SARISSA_XMLHTTP_PROGID){
+ _SARISSA_XMLHTTP_PROGID =
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
//============================================
// Factory methods (IE)
@@ -164,7 +167,7 @@
// see non-IE version
Sarissa.getParseErrorText = function (oDoc) {
var parseErrorText = Sarissa.PARSED_OK;
- if(oDoc && oDoc.parseError && oDoc.parseError.errorCode
&& oDoc.parseError.errorCode !== 0){
+ if(oDoc && oDoc.parseError && oDoc.parseError.errorCode
&& oDoc.parseError.errorCode != 0){
parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason +
"\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 transforms.
* @constructor
*/
XSLTProcessor = 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() =
'import' or local-name() = 'include']") !== null){
+ if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() =
'import' or local-name() = 'include']") != null){
converted.async = false;
converted.load(xslDoc.url);
}
@@ -351,7 +353,7 @@
XSLTProcessor.prototype.clearParameters = function(){
for(var nsURI in this.paramsSet){
for(var name in this.paramsSet[nsURI]){
- if(nsURI!==""){
+ if(nsURI!=""){
this.processor.addParameter(name, "", nsURI);
}else{
this.processor.addParameter(name, "");
@@ -389,7 +391,7 @@
Sarissa.__setReadyState__ = function(oDoc, iReadyState){
oDoc.readyState = iReadyState;
oDoc.readystate = iReadyState;
- if (oDoc.onreadystatechange !== null && typeof
oDoc.onreadystatechange == "function") {
+ if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange
== "function") {
oDoc.onreadystatechange();
}
};
@@ -535,7 +537,7 @@
} else if(oDoc.getElementsByTagName("parsererror").length > 0){
var parsererror = oDoc.getElementsByTagName("parsererror")[0];
parseErrorText = Sarissa.getText(parsererror, true)+"\n";
- } else if(oDoc.parseError && oDoc.parseError.errorCode !== 0){
+ } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){
parseErrorText = 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
+ * <code>undefined</code>, <code>null</code> or empty, it is
returned as is.
* @memberOf Sarissa
*/
Sarissa.stripTags = function (s) {
- return s.replace(/<[^>]+>/g,"");
+ return s?s.replace(/<[^>]+>/g,""):s;
};
/**
* <p>Deletes all child nodes of the given node</p>
@@ -605,7 +608,7 @@
*/
Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
if(Sarissa._SARISSA_IS_SAFARI && nodeTo.nodeType == Node.DOCUMENT_NODE){ //
SAFARI_OLD ??
- nodeTo = nodeTo.documentElement; //Appearantly there's a bug in safari where you
can't appendChild to a document node
+ nodeTo = nodeTo.documentElement; //Apparently there's a bug in safari where you
can't appendChild to a document node
}
if((!nodeFrom) || (!nodeTo)){
@@ -714,7 +717,7 @@
/** @private */
Sarissa.updateCursor = function(oTargetElement, sValue) {
- if(oTargetElement && oTargetElement.style &&
oTargetElement.style.cursor !== undefined ){
+ if(oTargetElement && oTargetElement.style &&
oTargetElement.style.cursor != undefined ){
oTargetElement.style.cursor = 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 <code>callback(oNode, oTargetElement)</code>
+ * @param callback (optional) a Function object to execute once the update is finished
successfuly, called as <code>callback(sFromUrl, oTargetElement)</code>.
+ * In case an exception is thrown during execution, the callback is called as
called as <code>callback(sFromUrl, oTargetElement, oException)</code>
* @param skipCache (optional) whether to skip any cache
*/
Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc, callback,
skipCache) {
@@ -737,12 +741,28 @@
Sarissa.updateCursor(oTargetElement, "wait");
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", sFromUrl, true);
- sarissa_dhtml_loadHandler = function() {
+ xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
- Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement,
xsltproc, callback);
+ try{
+ var oDomDoc = xmlhttp.responseXML;
+ if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) ==
Sarissa.PARSED_OK){
+ Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement,
xsltproc);
+ callback(sFromUrl, oTargetElement);
+ }
+ else{
+ throw Sarissa.getParseErrorText(oDomDoc);
+ }
+ }
+ catch(e){
+ if(callback){
+ callback(sFromUrl, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
}
};
- xmlhttp.onreadystatechange = sarissa_dhtml_loadHandler;
if (skipCache) {
var oldage = "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 <code>callback(oNode, oTargetElement)</code>
*/
-Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc, callback) {
+Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
try {
Sarissa.updateCursor(oTargetElement, "wait");
Sarissa.clearChildNodes(oTargetElement);
// check for parsing errors
var ownerDoc = oNode.nodeType == Node.DOCUMENT_NODE?oNode:oNode.ownerDocument;
- if(ownerDoc.parseError && ownerDoc.parseError !== 0) {
+ if(ownerDoc.parseError && ownerDoc.parseError.errorCode != 0) {
var pre = document.createElement("pre");
pre.appendChild(document.createTextNode(Sarissa.getParseErrorText(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
* <code>functionName(oNode, oTargetElement);</code></p>
* <p>Here is an example of using this in a form element:</p>
- * <pre name="code" class="xml"><form
action="/my/form/handler" method="post"
+ * <pre name="code" class="xml">
+ * <div id="targetId"> this content will be
updated</div>
+ * <form action="/my/form/handler" method="post"
* onbeforesubmit="return Sarissa.updateContentFromForm(this,
document.getElementById('targetId'));"><pre>
* <p>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 parameter
@@ -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 <code>callback(oNode, oTargetElement)</code>
- * @param skipCache (optional) whether to skip any cache
+ * @param callback (optional) a Function object to execute once the update is finished
successfuly, called as <code>callback(oNode, oTargetElement)</code>.
+ * In case an exception occurs during excecution and a callback function was
provided, the exception is cought and the callback is called as
+ * <code>callback(oForm, oTargetElement, exception)</code>
*/
Sarissa.updateContentFromForm = function(oForm, oTargetElement, xsltproc, callback) {
try{
- Sarissa.updateCursor(oTargetElement, "wait");
+ Sarissa.updateCursor(oTargetElement, "wait");
// build parameters from form fields
var params = Sarissa.formToQueryString(oForm) + "&" +
Sarissa.REMOTE_CALL_FLAG + "=true";
var xmlhttp = new XMLHttpRequest();
- if(oForm.getAttribute("method") &&
oForm.getAttribute("method").toLowerCase() == "get") {
+ var bUseGet = oForm.getAttribute("method") &&
oForm.getAttribute("method").toLowerCase() == "get";
+ if(bUseGet) {
xmlhttp.open("GET",
oForm.getAttribute("action")+"?"+params, true);
}
else{
@@ -892,17 +917,38 @@
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
}
- sarissa_dhtml_loadHandler = function() {
- if (xmlhttp.readyState == 4) {
- Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement,
xsltproc, callback);
- }
+ xmlhttp.onreadystatechange = function() {
+ try{
+ if (xmlhttp.readyState == 4) {
+ var oDomDoc = xmlhttp.responseXML;
+ if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) ==
Sarissa.PARSED_OK){
+ Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement,
xsltproc);
+ callback(oForm, oTargetElement);
+ }
+ else{
+ throw Sarissa.getParseErrorText(oDomDoc);
+ }
+ }
+ }
+ catch(e){
+ if(callback){
+ callback(oForm, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
};
- xmlhttp.onreadystatechange = 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_xpath.js
===================================================================
--- 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
* ====================================================================
* 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 selectSingleNode
@@ -44,7 +44,7 @@
this.length = i;
};
/** <p>Set an Array as the prototype object</p> */
- SarissaNodeList.prototype = new Array(0);
+ SarissaNodeList.prototype = [];
/** <p>Inherit the Array constructor </p> */
SarissaNodeList.prototype.constructor = Array;
/**
@@ -68,7 +68,7 @@
/** dummy, used to accept IE's stuff without throwing errors */
if(window.XMLDocument && (!XMLDocument.prototype.setProperty)){
XMLDocument.prototype.setProperty = function(x,y){};
- };
+ }
/**
* <p>Programmatically control namespace URI/prefix mappings for XPath
* queries.</p>
@@ -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:</p>
- * <pre>Sarissa.setXpathNamespaces(oDoc,
"xmlns:myprefix=&aposhttp://mynsURI&apos");</pre>
+ * <pre>Sarissa.setXpathNamespaces(oDoc,
"xmlns:myprefix'http://mynsURI'");</pre>
* <p><b>Note 1 </b>: Use this method only if the source document
features
* a default namespace (without a prefix), otherwise just use IE's setProperty
* (moz will rezolve non-default namespaces by itself). You will need to map that
@@ -96,8 +96,8 @@
Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {
//oDoc._sarissa_setXpathNamespaces(sNsSet);
oDoc._sarissa_useCustomResolver = true;
- var namespaces = sNsSet.indexOf(" ")>-1?sNsSet.split("
"):new Array(sNsSet);
- oDoc._sarissa_xpathNamespaces = new Array(namespaces.length);
+ var namespaces = sNsSet.indexOf(" ")>-1?sNsSet.split("
"):[sNsSet];
+ oDoc._sarissa_xpathNamespaces = [];
for(var i=0;i < namespaces.length;i++){
var ns = namespaces[i];
var colonPos = ns.indexOf(":");
@@ -108,8 +108,8 @@
oDoc._sarissa_xpathNamespaces[prefix] = 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 = false;
/** @private */
- XMLDocument.prototype._sarissa_xpathNamespaces = new Array();
+ XMLDocument.prototype._sarissa_xpathNamespaces = [];
/**
* <p>Extends the XMLDocument to emulate IE's selectNodes.</p>
* @argument sExpr the XPath expression to use
@@ -128,13 +128,21 @@
*/
XMLDocument.prototype.selectNodes = function(sExpr, contextNode, returnSingle){
var nsDoc = this;
- var nsresolver = this._sarissa_useCustomResolver
- ? function(prefix){
- var s = 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 = function(prefix){
+ var s = nsDoc._sarissa_xpathNamespaces[prefix];
+ if(s){
+ return s;
+ }
+ else {
+ throw "No namespace URI found for prefix: '" +
prefix+"'";
+ }
+ };
+ }
+ else{
+ this.createNSResolver(this.documentElement);
+ }
var result = null;
if(!returnSingle){
var oResult = this.evaluate(sExpr,
@@ -143,16 +151,17 @@
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var nodeList = new SarissaNodeList(oResult.snapshotLength);
nodeList.expr = sExpr;
- for(var i=0;i<nodeList.length;i++)
+ for(var i=0;i<nodeList.length;i++){
nodeList[i] = oResult.snapshotItem(i);
+ }
result = nodeList;
}
else {
- result = oResult = this.evaluate(sExpr,
+ result = this.evaluate(sExpr,
(contextNode?contextNode:this),
nsresolver,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- };
+ }
return result;
};
/**
@@ -165,10 +174,12 @@
*/
Element.prototype.selectNodes = function(sExpr){
var doc = this.ownerDocument;
- if(doc.selectNodes)
+ if(doc.selectNodes){
return doc.selectNodes(sExpr, this);
- else
+ }
+ else{
throw "Method selectNodes is only supported by XML Elements";
+ }
};
/**
* <p>Extends the XMLDocument to emulate IE's selectSingleNode.</p>
@@ -190,10 +201,12 @@
*/
Element.prototype.selectSingleNode = function(sExpr){
var doc = 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 = true;
-};
\ No newline at end of file
+}
\ No newline at end of file