PageSourceSearch

https://www.borsaitaliana.it/borsa/dwr/engine.js

js borsaitaliana.it collected 2026-10-02 02:16:18 UTC 47,364 bytes, 1,330 lines download raw bytes

1/*
2 * Copyright 2005 Joe Walker
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Declare an object to which we can add real functions.
19 */
20if (dwr == null) var dwr = {};
21if (dwr.engine == null) dwr.engine = {};
22if (DWREngine == null) var DWREngine = dwr.engine;
23
24/**
25 * Set an alternative error handler from the default alert box.
26 * @see getahead.org/dwr/browser/engine/errors
27 */
28dwr.engine.setErrorHandler = function(handler) {
29  dwr.engine._errorHandler = handler;
30};
31
32/**
33 * Set an alternative warning handler from the default alert box.
34 * @see getahead.org/dwr/browser/engine/errors
35 */
36dwr.engine.setWarningHandler = function(handler) {
37  dwr.engine._warningHandler = handler;
38};
39
40/**
41 * Setter for the text/html handler - what happens if a DWR request gets an HTML
42 * reply rather than the expected Javascript. Often due to login timeout
43 */
44dwr.engine.setTextHtmlHandler = function(handler) {
45  dwr.engine._textHtmlHandler = handler;
46};
47
48/**
49 * Set a default timeout value for all calls. 0 (the default) turns timeouts off.
50 * @see getahead.org/dwr/browser/engine/errors
51 */
52dwr.engine.setTimeout = function(timeout) {
53  dwr.engine._timeout = timeout;
54};
55
56/**
57 * The Pre-Hook is called before any DWR remoting is done.
58 * @see getahead.org/dwr/browser/engine/hooks
59 */
60dwr.engine.setPreHook = function(handler) {
61  dwr.engine._preHook = handler;
62};
63
64/**
65 * The Post-Hook is called after any DWR remoting is done.
66 * @see getahead.org/dwr/browser/engine/hooks
67 */
68dwr.engine.setPostHook = function(handler) {
69  dwr.engine._postHook = handler;
70};
71
72/**
73 * Custom headers for all DWR calls
74 * @see getahead.org/dwr/????
75 */
76dwr.engine.setHeaders = function(headers) {
77  dwr.engine._headers = headers;
78};
79
80/**
81 * Custom parameters for all DWR calls
82 * @see getahead.org/dwr/????
83 */
84dwr.engine.setParameters = function(parameters) {
85  dwr.engine._parameters = parameters;
86};
87
88/** XHR remoting type constant. See dwr.engine.set[Rpc|Poll]Type() */
89dwr.engine.XMLHttpRequest = 1;
90
91/** XHR remoting type constant. See dwr.engine.set[Rpc|Poll]Type() */
92dwr.engine.IFrame = 2;
93
94/** XHR remoting type constant. See dwr.engine.setRpcType() */
95dwr.engine.ScriptTag = 3;
96
97/**
98 * Set the preferred remoting type.
99 * @param newType One of dwr.engine.XMLHttpRequest or dwr.engine.IFrame or dwr.engine.ScriptTag
100 * @see getahead.org/dwr/browser/engine/options
101 */
102dwr.engine.setRpcType = function(newType) {
103  if (newType != dwr.engine.XMLHttpRequest && newType != dwr.engine.IFrame && newType != dwr.engine.ScriptTag) {
104    dwr.engine._handleError(null, { name:"dwr.engine.invalidRpcType", message:"RpcType must be one of dwr.engine.XMLHttpRequest or dwr.engine.IFrame or dwr.engine.ScriptTag" });
105    return;
106  }
107  dwr.engine._rpcType = newType;
108};
109
110/**
111 * Which HTTP method do we use to send results? Must be one of "GET" or "POST".
112 * @see getahead.org/dwr/browser/engine/options
113 */
114dwr.engine.setHttpMethod = function(httpMethod) {
115  if (httpMethod != "GET" && httpMethod != "POST") {
116    dwr.engine._handleError(null, { name:"dwr.engine.invalidHttpMethod", message:"Remoting method must be one of GET or POST" });
117    return;
118  }
119  dwr.engine._httpMethod = httpMethod;
120};
121
122/**
123 * Ensure that remote calls happen in the order in which they were sent? (Default: false)
124 * @see getahead.org/dwr/browser/engine/ordering
125 */
126dwr.engine.setOrdered = function(ordered) {
127  dwr.engine._ordered = ordered;
128};
129
130/**
131 * Do we ask the XHR object to be asynchronous? (Default: true)
132 * @see getahead.org/dwr/browser/engine/options
133 */
134dwr.engine.setAsync = function(async) {
135  dwr.engine._async = async;
136};
137
138/**
139 * Does DWR poll the server for updates? (Default: false)
140 * @see getahead.org/dwr/browser/engine/options
141 */
142dwr.engine.setActiveReverseAjax = function(activeReverseAjax) {
143  if (activeReverseAjax) {
144    // Bail if we are already started
145    if (dwr.engine._activeReverseAjax) return;
146    dwr.engine._activeReverseAjax = true;
147    dwr.engine._poll();
148  }
149  else {
150    // Can we cancel an existing request?
151    if (dwr.engine._activeReverseAjax && dwr.engine._pollReq) dwr.engine._pollReq.abort();
152    dwr.engine._activeReverseAjax = false;
153  }
154  // TODO: in iframe mode, if we start, stop, start then the second start may
155  // well kick off a second iframe while the first is still about to return
156  // we should cope with this but we don't
157};
158
159/**
160 * The default message handler.
161 * @see getahead.org/dwr/browser/engine/errors
162 */
163dwr.engine.defaultErrorHandler = function(message, ex) {
164  dwr.engine._debug("Error: " + ex.name + ", " + ex.message, true);
165  if (message == null || message == "") alert("A server error has occured.");
166  // Ignore NS_ERROR_NOT_AVAILABLE if Mozilla is being narky
167  else if (message.indexOf("0x80040111") != -1) dwr.engine._debug(message);
168  else alert(message);
169};
170
171/**
172 * The default warning handler.
173 * @see getahead.org/dwr/browser/engine/errors
174 */
175dwr.engine.defaultWarningHandler = function(message, ex) {
176  dwr.engine._debug(message);
177};
178
179/**
180 * For reduced latency you can group several remote calls together using a batch.
181 * @see getahead.org/dwr/browser/engine/batch
182 */
183dwr.engine.beginBatch = function() {
184  if (dwr.engine._batch) {
185    dwr.engine._handleError(null, { name:"dwr.engine.batchBegun", message:"Batch already begun" });
186    return;
187  }
188  dwr.engine._batch = dwr.engine._createBatch();
189};
190
191/**
192 * Finished grouping a set of remote calls together. Go and execute them all.
193 * @see getahead.org/dwr/browser/engine/batch
194 */
195dwr.engine.endBatch = function(options) {
196  var batch = dwr.engine._batch;
197  if (batch == null) {
198    dwr.engine._handleError(null, { name:"dwr.engine.batchNotBegun", message:"No batch in progress" });
199    return;
200  }
201  dwr.engine._batch = null;
202  if (batch.map.callCount == 0) return;
203
204  // The hooks need to be merged carefully to preserve ordering
205  if (options) dwr.engine._mergeBatch(batch, options);
206
207  // In ordered mode, we don't send unless the list of sent items is empty
208  if (dwr.engine._ordered && dwr.engine._batchesLength != 0) {
209    dwr.engine._batchQueue[dwr.engine._batchQueue.length] = batch;
210  }
211  else {
212    dwr.engine._sendData(batch);
213  }
214};
215
216/** @deprecated */
217dwr.engine.setPollMethod = function(type) { dwr.engine.setPollType(type); };
218dwr.engine.setMethod = function(type) { dwr.engine.setRpcType(type); };
219dwr.engine.setVerb = function(verb) { dwr.engine.setHttpMethod(verb); };
220dwr.engine.setPollType = function() { dwr.engine._debug("Manually setting the Poll Type is not supported"); };
221
222//==============================================================================
223// Only private stuff below here
224//==============================================================================
225
226/** The original page id sent from the server */
227dwr.engine._origScriptSessionId = "9C1E4CCAA5DA5F23DC811DC6A0150192";
228
229/** The session cookie name */
230dwr.engine._sessionCookieName = "JSESSIONID"; // JSESSIONID
231
232/** Is GET enabled for the benefit of Safari? */
233dwr.engine._allowGetForSafariButMakeForgeryEasier = "false";
234
235/** The script prefix to strip in the case of scriptTagProtection. */
236dwr.engine._scriptTagProtection = "throw 'allowScriptTagRemoting is false.';";
237
238/** The default path to the DWR servlet */
239dwr.engine._defaultPath = "/borsa/dwr";
240
241/** Do we use XHR for reverse ajax because we are not streaming? */
242dwr.engine._pollWithXhr = "false";
243
244/** The read page id that we calculate */
245dwr.engine._scriptSessionId = null;
246
247/** The function that we use to fetch/calculate a session id */
248dwr.engine._getScriptSessionId = function() {
249  if (dwr.engine._scriptSessionId == null) {
250    dwr.engine._scriptSessionId = dwr.engine._origScriptSessionId + Math.floor(Math.random() * 1000);
251  }
252  return dwr.engine._scriptSessionId;
253};
254
255/** A function to call if something fails. */
256dwr.engine._errorHandler = dwr.engine.defaultErrorHandler;
257
258/** For debugging when something unexplained happens. */
259dwr.engine._warningHandler = dwr.engine.defaultWarningHandler;
260
261/** A function to be called before requests are marshalled. Can be null. */
262dwr.engine._preHook = null;
263
264/** A function to be called after replies are received. Can be null. */
265dwr.engine._postHook = null;
266
267/** An map of the batches that we have sent and are awaiting a reply on. */
268dwr.engine._batches = {};
269
270/** A count of the number of outstanding batches. Should be == to _batches.length unless prototype has messed things up */
271dwr.engine._batchesLength = 0;
272
273/** In ordered mode, the array of batches waiting to be sent */
274dwr.engine._batchQueue = [];
275
276/** What is the default rpc type */
277dwr.engine._rpcType = dwr.engine.XMLHttpRequest;
278
279/** What is the default remoting method (ie GET or POST) */
280dwr.engine._httpMethod = "POST";
281
282/** Do we attempt to ensure that calls happen in the order in which they were sent? */
283dwr.engine._ordered = false;
284
285/** Do we make the calls async? */
286dwr.engine._async = true;
287
288/** The current batch (if we are in batch mode) */
289dwr.engine._batch = null;
290
291/** The global timeout */
292dwr.engine._timeout = 0;
293
294/** ActiveX objects to use when we want to convert an xml string into a DOM object. */
295dwr.engine._DOMDocument = ["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"];
296
297/** The ActiveX objects to use when we want to do an XMLHttpRequest call. */
298dwr.engine._XMLHTTP = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
299
300/** Are we doing comet or polling? */
301dwr.engine._activeReverseAjax = false;
302
303/** The iframe that we are using to poll */
304dwr.engine._outstandingIFrames = [];
305
306/** The xhr object that we are using to poll */
307dwr.engine._pollReq = null;
308
309/** How many milliseconds between internal comet polls */
310dwr.engine._pollCometInterval = 200;
311
312/** How many times have we re-tried to poll? */
313dwr.engine._pollRetries = 0;
314dwr.engine._maxPollRetries = 0;
315
316/** Do we do a document.reload if we get a text/html reply? */
317dwr.engine._textHtmlHandler = null;
318
319/** If you wish to send custom headers with every request */
320dwr.engine._headers = null;
321
322/** If you wish to send extra custom request parameters with each request */
323dwr.engine._parameters = null;
324
325/** Undocumented interceptors - do not use */
326dwr.engine._postSeperator = "\n";
327dwr.engine._defaultInterceptor = function(data) { return data; };
328dwr.engine._urlRewriteHandler = dwr.engine._defaultInterceptor;
329dwr.engine._contentRewriteHandler = dwr.engine._defaultInterceptor;
330dwr.engine._replyRewriteHandler = dwr.engine._defaultInterceptor;
331
332/** Batch ids allow us to know which batch the server is answering */
333dwr.engine._nextBatchId = 0;
334
335/** A list of the properties that need merging from calls to a batch */
336dwr.engine._propnames = [ "rpcType", "httpMethod", "async", "timeout", "errorHandler", "warningHandler", "textHtmlHandler" ];
337
338/** Do we stream, or can be hacked to do so? */
339dwr.engine._partialResponseNo = 0;
340dwr.engine._partialResponseYes = 1;
341dwr.engine._partialResponseFlush = 2;
342
343/** Is this page in the process of unloading? */
344dwr.engine._unloading = false;
345
346/**
347 * @private Send a request. Called by the Javascript interface stub
348 * @param path part of URL after the host and before the exec bit without leading or trailing /s
349 * @param scriptName The class to execute
350 * @param methodName The method on said class to execute
351 * @param func The callback function to which any returned data should be passed
352 *       if this is null, any returned data will be ignored
353 * @param vararg_params The parameters to pass to the above class
354 */
355dwr.engine._execute = function(path, scriptName, methodName, vararg_params) {
356  var singleShot = false;
357  if (dwr.engine._batch == null) {
358    dwr.engine.beginBatch();
359    singleShot = true;
360  }
361  var batch = dwr.engine._batch;
362  // To make them easy to manipulate we copy the arguments into an args array
363  var args = [];
364  for (var i = 0; i < arguments.length - 3; i++) {
365    args[i] = arguments[i + 3];
366  }
367  // All the paths MUST be to the same servlet
368  if (batch.path == null) {
369    batch.path = path;
370  }
371  else {
372    if (batch.path != path) {
373      dwr.engine._handleError(batch, { name:"dwr.engine.multipleServlets", message:"Can't batch requests to multiple DWR Servlets." });
374      return;
375    }
376  }
377  // From the other params, work out which is the function (or object with
378  // call meta-data) and which is the call parameters
379  var callData;
380  var lastArg = args[args.length - 1];
381  if (typeof lastArg == "function" || lastArg == null) callData = { callback:args.pop() };
382  else callData = args.pop();
383
384  // Merge from the callData into the batch
385  dwr.engine._mergeBatch(batch, callData);
386  batch.handlers[batch.map.callCount] = {
387    exceptionHandler:callData.exceptionHandler,
388    callback:callData.callback
389  };
390
391  // Copy to the map the things that need serializing
392  var prefix = "c" + batch.map.callCount + "-";
393  batch.map[prefix + "scriptName"] = scriptName;
394  batch.map[prefix + "methodName"] = methodName;
395  batch.map[prefix + "id"] = batch.map.callCount;
396  var refctx = [];
397  for (i = 0; i < args.length; i++) {
398    dwr.engine._serializeAll(batch, refctx, args[i], prefix + "param" + i);
399  }
400
401  // Now we have finished remembering the call, we incr the call count
402  batch.map.callCount++;
403  if (singleShot) dwr.engine.endBatch();
404};
405
406/** @private Poll the server to see if there is any data waiting */
407dwr.engine._poll = function() {
408  if (!dwr.engine._activeReverseAjax) return;
409
410  var batch = dwr.engine._createBatch();
411  batch.map.id = 0; // TODO: Do we need this??
412  batch.map.callCount = 1;
413  batch.isPoll = true;
414  if (dwr.engine._pollWithXhr == "true") {
415    batch.rpcType = dwr.engine.XMLHttpRequest;
416    batch.map.partialResponse = dwr.engine._partialResponseNo;
417  }
418  else {
419    if (navigator.userAgent.indexOf("Gecko/") != -1) {
420      batch.rpcType = dwr.engine.XMLHttpRequest;
421      batch.map.partialResponse = dwr.engine._partialResponseYes;
422    }
423    else {
424      batch.rpcType = dwr.engine.XMLHttpRequest;
425      batch.map.partialResponse = dwr.engine._partialResponseNo;
426    }
427  }
428  batch.httpMethod = "POST";
429  batch.async = true;
430  batch.timeout = 0;
431  batch.path = dwr.engine._defaultPath;
432  batch.preHooks = [];
433  batch.postHooks = [];
434  batch.errorHandler = dwr.engine._pollErrorHandler;
435  batch.warningHandler = dwr.engine._pollErrorHandler;
436  batch.handlers[0] = {
437    callback:function(pause) {
438      dwr.engine._pollRetries = 0;
439      setTimeout(dwr.engine._poll, pause);
440    }
441  };
442
443  // Send the data
444  dwr.engine._sendData(batch);
445  if (batch.rpcType == dwr.engine.XMLHttpRequest && batch.map.partialResponse == dwr.engine._partialResponseYes) {
446    dwr.engine._checkCometPoll();
447  }
448};
449
450/** Try to recover from polling errors */
451dwr.engine._pollErrorHandler = function(msg, ex) {
452  // if anything goes wrong then just silently try again (up to 3x) after 10s
453  dwr.engine._pollRetries++;
454  dwr.engine._debug("Reverse Ajax poll failed (pollRetries=" + dwr.engine._pollRetries + "): " + ex.name + " : " + ex.message);
455  if (dwr.engine._pollRetries < dwr.engine._maxPollRetries) {
456    setTimeout(dwr.engine._poll, 10000);
457  }
458  else {
459    dwr.engine._activeReverseAjax = false;
460    dwr.engine._debug("Giving up.");
461  }
462};
463
464/** @private Generate a new standard batch */
465dwr.engine._createBatch = function() {
466  var batch = {
467    map:{
468      callCount:0,
469      page:window.location.pathname + window.location.search,
470      httpSessionId:dwr.engine._getJSessionId(),
471      scriptSessionId:dwr.engine._getScriptSessionId()
472    },
473    charsProcessed:0, paramCount:0,
474    parameters:{}, headers:{},
475    isPoll:false, handlers:{}, preHooks:[], postHooks:[],
476    rpcType:dwr.engine._rpcType,
477    httpMethod:dwr.engine._httpMethod,
478    async:dwr.engine._async,
479    timeout:dwr.engine._timeout,
480    errorHandler:dwr.engine._errorHandler,
481    warningHandler:dwr.engine._warningHandler,
482    textHtmlHandler:dwr.engine._textHtmlHandler
483  };
484  if (dwr.engine._preHook) batch.preHooks.push(dwr.engine._preHook);
485  if (dwr.engine._postHook) batch.postHooks.push(dwr.engine._postHook);
486  var propname, data;
487  if (dwr.engine._headers) {
488    for (propname in dwr.engine._headers) {
489      data = dwr.engine._headers[propname];
490      if (typeof data != "function") batch.headers[propname] = data;
491    }
492  }
493  if (dwr.engine._parameters) {
494    for (propname in dwr.engine._parameters) {
495      data = dwr.engine._parameters[propname];
496      if (typeof data != "function") batch.parameters[propname] = data;
497    }
498  }
499  return batch;
500};
501
502/** @private Take further options and merge them into */
503dwr.engine._mergeBatch = function(batch, overrides) {
504  var propname, data;
505  for (var i = 0; i < dwr.engine._propnames.length; i++) {
506    propname = dwr.engine._propnames[i];
507    if (overrides[propname] != null) batch[propname] = overrides[propname];
508  }
509  if (overrides.preHook != null) batch.preHooks.unshift(overrides.preHook);
510  if (overrides.postHook != null) batch.postHooks.push(overrides.postHook);
511  if (overrides.headers) {
512    for (propname in overrides.headers) {
513      data = overrides.headers[propname];
514      if (typeof data != "function") batch.headers[propname] = data;
515    }
516  }
517  if (overrides.parameters) {
518    for (propname in overrides.parameters) {
519      data = overrides.parameters[propname];
520      if (typeof data != "function") batch.map["p-" + propname] = "" + data;
521    }
522  }
523};
524
525/** @private What is our session id? */
526dwr.engine._getJSessionId =  function() {
527  var cookies = document.cookie.split(';');
528  for (var i = 0; i < cookies.length; i++) {
529    var cookie = cookies[i];
530    while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
531    if (cookie.indexOf(dwr.engine._sessionCookieName + "=") == 0) {
532      return cookie.substring(dwr.engine._sessionCookieName.length + 1, cookie.length);
533    }
534  }
535  return "";
536};
537
538/** @private Check for reverse Ajax activity */
539dwr.engine._checkCometPoll = function() {
540  for (var i = 0; i < dwr.engine._outstandingIFrames.length; i++) {
541    var text = "";
542    var iframe = dwr.engine._outstandingIFrames[i];
543    try {
544      text = dwr.engine._getTextFromCometIFrame(iframe);
545    }
546    catch (ex) {
547      dwr.engine._handleWarning(iframe.batch, ex);
548    }
549    if (text != "") dwr.engine._processCometResponse(text, iframe.batch);
550  }
551  if (dwr.engine._pollReq) {
552    var req = dwr.engine._pollReq;
553    var text = req.responseText;
554    if (text != null) dwr.engine._processCometResponse(text, req.batch);
555  }
556
557  // If the poll resources are still there, come back again
558  if (dwr.engine._outstandingIFrames.length > 0 || dwr.engine._pollReq) {
559    setTimeout(dwr.engine._checkCometPoll, dwr.engine._pollCometInterval);
560  }
561};
562
563/** @private Extract the whole (executed an all) text from the current iframe */
564dwr.engine._getTextFromCometIFrame = function(frameEle) {
565  var body = frameEle.contentWindow.document.body;
566  if (body == null) return "";
567  var text = body.innerHTML;
568  // We need to prevent IE from stripping line feeds
569  if (text.indexOf("<PRE>") == 0 || text.indexOf("<pre>") == 0) {
570    text = text.substring(5, text.length - 7);
571  }
572  return text;
573};
574
575/** @private Some more text might have come in, test and execute the new stuff */
576dwr.engine._processCometResponse = function(response, batch) {
577  if (batch.charsProcessed == response.length) return;
578  if (response.length == 0) {
579    batch.charsProcessed = 0;
580    return;
581  }
582
583  var firstStartTag = response.indexOf("//#DWR-START#", batch.charsProcessed);
584  if (firstStartTag == -1) {
585    // dwr.engine._debug("No start tag (search from " + batch.charsProcessed + "). skipping '" + response.substring(batch.charsProcessed) + "'");
586    batch.charsProcessed = response.length;
587    return;
588  }
589  // if (firstStartTag > 0) {
590  //   dwr.engine._debug("Start tag not at start (search from " + batch.charsProcessed + "). skipping '" + response.substring(batch.charsProcessed, firstStartTag) + "'");
591  // }
592
593  var lastEndTag = response.lastIndexOf("//#DWR-END#");
594  if (lastEndTag == -1) {
595    // dwr.engine._debug("No end tag. unchanged charsProcessed=" + batch.charsProcessed);
596    return;
597  }
598
599  // Skip the end tag too for next time, remembering CR and LF
600  if (response.charCodeAt(lastEndTag + 11) == 13 && response.charCodeAt(lastEndTag + 12) == 10) {
601    batch.charsProcessed = lastEndTag + 13;
602  }
603  else {
604    batch.charsProcessed = lastEndTag + 11;
605  }
606
607  var exec = response.substring(firstStartTag + 13, lastEndTag);
608
609  dwr.engine._receivedBatch = batch;
610  dwr.engine._eval(exec);
611  dwr.engine._receivedBatch = null;
612};
613
614/** @private Actually send the block of data in the batch object. */
615dwr.engine._sendData = function(batch) {
616  batch.map.batchId = dwr.engine._nextBatchId;
617  dwr.engine._nextBatchId++;
618  dwr.engine._batches[batch.map.batchId] = batch;
619  dwr.engine._batchesLength++;
620  batch.completed = false;
621
622  for (var i = 0; i < batch.preHooks.length; i++) {
623    batch.preHooks[i]();
624  }
625  batch.preHooks = null;
626  // Set a timeout
627  if (batch.timeout && batch.timeout != 0) {
628    batch.timeoutId = setTimeout(function() { dwr.engine._abortRequest(batch); }, batch.timeout);
629  }
630  // Get setup for XMLHttpRequest if possible
631  if (batch.rpcType == dwr.engine.XMLHttpRequest) {
632    if (window.XMLHttpRequest) {
633      batch.req = new XMLHttpRequest();
634    }
635    // IE5 for the mac claims to support window.ActiveXObject, but throws an error when it's used
636    else if (window.ActiveXObject && !(navigator.userAgent.indexOf("Mac") >= 0 && navigator.userAgent.indexOf("MSIE") >= 0)) {
637      batch.req = dwr.engine._newActiveXObject(dwr.engine._XMLHTTP);
638    }
639  }
640
641  var prop, request;
642  if (batch.req) {
643    // Proceed using XMLHttpRequest
644    if (batch.async) {
645      batch.req.onreadystatechange = function() {
646        if (typeof dwr != 'undefined') dwr.engine._stateChange(batch);
647      };
648    }
649    // If we're polling, record this for monitoring
650    if (batch.isPoll) {
651      dwr.engine._pollReq = batch.req;
652      // In IE XHR is an ActiveX control so you can't augment it like this
653      if (!(document.all && !window.opera)) batch.req.batch = batch;
654    }
655    // Workaround for Safari 1.x POST bug
656    var indexSafari = navigator.userAgent.indexOf("Safari/");
657    if (indexSafari >= 0) {
658      var version = navigator.userAgent.substring(indexSafari + 7);
659      if (parseInt(version, 10) < 400) {
660        if (dwr.engine._allowGetForSafariButMakeForgeryEasier == "true") batch.httpMethod = "GET";
661        else dwr.engine._handleWarning(batch, { name:"dwr.engine.oldSafari", message:"Safari GET support disabled. See getahead.org/dwr/server/servlet and allowGetForSafariButMakeForgeryEasier." });
662      }
663    }
664    batch.mode = batch.isPoll ? dwr.engine._ModePlainPoll : dwr.engine._ModePlainCall;
665    request = dwr.engine._constructRequest(batch);
666    try {
667      batch.req.open(batch.httpMethod, request.url, batch.async);
668      try {
669        for (prop in batch.headers) {
670          var value = batch.headers[prop];
671          if (typeof value == "string") batch.req.setRequestHeader(prop, value);
672        }
673        if (!batch.headers["Content-Type"]) batch.req.setRequestHeader("Content-Type", "text/plain");
674      }
675      catch (ex) {
676        dwr.engine._handleWarning(batch, ex);
677      }
678      batch.req.send(request.body);
679      if (!batch.async) dwr.engine._stateChange(batch);
680    }
681    catch (ex) {
682      dwr.engine._handleError(batch, ex);
683    }
684  }
685  else if (batch.rpcType != dwr.engine.ScriptTag) {
686    var idname = batch.isPoll ? "dwr-if-poll-" + batch.map.batchId : "dwr-if-" + batch.map.batchId;
687    // Removed htmlfile implementation. Don't expect it to return before v3
688    batch.div = document.createElement("div");
689    // Add the div to the document first, otherwise IE 6 will ignore onload handler.
690    document.body.appendChild(batch.div);
691    batch.div.innerHTML = "<iframe src='javascript:void(0)' frameborder='0' style='width:0px;height:0px;border:0;' id='" + idname + "' name='" + idname + "' onload='dwr.engine._iframeLoadingComplete (" + batch.map.batchId + ");'></iframe>";
692    batch.document = document;
693    batch.iframe = batch.document.getElementById(idname);
694    batch.iframe.batch = batch;
695    batch.mode = batch.isPoll ? dwr.engine._ModeHtmlPoll : dwr.engine._ModeHtmlCall;
696    if (batch.isPoll) dwr.engine._outstandingIFrames.push(batch.iframe);
697    request = dwr.engine._constructRequest(batch);
698    if (batch.httpMethod == "GET") {
699      batch.iframe.setAttribute("src", request.url);
700    }
701    else {
702      batch.form = batch.document.createElement("form");
703      batch.form.setAttribute("id", "dwr-form");
704      batch.form.setAttribute("action", request.url);
705      batch.form.setAttribute("style", "display:none;");
706      batch.form.setAttribute("target", idname);
707      batch.form.target = idname;
708      batch.form.setAttribute("method", batch.httpMethod);
709      for (prop in batch.map) {
710        var value = batch.map[prop];
711        if (typeof value != "function") {
712          var formInput = batch.document.createElement("input");
713          formInput.setAttribute("type", "hidden");
714          formInput.setAttribute("name", prop);
715          formInput.setAttribute("value", value);
716          batch.form.appendChild(formInput);
717        }
718      }
719      batch.document.body.appendChild(batch.form);
720      batch.form.submit();
721    }
722  }
723  else {
724    batch.httpMethod = "GET"; // There's no such thing as ScriptTag using POST
725    batch.mode = batch.isPoll ? dwr.engine._ModePlainPoll : dwr.engine._ModePlainCall;
726    request = dwr.engine._constructRequest(batch);
727    batch.script = document.createElement("script");
728    batch.script.id = "dwr-st-" + batch.map["c0-id"];
729    batch.script.src = request.url;
730    document.body.appendChild(batch.script);
731  }
732};
733
734dwr.engine._ModePlainCall = "/call/plaincall/";
735dwr.engine._ModeHtmlCall = "/call/htmlcall/";
736dwr.engine._ModePlainPoll = "/call/plainpoll/";
737dwr.engine._ModeHtmlPoll = "/call/htmlpoll/";
738
739/** @private Work out what the URL should look like */
740dwr.engine._constructRequest = function(batch) {
741  // A quick string to help people that use web log analysers
742  var request = { url:batch.path + batch.mode, body:null };
743  if (batch.isPoll == true) {
744    request.url += "ReverseAjax.dwr";
745  }
746  else if (batch.map.callCount == 1) {
747    request.url += batch.map["c0-scriptName"] + "." + batch.map["c0-methodName"] + ".dwr";
748  }
749  else {
750    request.url += "Multiple." + batch.map.callCount + ".dwr";
751  }
752  // Play nice with url re-writing
753  var sessionMatch = location.href.match(/jsessionid=([^?]+)/);
754  if (sessionMatch != null) {
755    request.url += ";jsessionid=" + sessionMatch[1];
756  }
757
758  var prop;
759  if (batch.httpMethod == "GET") {
760    // Some browsers (Opera/Safari2) seem to fail to convert the callCount value
761    // to a string in the loop below so we do it manually here.
762    batch.map.callCount = "" + batch.map.callCount;
763    request.url += "?";
764    for (prop in batch.map) {
765      if (typeof batch.map[prop] != "function") {
766        request.url += encodeURIComponent(prop) + "=" + encodeURIComponent(batch.map[prop]) + "&";
767      }
768    }
769    request.url = request.url.substring(0, request.url.length - 1);
770  }
771  else {
772    // PERFORMANCE: for iframe mode this is thrown away.
773    request.body = "";
774    if (document.all && !window.opera) {
775      // Use array joining on IE (fastest)
776      var buf = [];
777      for (prop in batch.map) {
778        if (typeof batch.map[prop] != "function") {
779          buf.push(prop + "=" + batch.map[prop] + dwr.engine._postSeperator);
780        }
781      }
782      request.body = buf.join("");
783    }
784    else {
785      // Use string concat on other browsers (fastest)
786      for (prop in batch.map) {
787        if (typeof batch.map[prop] != "function") {
788          request.body += prop + "=" + batch.map[prop] + dwr.engine._postSeperator;
789        }
790      }
791    }
792    request.body = dwr.engine._contentRewriteHandler(request.body);
793  }
794  request.url = dwr.engine._urlRewriteHandler(request.url);
795  return request;
796};
797
798/** @private Called by XMLHttpRequest to indicate that something has happened */
799dwr.engine._stateChange = function(batch) {
800  var toEval;
801
802  if (batch.completed) {
803    dwr.engine._debug("Error: _stateChange() with batch.completed");
804    return;
805  }
806
807  var req = batch.req;
808  try {
809    if (req.readyState != 4) return;
810  }
811  catch (ex) {
812    dwr.engine._handleWarning(batch, ex);
813    // It's broken - clear up and forget this call
814    dwr.engine._clearUp(batch);
815    return;
816  }
817
818  if (dwr.engine._unloading) {
819    dwr.engine._debug("Ignoring reply from server as page is unloading.");
820    return;
821  }
822  
823  try {
824    var reply = req.responseText;
825    reply = dwr.engine._replyRewriteHandler(reply);
826    var status = req.status; // causes Mozilla to except on page moves
827
828    if (reply == null || reply == "") {
829      dwr.engine._handleWarning(batch, { name:"dwr.engine.missingData", message:"No data received from server" });
830    }
831    else if (status != 200) {
832      dwr.engine._handleError(batch, { name:"dwr.engine.http." + status, message:req.statusText });
833    }
834    else {
835      var contentType = req.getResponseHeader("Content-Type");
836      if (!contentType.match(/^text\/plain/) && !contentType.match(/^text\/javascript/)) {
837        if (contentType.match(/^text\/html/) && typeof batch.textHtmlHandler == "function") {
838          batch.textHtmlHandler({ status:status, responseText:reply, contentType:contentType });
839        }
840        else {
841          dwr.engine._handleWarning(batch, { name:"dwr.engine.invalidMimeType", message:"Invalid content type: '" + contentType + "'" });
842        }
843      }
844      else {
845        // Comet replies might have already partially executed
846        if (batch.isPoll && batch.map.partialResponse == dwr.engine._partialResponseYes) {
847          dwr.engine._processCometResponse(reply, batch);
848        }
849        else {
850          if (reply.search("//#DWR") == -1) {
851            dwr.engine._handleWarning(batch, { name:"dwr.engine.invalidReply", message:"Invalid reply from server" });
852          }
853          else {
854            toEval = reply;
855          }
856        }
857      }
858    }
859  }
860  catch (ex) {
861    dwr.engine._handleWarning(batch, ex);
862  }
863
864  dwr.engine._callPostHooks(batch);
865
866  // Outside of the try/catch so errors propogate normally:
867  dwr.engine._receivedBatch = batch;
868  if (toEval != null) toEval = toEval.replace(dwr.engine._scriptTagProtection, "");
869  dwr.engine._eval(toEval);
870  dwr.engine._receivedBatch = null;
871  dwr.engine._validateBatch(batch);
872  if (!batch.completed) dwr.engine._clearUp(batch);
873};
874
875/**
876 * @private This function is invoked when a batch reply is received.
877 * It checks that there is a response for every call in the batch. Otherwise,
878 * an error will be signaled (a call without a response indicates that the 
879 * server failed to send complete batch response). 
880 */
881dwr.engine._validateBatch = function(batch) {
882  // If some call left unreplied, report an error.
883  if (!batch.completed) {
884    for (var i = 0; i < batch.map.callCount; i++) {
885      if (batch.handlers[i] != null) {
886        dwr.engine._handleWarning(batch, { name:"dwr.engine.incompleteReply", message:"Incomplete reply from server" });
887        break;
888      }
889    }
890  }
891}
892
893/** @private Called from iframe onload, check batch using batch-id */
894dwr.engine._iframeLoadingComplete = function(batchId) {
895  // dwr.engine._checkCometPoll();
896  var batch = dwr.engine._batches[batchId];
897  if (batch) dwr.engine._validateBatch(batch);
898}
899
900/** @private Called by the server: Execute a callback */
901dwr.engine._remoteHandleCallback = function(batchId, callId, reply) {
902  var batch = dwr.engine._batches[batchId];
903  if (batch == null) {
904    dwr.engine._debug("Warning: batch == null in remoteHandleCallback for batchId=" + batchId, true);
905    return;
906  }
907  // Error handlers inside here indicate an error that is nothing to do
908  // with DWR so we handle them differently.
909  try {
910    var handlers = batch.handlers[callId];
911    batch.handlers[callId] = null;
912    if (!handlers) {
913      dwr.engine._debug("Warning: Missing handlers. callId=" + callId, true);
914    }
915    else if (typeof handlers.callback == "function") handlers.callback(reply);
916  }
917  catch (ex) {
918    dwr.engine._handleError(batch, ex);
919  }
920};
921
922/** @private Called by the server: Handle an exception for a call */
923dwr.engine._remoteHandleException = function(batchId, callId, ex) {
924  var batch = dwr.engine._batches[batchId];
925  if (batch == null) { dwr.engine._debug("Warning: null batch in remoteHandleException", true); return; }
926  var handlers = batch.handlers[callId];
927  batch.handlers[callId] = null;
928  if (handlers == null) { dwr.engine._debug("Warning: null handlers in remoteHandleException", true); return; }
929  if (ex.message == undefined) ex.message = "";
930  if (typeof handlers.exceptionHandler == "function") handlers.exceptionHandler(ex.message, ex);
931  else if (typeof batch.errorHandler == "function") batch.errorHandler(ex.message, ex);
932};
933
934/** @private Called by the server: The whole batch is broken */
935dwr.engine._remoteHandleBatchException = function(ex, batchId) {
936  var searchBatch = (dwr.engine._receivedBatch == null && batchId != null);
937  if (searchBatch) {
938    dwr.engine._receivedBatch = dwr.engine._batches[batchId];
939  }
940  if (ex.message == undefined) ex.message = "";
941  dwr.engine._handleError(dwr.engine._receivedBatch, ex);
942  if (searchBatch) {
943    dwr.engine._receivedBatch = null;
944    dwr.engine._clearUp(dwr.engine._batches[batchId]);
945  }
946};
947
948/** @private Called by the server: Reverse ajax should not be used */
949dwr.engine._remotePollCometDisabled = function(ex, batchId) {
950  dwr.engine.setActiveReverseAjax(false);
951  var searchBatch = (dwr.engine._receivedBatch == null && batchId != null);
952  if (searchBatch) {
953    dwr.engine._receivedBatch = dwr.engine._batches[batchId];
954  }
955  if (ex.message == undefined) ex.message = "";
956  dwr.engine._handleError(dwr.engine._receivedBatch, ex);
957  if (searchBatch) {
958    dwr.engine._receivedBatch = null;
959    dwr.engine._clearUp(dwr.engine._batches[batchId]);
960  }
961};
962
963/** @private Called by the server: An IFrame reply is about to start */
964dwr.engine._remoteBeginIFrameResponse = function(iframe, batchId) {
965  if (iframe != null) dwr.engine._receivedBatch = iframe.batch;
966  dwr.engine._callPostHooks(dwr.engine._receivedBatch);
967};
968
969/** @private Called by the server: An IFrame reply is just completing */
970dwr.engine._remoteEndIFrameResponse = function(batchId) {
971  dwr.engine._clearUp(dwr.engine._receivedBatch);
972  dwr.engine._receivedBatch = null;
973};
974
975/** @private This is a hack to make the context be this window */
976dwr.engine._eval = function(script) {
977  if (script == null) return null;
978  if (script == "") { dwr.engine._debug("Warning: blank script", true); return null; }
979  // dwr.engine._debug("Exec: [" + script + "]", true);
980  return eval(script);
981};
982
983/** @private Called as a result of a request timeout */
984dwr.engine._abortRequest = function(batch) {
985  if (batch && !batch.completed) {
986    dwr.engine._clearUp(batch);
987    if (batch.req) batch.req.abort();
988    dwr.engine._handleError(batch, { name:"dwr.engine.timeout", message:"Timeout" });
989  }
990};
991
992/** @private call all the post hooks for a batch */
993dwr.engine._callPostHooks = function(batch) {
994  if (batch.postHooks) {
995    for (var i = 0; i < batch.postHooks.length; i++) {
996      batch.postHooks[i]();
997    }
998    batch.postHooks = null;
999  }
1000};
1001
1002/** @private A call has finished by whatever means and we need to shut it all down. */
1003dwr.engine._clearUp = function(batch) {
1004  if (!batch) { dwr.engine._debug("Warning: null batch in dwr.engine._clearUp()", true); return; }
1005  if (batch.completed) { dwr.engine._debug("Warning: Double complete", true); return; }
1006
1007  // IFrame tidyup
1008  if (batch.div) batch.div.parentNode.removeChild(batch.div);
1009  if (batch.iframe) {
1010    // If this is a poll frame then stop comet polling
1011    for (var i = 0; i < dwr.engine._outstandingIFrames.length; i++) {
1012      if (dwr.engine._outstandingIFrames[i] == batch.iframe) {
1013        dwr.engine._outstandingIFrames.splice(i, 1);
1014      }
1015    }
1016    batch.iframe.parentNode.removeChild(batch.iframe);
1017  }
1018  if (batch.form) batch.form.parentNode.removeChild(batch.form);
1019
1020  // XHR tidyup: avoid IE handles increase
1021  if (batch.req) {
1022    // If this is a poll frame then stop comet polling
1023    if (batch.req == dwr.engine._pollReq) dwr.engine._pollReq = null;
1024    delete batch.req;
1025  }
1026
1027  // Timeout tidyup
1028  if (batch.timeoutId != null) {
1029    clearTimeout(batch.timeoutId);
1030    delete batch.timeoutId;
1031  }
1032
1033  if (batch.map && (batch.map.batchId || batch.map.batchId == 0)
1033) {
1034    delete dwr.engine._batches[batch.map.batchId];
1035    dwr.engine._batchesLength--;
1036  }
1037
1038  batch.completed = true;
1039
1040  // If there is anything on the queue waiting to go out, then send it.
1041  // We don't need to check for ordered mode, here because when ordered mode
1042  // gets turned off, we still process *waiting* batches in an ordered way.
1043  if (dwr.engine._batchQueue.length != 0) {
1044    var sendbatch = dwr.engine._batchQueue.shift();
1045    dwr.engine._sendData(sendbatch);
1046  }
1047};
1048
1049/** @private Abort any XHRs in progress at page unload (solves zombie socket problems in IE). */
1050dwr.engine._unloader = function() {
1051  dwr.engine._unloading = true;
1052
1053  // Empty queue of waiting ordered requests
1054  dwr.engine._batchQueue.length = 0;
1055
1056  // Abort any ongoing XHRs and clear their batches
1057  for (var batchId in dwr.engine._batches) {
1058    var batch = dwr.engine._batches[batchId];
1059    // Only process objects that look like batches (avoid prototype additions!)
1060    if (batch && batch.map) {
1061      if (batch.req) {
1062        batch.req.abort();
1063      }
1064      dwr.engine._clearUp(batch);
1065    }
1066  }
1067};
1068// Now register the unload handler
1069if (window.addEventListener) window.addEventListener('unload', dwr.engine._unloader, false);
1070else if (window.attachEvent) window.attachEvent('onunload', dwr.engine._unloader);
1071
1072/** @private Generic error handling routing to save having null checks everywhere */
1073dwr.engine._handleError = function(batch, ex) {
1074  if (typeof ex == "string") ex = { name:"unknown", message:ex };
1075  if (ex.message == null) ex.message = "";
1076  if (ex.name == null) ex.name = "unknown";
1077  if (batch && typeof batch.errorHandler == "function") batch.errorHandler(ex.message, ex);
1078  else if (dwr.engine._errorHandler) dwr.engine._errorHandler(ex.message, ex);
1079  if (batch) dwr.engine._clearUp(batch);
1080};
1081
1082/** @private Generic error handling routing to save having null checks everywhere */
1083dwr.engine._handleWarning = function(batch, ex) {
1084  if (typeof ex == "string") ex = { name:"unknown", message:ex };
1085  if (ex.message == null) ex.message = "";
1086  if (ex.name == null) ex.name = "unknown";
1087  if (batch && typeof batch.warningHandler == "function") batch.warningHandler(ex.message, ex);
1088  else if (dwr.engine._warningHandler) dwr.engine._warningHandler(ex.message, ex);
1089  if (batch) dwr.engine._clearUp(batch);
1090};
1091
1092/**
1093 * @private Marshall a data item
1094 * @param batch A map of variables to how they have been marshalled
1095 * @param referto An array of already marshalled variables to prevent recurrsion
1096 * @param data The data to be marshalled
1097 * @param name The name of the data being marshalled
1098 */
1099dwr.engine._serializeAll = function(batch, referto, data, name) {
1100  if (data == null) {
1101    batch.map[name] = "null:null";
1102    return;
1103  }
1104
1105  switch (typeof data) {
1106  case "boolean":
1107    batch.map[name] = "boolean:" + data;
1108    break;
1109  case "number":
1110    batch.map[name] = "number:" + data;
1111    break;
1112  case "string":
1113    batch.map[name] = "string:" + encodeURIComponent(data);
1114    break;
1115  case "object":
1116    var objstr = Object.prototype.toString.call(data);
1117    if (objstr == "[object String]") batch.map[name] = "String:" + encodeURIComponent(data);
1118    else if (objstr == "[object Boolean]") batch.map[name] = "Boolean:" + data;
1119    else if (objstr == "[object Number]") batch.map[name] = "Number:" + data;
1120    else if (objstr == "[object Date]") batch.map[name] = "Date:" + data.getTime();
1121    else if (objstr == "[object Array]") batch.map[name] = dwr.engine._serializeArray(batch, referto, data, name);
1122    else batch.map[name] = dwr.engine._serializeObject(batch, referto, data, name);
1123    break;
1124  case "function":
1125    // We just ignore functions.
1126    break;
1127  default:
1128    dwr.engine._handleWarning(null, { name:"dwr.engine.unexpectedType", message:"Unexpected type: " + typeof data + ", attempting default converter." });
1129    batch.map[name] = "default:" + data;
1130    break;
1131  }
1132};
1133
1134/** @private Have we already converted this object? */
1135dwr.engine._lookup = function(referto, data, name) {
1136  var lookup;
1137  // Can't use a map: getahead.org/ajax/javascript-gotchas
1138  for (var i = 0; i < referto.length; i++) {
1139    if (referto[i].data == data) {
1140      lookup = referto[i];
1141      break;
1142    }
1143  }
1144  if (lookup) return "reference:" + lookup.name;
1145  referto.push({ data:data, name:name });
1146  return null;
1147};
1148
1149/** @private Marshall an object */
1150dwr.engine._serializeObject = function(batch, referto, data, name) {
1151  var ref = dwr.engine._lookup(referto, data, name);
1152  if (ref) return ref;
1153
1154  // This check for an HTML is not complete, but is there a better way?
1155  // Maybe we should add: data.hasChildNodes typeof "function" == true
1156  if (data.nodeName && data.nodeType) {
1157    return dwr.engine._serializeXml(batch, referto, data, name);
1158  }
1159
1160  // treat objects as an associative arrays
1161  var reply = "Object_" + dwr.engine._getObjectClassName(data) + ":{";
1162  var element;
1163  for (element in data) {
1164    if (typeof data[element] != "function") {
1165      batch.paramCount++;
1166      var childName = "c" + dwr.engine._batch.map.callCount + "-e" + batch.paramCount;
1167      dwr.engine._serializeAll(batch, referto, data[element], childName);
1168
1169      reply += encodeURIComponent(element) + ":reference:" + childName + ", ";
1170    }
1171  }
1172
1173  if (reply.substring(reply.length - 2) == ", ") {
1174    reply = reply.substring(0, reply.length - 2);
1175  }
1176  reply += "}";
1177
1178  return reply;
1179};
1180
1181/** @private Returns the classname of supplied argument obj */
1182dwr.engine._errorClasses = { "Error":Error, "EvalError":EvalError, "RangeError":RangeError, "ReferenceError":ReferenceError, "SyntaxError":SyntaxError, "TypeError":TypeError, "URIError":URIError };
1183dwr.engine._getObjectClassName = function(obj) {
1184  // Try to find the classname by stringifying the object's constructor
1185  // and extract <class> from "function <class>".
1186  if (obj && obj.constructor && obj.constructor.toString)
1187  {
1188    var str = obj.constructor.toString();
1189    var regexpmatch = str.match(/function\s+(\w+)/);
1190    if (regexpmatch && regexpmatch.length == 2) {
1191      return regexpmatch[1];
1192    }
1193  }
1194
1195  // Now manually test against the core Error classes, as these in some 
1196  // browsers successfully match to the wrong class in the 
1197  // Object.toString() test we will do later
1198  if (obj && obj.constructor) {
1199    for (var errorname in dwr.engine._errorClasses) {
1200      if (obj.constructor == dwr.engine._errorClasses[errorname]) return errorname;
1201    }
1202  }
1203
1204  // Try to find the classname by calling Object.toString() on the object
1205  // and extracting <class> from "[object <class>]"
1206  if (obj) {
1207    var str = Object.prototype.toString.call(obj);
1208    var regexpmatch = str.match(/\[object\s+(\w+)/);
1209    if (regexpmatch && regexpmatch.length==2) {
1210      return regexpmatch[1];
1211    }
1212  }
1213
1214  // Supplied argument was probably not an object, but what is better?
1215  return "Object";
1216};
1217
1218/** @private Marshall an object */
1219dwr.engine._serializeXml = function(batch, referto, data, name) {
1220  var ref = dwr.engine._lookup(referto, data, name);
1221  if (ref) return ref;
1222
1223  var output;
1224  if (window.XMLSerializer) output = new XMLSerializer().serializeToString(data);
1225  else if (data.toXml) output = data.toXml;
1226  else output = data.innerHTML;
1227
1228  return "XML:" + encodeURIComponent(output);
1229};
1230
1231/** @private Marshall an array */
1232dwr.engine._serializeArray = function(batch, referto, data, name) {
1233  var ref = dwr.engine._lookup(referto, data, name);
1234  if (ref) return ref;
1235
1236  if (document.all && !window.opera) {
1237    // Use array joining on IE (fastest)
1238    var buf = ["Array:["];
1239    for (var i = 0; i < data.length; i++) {
1240      if (i != 0) buf.push(",");
1241      batch.paramCount++;
1242      var childName = "c" + dwr.engine._batch.map.callCount + "-e" + batch.paramCount;
1243      dwr.engine._serializeAll(batch, referto, data[i], childName);
1244      buf.push("reference:");
1245      buf.push(childName);
1246    }
1247    buf.push("]");
1248    reply = buf.join("");
1249  }
1250  else {
1251    // Use string concat on other browsers (fastest)
1252    var reply = "Array:[";
1253    for (var i = 0; i < data.length; i++) {
1254      if (i != 0) reply += ",";
1255      batch.paramCount++;
1256      var childName = "c" + dwr.engine._batch.map.callCount + "-e" + batch.paramCount;
1257      dwr.engine._serializeAll(batch, referto, data[i], childName);
1258      reply += "reference:";
1259      reply += childName;
1260    }
1261    reply += "]";
1262  }
1263
1264  return reply;
1265};
1266
1267/** @private Convert an XML string into a DOM object. */
1268dwr.engine._unserializeDocument = function(xml) {
1269  var dom;
1270  if (window.DOMParser) {
1271    var parser = new DOMParser();
1272    dom = parser.parseFromString(xml, "text/xml");
1273    if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
1274      var message = dom.documentElement.firstChild.data;
1275      message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
1276      throw message;
1277    }
1278    return dom;
1279  }
1280  else if (window.ActiveXObject) {
1281    dom = dwr.engine._newActiveXObject(dwr.engine._DOMDocument);
1282    dom.loadXML(xml); // What happens on parse fail with IE?
1283    return dom;
1284  }
1285  else {
1286    var div = document.createElement("div");
1287    div.innerHTML = xml;
1288    return div;
1289  }
1290};
1291
1292/** @param axarray An array of strings to attempt to create ActiveX objects from */
1293dwr.engine._newActiveXObject = function(axarray) {
1294  var returnValue;  
1295  for (var i = 0; i < axarray.length; i++) {
1296    try {
1297      returnValue = new ActiveXObject(axarray[i]);
1298      break;
1299    }
1300    catch (ex) { /* ignore */ }
1301  }
1302  return returnValue;
1303};
1304
1305/** @private Used internally when some message needs to get to the programmer */
1306dwr.engine._debug = function(message, stacktrace) {
1307  var written = false;
1308  try {
1309    if (window.console) {
1310      if (stacktrace && window.console.trace) window.console.trace();
1311      window.console.log(message);
1312      written = true;
1313    }
1314    else if (window.opera && window.opera.postError) {
1315      window.opera.postError(message);
1316      written = true;
1317    }
1318  }
1319  catch (ex) { /* ignore */ }
1320
1321  if (!written) {
1322    var debug = document.getElementById("dwr-debug");
1323    if (debug) {
1324      var contents = message + "<br/>" + debug.innerHTML;
1325      if (contents.length > 2048) contents = contents.substring(0, 2048);
1326      debug.innerHTML = contents;
1327    }
1328  }
1329};
1330

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.