Author: hqm
Date: 2007-10-28 19:32:02 -0700 (Sun, 28 Oct 2007)
New Revision: 7037
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/data/LzHTTPDataProvider.lzs
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzHTTPLoader.js
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzHTTPLoader.as
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
openlaszlo/branches/wafflecone/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
Log:
merge from r6855 in trunk, for LPP-4844
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/data/LzHTTPDataProvider.lzs
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/data/LzHTTPDataProvider.lzs
2007-10-29 01:36:40 UTC (rev 7036)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/data/LzHTTPDataProvider.lzs
2007-10-29 02:32:02 UTC (rev 7037)
@@ -201,7 +201,7 @@
function loadTimeout( loader, data ) {
var dreq = loader.dataRequest;
dreq.status = LzDataRequest.TIMEOUT;
- loader.owner.loadResponse( dreq, data );
+ dreq.onstatus.sendEvent( dreq );
}
function setRequestError (dreq, msg) {
@@ -220,6 +220,7 @@
// all its values.
var content = null;
+
if (data == null) {
this.setRequestError(dreq, "client could not parse XML from
server");
dreq.onstatus.sendEvent( dreq );
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzHTTPLoader.js
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzHTTPLoader.js
2007-10-29 01:36:40 UTC (rev 7036)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzHTTPLoader.js
2007-10-29 02:32:02 UTC (rev 7037)
@@ -14,6 +14,8 @@
this.options = {parsexml: true};
this.requestheaders = {};
this.requestmethod = LzHTTPLoader.GET_METHOD;
+
+ this.__loaderid = LzHTTPLoader.loaderIDCounter++;
}
// Default callback handlers
@@ -61,8 +63,10 @@
LzHTTPLoader.prototype.abort = function () {
if (this.req) {
- this.req.cancel();
- // [todo hqm 2006-07 ] +++ abort timeout timer
+ this.__abort = true;
+ this.req.abort();
+ this.req = null;
+ this.removeTimeout(this);
}
}
@@ -113,10 +117,16 @@
// headers can be a hashtable or null
LzHTTPLoader.prototype.open = function (method, url, username, password) {
- {
+ if (this.req) {
+ Debug.warn("pending request for id=%s", this.__loaderid);
+ }
+
+ {
#pragma "passThrough=true"
this.req = window.XMLHttpRequest? new XMLHttpRequest(): new
ActiveXObject("Microsoft.XMLHTTP");
}
+ this.__abort = false;
+ this.__timeout = false;
this.requesturl = url;
this.requestmethod = method;
@@ -189,7 +199,9 @@
// holds list of outstanding data requests, to handle timeouts
-LzHTTPLoader.activeRequests = [];
+//LzHTTPLoader.activeRequests = [];
+LzHTTPLoader.activeRequests = {};
+LzHTTPLoader.loaderIDCounter = 0;
// Default infinite timeout
LzHTTPLoader.prototype.timeout = Infinity;
@@ -199,49 +211,64 @@
// [todo hqm 2006-07] Should we have an API method for setting LzLoader
timeout?
}
-// Set up a pending timeout for a dataset.
+// Set up a pending timeout for a loader.
+/*
LzHTTPLoader.prototype.setupTimeout = function (obj, duration) {
var endtime = (new Date()).getTime() + duration;
LzHTTPLoader.activeRequests.push(obj, endtime);
setTimeout("LzHTTPLoader.__LZcheckXMLHTTPTimeouts()", duration);
}
+*/
+LzHTTPLoader.prototype.setupTimeout = function (obj, duration) {
+ var endtime = (new Date()).getTime() + duration;
+ //obj.__loaderid = LzHTTPLoader.loaderIDCounter++;//uncomment to give
LzHTTPLoader-instance a new loader-id
+ var lid = obj.__loaderid;
-// Remove a dataset from the timeouts list.
+ LzHTTPLoader.activeRequests[lid] = [obj, endtime];
+ var timeoutid = setTimeout("LzHTTPLoader.__LZcheckXMLHTTPTimeouts(" + lid
+ ")", duration);
+ LzHTTPLoader.activeRequests[lid][2] = timeoutid;
+}
+
+// Remove a loader from the timeouts list.
LzHTTPLoader.prototype.removeTimeout = function (target) {
- var activeReqs = LzHTTPLoader.activeRequests;
- LzHTTPLoader.activeRequests = [];
- // copy every dataset in the list except for the target
- for (var i = 0; i < activeReqs.length; i+=2) {
- var dset = activeReqs[i];
- var dstimeout = activeReqs[i+1];
- if (dset != target) {
- LzHTTPLoader.activeRequests.push(dset, dstimeout);
+ var lid = target.__loaderid;
+ //Debug.write("remove timeout for id=%s", lid);
+ if (lid != null) {
+ var reqarr = LzHTTPLoader.activeRequests[lid];
+ if (reqarr && reqarr[0] === target) {
+ clearTimeout(reqarr[2]);
+ delete LzHTTPLoader.activeRequests[lid];
}
}
}
// Check if any outstanding requests have timed out.
-LzHTTPLoader.__LZcheckXMLHTTPTimeouts = function () {
- var activeReqs = LzHTTPLoader.activeRequests;
- LzHTTPLoader.activeRequests = [];
- for (var i = 0; i < activeReqs.length; i+=2) {
- var loader = activeReqs[i];
- var dstimeout = activeReqs[i+1];
+LzHTTPLoader.__LZcheckXMLHTTPTimeouts = function (lid) {
+ var req = LzHTTPLoader.activeRequests[lid];
+ if (req) {
var now = (new Date()).getTime();
- if (now > dstimeout) {
+ var loader = req[0];
+ var dstimeout = req[1];
+ //Debug.write("diff %d", now - dstimeout);
+ if (now >= dstimeout) {
+ //Debug.write("timeout for %s", lid);
+ delete LzHTTPLoader.activeRequests[lid];
+ loader.__timeout = true;
if (loader.req) {
loader.req.abort();
}
- this.req = null;
+ loader.req = null;
loader.loadTimeout(loader, null);
} else {
// if it hasn't timed out, add it back to the list for the future
- LzHTTPLoader.activeRequests.push(loader, dstimeout);
+ //Debug.write("recheck timeout");
+ var timeoutid =
setTimeout("LzHTTPLoader.__LZcheckXMLHTTPTimeouts(" + lid + ")", now -
dstimeout);
+ req[2] = timeoutid;
}
}
}
-
+
LzHTTPLoader.prototype.getElapsedTime = function () {
return ((new Date()).getTime() - this.gstart);
}
@@ -267,45 +294,58 @@
var __pthis__ = this;
this.req.onreadystatechange = function () {
if (__pthis__.req == null) { return; }
-
+ //Debug.write("readyState=%d", __pthis__.req.readyState);
if (__pthis__.req.readyState == 4) {
- // only if "OK"
- if (__pthis__.req.status == 200 || __pthis__.req.status ==
304) {
- var elt = null;
- var xml = __pthis__.req.responseXML;
- __pthis__.responseXML = xml;
- var lzxdata = null;
- if (xml != null && parsexml) {
- var nodes = __pthis__.req.responseXML.childNodes;
- // find first content (type == 1) child node
- for (var i = 0; i < nodes.length; i++) {
- var child = nodes.item(i);
- if (child.nodeType == 1) {
- elt = child;
- break;
+ if (__pthis__.__timeout) {
+ //Debug.write("timeout for id=%s, xhr=%w",
__pthis__.__loaderid, __pthis__.req);
+ } else if (__pthis__.__abort) {
+ //Debug.write("abort for id=%s, xhr=%w",
__pthis__.__loaderid, __pthis__.req);
+ } else {
+ try {
+ // only if "OK"
+ //Debug.write("status=%d", __pthis__.req.status);
+ if (__pthis__.req.status == 200 ||
__pthis__.req.status == 304) {
+ var elt = null;
+ var xml = __pthis__.req.responseXML;
+ __pthis__.responseXML = xml;
+ var lzxdata = null;
+ if (xml != null && parsexml) {
+ var nodes =
__pthis__.req.responseXML.childNodes;
+ // find first content (type == 1) child node
+ for (var i = 0; i < nodes.length; i++) {
+ var child = nodes.item(i);
+ if (child.nodeType == 1) {
+ elt = child;
+ break;
+ }
+ }
+ lzxdata = LzXMLTranslator.copyXML(elt,
+
__pthis__.options.trimwhitespace,
+
__pthis__.options.nsprefix);
}
+
+ __pthis__.responseText =
__pthis__.req.responseText;
+ __pthis__.removeTimeout(__pthis__);
+
+
+
+ /**** DEBUGGING
+ var xmlSerializer = new XMLSerializer();
+ var markup = xmlSerializer.serializeToString(elt);
+ Debug.write("loadXMLDoc", elt, markup,
d.serialize());
+ *** /DEBUGGING
+ */
+ __pthis__.req = null;
+ __pthis__.loadSuccess(__pthis__, lzxdata);
+ } else {
+ __pthis__.req = null;
+ __pthis__.loadError(__pthis__, null);
}
- lzxdata = LzXMLTranslator.copyXML(elt,
-
__pthis__.options.trimwhitespace,
-
__pthis__.options.nsprefix);
+ } catch (e) {
+ //if you abort a request, readyState will be set to 4,
+ //but reading status will result in an exception (at
least in Firefox).
+ //Debug.write("catched error: %s", e);
}
-
- __pthis__.responseText = __pthis__.req.responseText;
- __pthis__.removeTimeout(__pthis__);
-
-
-
- /**** DEBUGGING
- var xmlSerializer = new XMLSerializer();
- var markup = xmlSerializer.serializeToString(elt);
- Debug.write("loadXMLDoc", elt, markup, d.serialize());
- *** /DEBUGGING
- */
- __pthis__.req = null;
- __pthis__.loadSuccess(__pthis__, lzxdata);
- } else {
- __pthis__.req = null;
- __pthis__.loadError(__pthis__, null);
}
}
};
@@ -319,6 +359,8 @@
this.req.send(postbody);
}
// Set up the timeout
- this.setupTimeout(this, this.timeout);
+ if (isFinite(this.timeout)) {
+ this.setupTimeout(this, this.timeout);
+ }
}
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzHTTPLoader.as
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzHTTPLoader.as
2007-10-29 01:36:40 UTC (rev 7036)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzHTTPLoader.as
2007-10-29 02:32:02 UTC (rev 7037)
@@ -34,9 +34,9 @@
// Default callback handlers
-LzHTTPLoader.prototype._loadSuccessHandler = function (data)
{this.loadSuccess(this,data);}
-LzHTTPLoader.prototype._loadErrorHandler = function (data) {
this.loadError(this,data);}
-LzHTTPLoader.prototype._loadTimeoutHandler = function (data) {
this.loadTimeout(this,data);}
+LzHTTPLoader.prototype._loadSuccessHandler = function (data) {
this.loadSuccess(this,data); }
+LzHTTPLoader.prototype._loadErrorHandler = function (data) { this.loadError
(this,data); }
+LzHTTPLoader.prototype._loadTimeoutHandler = function (data) {
this.loadTimeout(this,data); }
LzHTTPLoader.GET_METHOD = "GET";
LzHTTPLoader.POST_METHOD = "POST";
Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
2007-10-29 01:36:40 UTC (rev 7036)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
2007-10-29 02:32:02 UTC (rev 7037)
@@ -144,7 +144,7 @@
// object. This can happen if a serverless data load timed out in
// the LFC, but eventually returned something via the
// LoadVars.sendAndLoad() callback.
- if (loadobj.loaded) {
+ if (loadobj.loaded && loadobj.valid) {
if ($debug) {
Debug.warn("%w.returnData: %w already loaded",
this, loadobj);
@@ -399,7 +399,7 @@
}
if (loadobj) {
this.unload(loadobj);
- if (this.ontimeout.ready) this.ontimeout.sendEvent( loadobj.reqobj);
+ if (this.ontimeout.ready) this.ontimeout.sendEvent();
}
}
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
===================================================================
---
openlaszlo/branches/wafflecone/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
2007-10-29 01:36:40 UTC (rev 7036)
+++
openlaszlo/branches/wafflecone/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
2007-10-29 02:32:02 UTC (rev 7037)
@@ -334,8 +334,18 @@
// <dataset> tags that are not top level datasets.
if (elt.getName().equals("dataset")) {
+ boolean contentIsLiteralXMLData = true;
String datafromchild = elt.getAttributeValue("datafromchild");
- if (! "true".equals(datafromchild)) {
+ String src = elt.getAttributeValue("src");
+ String type = elt.getAttributeValue("type");
+
+ if ((type != null && (type.equals("soap") || type.equals("http")))
+ || (src != null && XMLUtils.isURL(src))
+ || "true".equals(datafromchild)) {
+ contentIsLiteralXMLData = false;
+ }
+
+ if (contentIsLiteralXMLData) {
// Default to legacy behavior, treat all children as XML
literal data.
attrs.put("initialdata", getDatasetContent(elt, env));
includeChildren = false;
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins