You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by he...@apache.org on 2006/11/13 23:55:14 UTC
svn commit: r474551 [21/49] - in
/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo:
./ src/ src/alg/ src/animation/ src/cal/ src/charting/ src/charting/svg/
src/charting/vml/ src/collections/ src/crypto/ src/data/ src/data/cs...
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -8,310 +8,7 @@
http://dojotoolkit.org/community/licensing.shtml
*/
-dojo.provide("dojo.io.IO");
-dojo.require("dojo.string");
+dojo.provide("dojo.io");
-/******************************************************************************
- * Notes about dojo.io design:
- *
- * The dojo.io.* package has the unenviable task of making a lot of different
- * types of I/O feel natural, despite a universal lack of good (or even
- * reasonable!) I/O capability in the host environment. So lets pin this down
- * a little bit further.
- *
- * Rhino:
- * perhaps the best situation anywhere. Access to Java classes allows you
- * to do anything one might want in terms of I/O, both synchronously and
- * async. Can open TCP sockets and perform low-latency client/server
- * interactions. HTTP transport is available through Java HTTP client and
- * server classes. Wish it were always this easy.
- *
- * xpcshell:
- * XPCOM for I/O. A cluster-fuck to be sure.
- *
- * spidermonkey:
- * S.O.L.
- *
- * Browsers:
- * Browsers generally do not provide any useable filesystem access. We are
- * therefore limited to HTTP for moving information to and from Dojo
- * instances living in a browser.
- *
- * XMLHTTP:
- * Sync or async, allows reading of arbitrary text files (including
- * JS, which can then be eval()'d), writing requires server
- * cooperation and is limited to HTTP mechanisms (POST and GET).
- *
- * <iframe> hacks:
- * iframe document hacks allow browsers to communicate asynchronously
- * with a server via HTTP POST and GET operations. With significant
- * effort and server cooperation, low-latency data transit between
- * client and server can be acheived via iframe mechanisms (repubsub).
- *
- * SVG:
- * Adobe's SVG viewer implements helpful primitives for XML-based
- * requests, but receipt of arbitrary text data seems unlikely w/o
- * <![CDATA[]]> sections.
- *
- *
- * A discussion between Dylan, Mark, Tom, and Alex helped to lay down a lot
- * the IO API interface. A transcript of it can be found at:
- * http://dojotoolkit.org/viewcvs/viewcvs.py/documents/irc/irc_io_api_log.txt?rev=307&view=auto
- *
- * Also referenced in the design of the API was the DOM 3 L&S spec:
- * http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html
- ******************************************************************************/
-
-// a map of the available transport options. Transports should add themselves
-// by calling add(name)
-dojo.io.transports = [];
-dojo.io.hdlrFuncNames = [ "load", "error" ]; // we're omitting a progress() event for now
-
-dojo.io.Request = function(url, mimetype, transport, changeUrl){
- if((arguments.length == 1)&&(arguments[0].constructor == Object)){
- this.fromKwArgs(arguments[0]);
- }else{
- this.url = url;
- if(mimetype){ this.mimetype = mimetype; }
- if(transport){ this.transport = transport; }
- if(arguments.length >= 4){ this.changeUrl = changeUrl; }
- }
-}
-
-dojo.lang.extend(dojo.io.Request, {
-
- /** The URL to hit */
- url: "",
-
- /** The mime type used to interrpret the response body */
- mimetype: "text/plain",
-
- /** The HTTP method to use */
- method: "GET",
-
- /** An Object containing key-value pairs to be included with the request */
- content: undefined, // Object
-
- /** The transport medium to use */
- transport: undefined, // String
-
- /** If defined the URL of the page is physically changed */
- changeUrl: undefined, // String
-
- /** A form node to use in the request */
- formNode: undefined, // HTMLFormElement
-
- /** Whether the request should be made synchronously */
- sync: false,
-
- bindSuccess: false,
-
- /** Cache/look for the request in the cache before attempting to request?
- * NOTE: this isn't a browser cache, this is internal and would only cache in-page
- */
- useCache: false,
-
- /** Prevent the browser from caching this by adding a query string argument to the URL */
- preventCache: false,
-
- // events stuff
- load: function(type, data, evt){ },
- error: function(type, error){ },
- handle: function(){ },
-
- // the abort method needs to be filled in by the transport that accepts the
- // bind() request
- abort: function(){ },
-
- // backButton: function(){ },
- // forwardButton: function(){ },
-
- fromKwArgs: function(kwArgs){
- // normalize args
- if(kwArgs["url"]){ kwArgs.url = kwArgs.url.toString(); }
- if(!kwArgs["method"] && kwArgs["formNode"] && kwArgs["formNode"].method) {
- kwArgs.method = kwArgs["formNode"].method;
- }
-
- // backwards compatibility
- if(!kwArgs["handle"] && kwArgs["handler"]){ kwArgs.handle = kwArgs.handler; }
- if(!kwArgs["load"] && kwArgs["loaded"]){ kwArgs.load = kwArgs.loaded; }
- if(!kwArgs["changeUrl"] && kwArgs["changeURL"]) { kwArgs.changeUrl = kwArgs.changeURL; }
-
- // encoding fun!
- kwArgs.encoding = dojo.lang.firstValued(kwArgs["encoding"], djConfig["bindEncoding"], "");
-
- kwArgs.sendTransport = dojo.lang.firstValued(kwArgs["sendTransport"], djConfig["ioSendTransport"], true);
-
- var isFunction = dojo.lang.isFunction;
- for(var x=0; x<dojo.io.hdlrFuncNames.length; x++){
- var fn = dojo.io.hdlrFuncNames[x];
- if(isFunction(kwArgs[fn])){ continue; }
- if(isFunction(kwArgs["handle"])){
- kwArgs[fn] = kwArgs.handle;
- }
- // handler is aliased above, shouldn't need this check
- /* else if(dojo.lang.isObject(kwArgs.handler)){
- if(isFunction(kwArgs.handler[fn])){
- kwArgs[fn] = kwArgs.handler[fn]||kwArgs.handler["handle"]||function(){};
- }
- }*/
- }
- dojo.lang.mixin(this, kwArgs);
- }
-
-});
-
-dojo.io.Error = function(msg, type, num){
- this.message = msg;
- this.type = type || "unknown"; // must be one of "io", "parse", "unknown"
- this.number = num || 0; // per-substrate error number, not normalized
-}
-
-dojo.io.transports.addTransport = function(name){
- this.push(name);
- // FIXME: do we need to handle things that aren't direct children of the
- // dojo.io namespace? (say, dojo.io.foo.fooTransport?)
- this[name] = dojo.io[name];
-}
-
-// binding interface, the various implementations register their capabilities
-// and the bind() method dispatches
-dojo.io.bind = function(request){
- // if the request asks for a particular implementation, use it
- if(!(request instanceof dojo.io.Request)){
- try{
- request = new dojo.io.Request(request);
- }catch(e){ dojo.debug(e); }
- }
- var tsName = "";
- if(request["transport"]){
- tsName = request["transport"];
- // FIXME: it would be good to call the error handler, although we'd
- // need to use setTimeout or similar to accomplish this and we can't
- // garuntee that this facility is available.
- if(!this[tsName]){ return request; }
- }else{
- // otherwise we do our best to auto-detect what available transports
- // will handle
- for(var x=0; x<dojo.io.transports.length; x++){
- var tmp = dojo.io.transports[x];
- if((this[tmp])&&(this[tmp].canHandle(request))){
- tsName = tmp;
- }
- }
- if(tsName == ""){ return request; }
- }
- this[tsName].bind(request);
- request.bindSuccess = true;
- return request;
-}
-
-dojo.io.queueBind = function(request){
- if(!(request instanceof dojo.io.Request)){
- try{
- request = new dojo.io.Request(request);
- }catch(e){ dojo.debug(e); }
- }
-
- // make sure we get called if/when we get a response
- var oldLoad = request.load;
- request.load = function(){
- dojo.io._queueBindInFlight = false;
- var ret = oldLoad.apply(this, arguments);
- dojo.io._dispatchNextQueueBind();
- return ret;
- }
-
- var oldErr = request.error;
- request.error = function(){
- dojo.io._queueBindInFlight = false;
- var ret = oldErr.apply(this, arguments);
- dojo.io._dispatchNextQueueBind();
- return ret;
- }
-
- dojo.io._bindQueue.push(request);
- dojo.io._dispatchNextQueueBind();
- return request;
-}
-
-dojo.io._dispatchNextQueueBind = function(){
- if(!dojo.io._queueBindInFlight){
- dojo.io._queueBindInFlight = true;
- dojo.io.bind(dojo.io._bindQueue.shift());
- }
-}
-dojo.io._bindQueue = [];
-dojo.io._queueBindInFlight = false;
-
-dojo.io.argsFromMap = function(map, encoding){
- var control = new Object();
- var mapStr = "";
- var enc = /utf/i.test(encoding||"") ? encodeURIComponent : dojo.string.encodeAscii;
- for(var x in map){
- if(!control[x]){
- mapStr+= enc(x)+"="+enc(map[x])+"&";
- }
- }
-
- return mapStr;
-}
-
-/*
-dojo.io.sampleTranport = new function(){
- this.canHandle = function(kwArgs){
- // canHandle just tells dojo.io.bind() if this is a good transport to
- // use for the particular type of request.
- if(
- (
- (kwArgs["mimetype"] == "text/plain") ||
- (kwArgs["mimetype"] == "text/html") ||
- (kwArgs["mimetype"] == "text/javascript")
- )&&(
- (kwArgs["method"] == "get") ||
- ( (kwArgs["method"] == "post") && (!kwArgs["formNode"]) )
- )
- ){
- return true;
- }
-
- return false;
- }
-
- this.bind = function(kwArgs){
- var hdlrObj = {};
-
- // set up a handler object
- for(var x=0; x<dojo.io.hdlrFuncNames.length; x++){
- var fn = dojo.io.hdlrFuncNames[x];
- if(typeof kwArgs.handler == "object"){
- if(typeof kwArgs.handler[fn] == "function"){
- hdlrObj[fn] = kwArgs.handler[fn]||kwArgs.handler["handle"];
- }
- }else if(typeof kwArgs[fn] == "function"){
- hdlrObj[fn] = kwArgs[fn];
- }else{
- hdlrObj[fn] = kwArgs["handle"]||function(){};
- }
- }
-
- // build a handler function that calls back to the handler obj
- var hdlrFunc = function(evt){
- if(evt.type == "onload"){
- hdlrObj.load("load", evt.data, evt);
- }else if(evt.type == "onerr"){
- var errObj = new dojo.io.Error("sampleTransport Error: "+evt.msg);
- hdlrObj.error("error", errObj);
- }
- }
-
- // the sample transport would attach the hdlrFunc() when sending the
- // request down the pipe at this point
- var tgtURL = kwArgs.url+"?"+dojo.io.argsFromMap(kwArgs.content);
- // sampleTransport.sendRequest(tgtURL, hdlrFunc);
- }
-
- dojo.io.transports.addTransport("sampleTranport");
-}
-*/
+dojo.require("dojo.io.*");
+dojo.deprecated("dojo.io", "replaced by dojo.io.*", "0.5");
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/BrowserIO.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/BrowserIO.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/BrowserIO.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/BrowserIO.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -10,15 +10,12 @@
dojo.provide("dojo.io.BrowserIO");
-dojo.require("dojo.io");
-dojo.require("dojo.lang");
+dojo.require("dojo.io.common");
+dojo.require("dojo.lang.array");
+dojo.require("dojo.lang.func");
+dojo.require("dojo.string.extras");
dojo.require("dojo.dom");
-
-try {
- if((!djConfig["preventBackButtonFix"])&&(!dojo.hostenv.post_load_)){
- document.write("<iframe style='border: 0px; width: 1px; height: 1px; position: absolute; bottom: 0px; right: 0px; visibility: visible;' name='djhistory' id='djhistory' src='"+(dojo.hostenv.getBaseScriptUri()+'iframe_history.html')+"'></iframe>");
- }
-}catch(e){/* squelch */}
+dojo.require("dojo.undo.browser");
dojo.io.checkChildrenForFile = function(node){
var hasFile = false;
@@ -36,19 +33,45 @@
return dojo.io.checkChildrenForFile(formNode);
}
+dojo.io.updateNode = function(node, urlOrArgs){
+ node = dojo.byId(node);
+ var args = urlOrArgs;
+ if(dojo.lang.isString(urlOrArgs)){
+ args = { url: urlOrArgs };
+ }
+ args.mimetype = "text/html";
+ args.load = function(t, d, e){
+ while(node.firstChild){
+ if(dojo["event"]){
+ try{
+ dojo.event.browser.clean(node.firstChild);
+ }catch(e){}
+ }
+ node.removeChild(node.firstChild);
+ }
+ node.innerHTML = d;
+ };
+ dojo.io.bind(args);
+}
+
+dojo.io.formFilter = function(node) {
+ var type = (node.type||"").toLowerCase();
+ return !node.disabled && node.name
+ && !dojo.lang.inArray(["file", "submit", "image", "reset", "button"], type);
+}
+
// TODO: Move to htmlUtils
-dojo.io.encodeForm = function(formNode, encoding){
+dojo.io.encodeForm = function(formNode, encoding, formFilter){
if((!formNode)||(!formNode.tagName)||(!formNode.tagName.toLowerCase() == "form")){
dojo.raise("Attempted to encode a non-form element.");
}
+ if(!formFilter) { formFilter = dojo.io.formFilter; }
var enc = /utf/i.test(encoding||"") ? encodeURIComponent : dojo.string.encodeAscii;
var values = [];
for(var i = 0; i < formNode.elements.length; i++){
var elm = formNode.elements[i];
- if(elm.disabled || elm.tagName.toLowerCase() == "fieldset" || !elm.name){
- continue;
- }
+ if(!elm || elm.tagName.toLowerCase() == "fieldset" || !formFilter(elm)) { continue; }
var name = enc(elm.name);
var type = elm.type.toLowerCase();
@@ -58,11 +81,11 @@
values.push(name + "=" + enc(elm.options[j].value));
}
}
- }else if(dojo.lang.inArray(type, ["radio", "checkbox"])){
+ }else if(dojo.lang.inArray(["radio", "checkbox"], type)){
if(elm.checked){
values.push(name + "=" + enc(elm.value));
}
- }else if(!dojo.lang.inArray(type, ["file", "submit", "reset", "button"])) {
+ }else{
values.push(name + "=" + enc(elm.value));
}
}
@@ -71,7 +94,8 @@
var inputs = formNode.getElementsByTagName("input");
for(var i = 0; i < inputs.length; i++) {
var input = inputs[i];
- if(input.type.toLowerCase() == "image" && input.form == formNode) {
+ if(input.type.toLowerCase() == "image" && input.form == formNode
+ && formFilter(input)) {
var name = enc(input.name);
values.push(name + "=" + enc(input.value));
values.push(name + ".x=0");
@@ -81,69 +105,109 @@
return values.join("&") + "&";
}
-dojo.io.setIFrameSrc = function(iframe, src, replace){
- try{
- var r = dojo.render.html;
- // dojo.debug(iframe);
- if(!replace){
- if(r.safari){
- iframe.location = src;
- }else{
- frames[iframe.name].location = src;
- }
- }else{
- // Fun with DOM 0 incompatibilities!
- var idoc;
- if(r.ie){
- idoc = iframe.contentWindow.document;
- }else if(r.moz){
- idoc = iframe.contentWindow;
- }else if(r.safari){
- idoc = iframe.document;
- }
- idoc.location.replace(src);
- }
- }catch(e){
- dojo.debug(e);
- dojo.debug("setIFrameSrc: "+e);
+dojo.io.FormBind = function(args) {
+ this.bindArgs = {};
+
+ if(args && args.formNode) {
+ this.init(args);
+ } else if(args) {
+ this.init({formNode: args});
}
}
+dojo.lang.extend(dojo.io.FormBind, {
+ form: null,
-dojo.io.XMLHTTPTransport = new function(){
- var _this = this;
+ bindArgs: null,
+
+ clickedButton: null,
- this.initialHref = window.location.href;
- this.initialHash = window.location.hash;
+ init: function(args) {
+ var form = dojo.byId(args.formNode);
+
+ if(!form || !form.tagName || form.tagName.toLowerCase() != "form") {
+ throw new Error("FormBind: Couldn't apply, invalid form");
+ } else if(this.form == form) {
+ return;
+ } else if(this.form) {
+ throw new Error("FormBind: Already applied to a form");
+ }
- this.moveForward = false;
+ dojo.lang.mixin(this.bindArgs, args);
+ this.form = form;
+
+ this.connect(form, "onsubmit", "submit");
+
+ for(var i = 0; i < form.elements.length; i++) {
+ var node = form.elements[i];
+ if(node && node.type && dojo.lang.inArray(["submit", "button"], node.type.toLowerCase())) {
+ this.connect(node, "onclick", "click");
+ }
+ }
+
+ var inputs = form.getElementsByTagName("input");
+ for(var i = 0; i < inputs.length; i++) {
+ var input = inputs[i];
+ if(input.type.toLowerCase() == "image" && input.form == form) {
+ this.connect(input, "onclick", "click");
+ }
+ }
+ },
+
+ onSubmit: function(form) {
+ return true;
+ },
+
+ submit: function(e) {
+ e.preventDefault();
+ if(this.onSubmit(this.form)) {
+ dojo.io.bind(dojo.lang.mixin(this.bindArgs, {
+ formFilter: dojo.lang.hitch(this, "formFilter")
+ }));
+ }
+ },
+
+ click: function(e) {
+ var node = e.currentTarget;
+ if(node.disabled) { return; }
+ this.clickedButton = node;
+ },
+
+ formFilter: function(node) {
+ var type = (node.type||"").toLowerCase();
+ var accept = false;
+ if(node.disabled || !node.name) {
+ accept = false;
+ } else if(dojo.lang.inArray(["submit", "button", "image"], type)) {
+ if(!this.clickedButton) { this.clickedButton = node; }
+ accept = node == this.clickedButton;
+ } else {
+ accept = !dojo.lang.inArray(["file", "submit", "reset", "button"], type);
+ }
+ return accept;
+ },
+
+ // in case you don't have dojo.event.* pulled in
+ connect: function(srcObj, srcFcn, targetFcn) {
+ if(dojo.evalObjPath("dojo.event.connect")) {
+ dojo.event.connect(srcObj, srcFcn, this, targetFcn);
+ } else {
+ var fcn = dojo.lang.hitch(this, targetFcn);
+ srcObj[srcFcn] = function(e) {
+ if(!e) { e = window.event; }
+ if(!e.currentTarget) { e.currentTarget = e.srcElement; }
+ if(!e.preventDefault) { e.preventDefault = function() { window.event.returnValue = false; } }
+ fcn(e);
+ }
+ }
+ }
+});
+
+dojo.io.XMLHTTPTransport = new function(){
+ var _this = this;
var _cache = {}; // FIXME: make this public? do we even need to?
this.useCache = false; // if this is true, we'll cache unless kwArgs.useCache = false
this.preventCache = false; // if this is true, we'll always force GET requests to cache
- this.historyStack = [];
- this.forwardStack = [];
- this.historyIframe = null;
- this.bookmarkAnchor = null;
- this.locationTimer = null;
-
- /* NOTES:
- * Safari 1.2:
- * back button "works" fine, however it's not possible to actually
- * DETECT that you've moved backwards by inspecting window.location.
- * Unless there is some other means of locating.
- * FIXME: perhaps we can poll on history.length?
- * IE 5.5 SP2:
- * back button behavior is macro. It does not move back to the
- * previous hash value, but to the last full page load. This suggests
- * that the iframe is the correct way to capture the back button in
- * these cases.
- * IE 6.0:
- * same behavior as IE 5.5 SP2
- * Firefox 1.0:
- * the back button will return us to the previous hash on the same
- * page, thereby not requiring an iframe hack, although we do then
- * need to run a timer to detect inter-page movement.
- */
// FIXME: Should this even be a function? or do we just hard code it in the next 2 functions?
function getCacheKey(url, query, method) {
@@ -164,7 +228,11 @@
// moved successful load stuff here
function doLoad(kwArgs, http, url, query, useCache) {
- if((http.status==200)||(location.protocol=="file:" && http.status==0)) {
+ if( ((http.status>=200)&&(http.status<300))|| // allow any 2XX response code
+ (http.status==304)|| // get it out of the cache
+ (location.protocol=="file:" && (http.status==0 || http.status==undefined))||
+ (location.protocol=="chrome:" && (http.status==0 || http.status==undefined))
+ ){
var ret;
if(kwArgs.method.toLowerCase() == "head"){
var headers = http.getAllResponseHeaders();
@@ -185,7 +253,7 @@
dojo.debug(http.responseText);
ret = null;
}
- }else if(kwArgs.mimetype == "text/json"){
+ }else if(kwArgs.mimetype == "text/json" || kwArgs.mimetype == "application/json"){
try{
ret = dj_eval("("+http.responseText+")");
}catch(e){
@@ -196,7 +264,7 @@
}else if((kwArgs.mimetype == "application/xml")||
(kwArgs.mimetype == "text/xml")){
ret = http.responseXML;
- if(!ret || typeof ret == "string") {
+ if(!ret || typeof ret == "string" || !http.getResponseHeader("Content-Type")) {
ret = dojo.dom.createDocumentFromText(http.responseText);
}
}else{
@@ -206,10 +274,10 @@
if(useCache){ // only cache successful responses
addToCache(url, query, kwArgs.method, http);
}
- kwArgs[(typeof kwArgs.load == "function") ? "load" : "handle"]("load", ret, http);
+ kwArgs[(typeof kwArgs.load == "function") ? "load" : "handle"]("load", ret, http, kwArgs);
}else{
var errObj = new dojo.io.Error("XMLHttpTransport Error: "+http.status+" "+http.statusText);
- kwArgs[(typeof kwArgs.error == "function") ? "error" : "handle"]("error", errObj, http);
+ kwArgs[(typeof kwArgs.error == "function") ? "error" : "handle"]("error", errObj, http, kwArgs);
}
}
@@ -226,197 +294,66 @@
}
}
- this.addToHistory = function(args){
- var callback = args["back"]||args["backButton"]||args["handle"];
- var hash = null;
- if(!this.historyIframe){
- this.historyIframe = window.frames["djhistory"];
- }
- if(!this.bookmarkAnchor){
- this.bookmarkAnchor = document.createElement("a");
- (document.body||document.getElementsByTagName("body")[0]).appendChild(this.bookmarkAnchor);
- this.bookmarkAnchor.style.display = "none";
- }
- if((!args["changeUrl"])||(dojo.render.html.ie)){
- var url = dojo.hostenv.getBaseScriptUri()+"iframe_history.html?"+(new Date()).getTime();
- this.moveForward = true;
- dojo.io.setIFrameSrc(this.historyIframe, url, false);
- }
- if(args["changeUrl"]){
- hash = "#"+ ((args["changeUrl"]!==true) ? args["changeUrl"] : (new Date()).getTime());
- setTimeout("window.location.href = '"+hash+"';", 1);
- this.bookmarkAnchor.href = hash;
- if(dojo.render.html.ie){
- // IE requires manual setting of the hash since we are catching
- // events from the iframe
- var oldCB = callback;
- var lh = null;
- var hsl = this.historyStack.length-1;
- if(hsl>=0){
- while(!this.historyStack[hsl]["urlHash"]){
- hsl--;
- }
- lh = this.historyStack[hsl]["urlHash"];
- }
- if(lh){
- callback = function(){
- if(window.location.hash != ""){
- setTimeout("window.location.href = '"+lh+"';", 1);
- }
- oldCB();
- }
- }
- // when we issue a new bind(), we clobber the forward
- // FIXME: is this always a good idea?
- this.forwardStack = [];
- var oldFW = args["forward"]||args["forwardButton"];;
- var tfw = function(){
- if(window.location.hash != ""){
- window.location.href = hash;
- }
- if(oldFW){ // we might not actually have one
- oldFW();
- }
- }
- if(args["forward"]){
- args.forward = tfw;
- }else if(args["forwardButton"]){
- args.forwardButton = tfw;
- }
- }else if(dojo.render.html.moz){
- // start the timer
- if(!this.locationTimer){
- this.locationTimer = setInterval("dojo.io.XMLHTTPTransport.checkLocation();", 200);
- }
- }
- }
-
- this.historyStack.push({"url": url, "callback": callback, "kwArgs": args, "urlHash": hash});
- }
-
- this.checkLocation = function(){
- var hsl = this.historyStack.length;
-
- if((window.location.hash == this.initialHash)||(window.location.href == this.initialHref)&&(hsl == 1)){
- // FIXME: could this ever be a forward button?
- // we can't clear it because we still need to check for forwards. Ugg.
- // clearInterval(this.locationTimer);
- this.handleBackButton();
- return;
- }
- // first check to see if we could have gone forward. We always halt on
- // a no-hash item.
- if(this.forwardStack.length > 0){
- if(this.forwardStack[this.forwardStack.length-1].urlHash == window.location.hash){
- this.handleForwardButton();
- return;
- }
- }
- // ok, that didn't work, try someplace back in the history stack
- if((hsl >= 2)&&(this.historyStack[hsl-2])){
- if(this.historyStack[hsl-2].urlHash==window.location.hash){
- this.handleBackButton();
- return;
- }
- }
- }
-
- this.iframeLoaded = function(evt, ifrLoc){
- var isp = ifrLoc.href.split("?");
- if(isp.length < 2){
- // alert("iframeLoaded");
- // we hit the end of the history, so we should go back
- if(this.historyStack.length == 1){
- this.handleBackButton();
- }
- return;
- }
- var query = isp[1];
- if(this.moveForward){
- // we were expecting it, so it's not either a forward or backward
- // movement
- this.moveForward = false;
- return;
- }
-
- var last = this.historyStack.pop();
- // we don't have anything in history, so it could be a forward button
- if(!last){
- if(this.forwardStack.length > 0){
- var next = this.forwardStack[this.forwardStack.length-1];
- if(query == next.url.split("?")[1]){
- this.handleForwardButton();
- }
- }
- // regardless, we didnt' have any history, so it can't be a back button
- return;
- }
- // put it back on the stack so we can do something useful with it when
- // we call handleBackButton()
- this.historyStack.push(last);
- if(this.historyStack.length >= 2){
- if(isp[1] == this.historyStack[this.historyStack.length-2].url.split("?")[1]){
- // looks like it IS a back button press, so handle it
- this.handleBackButton();
- }
- }else{
- this.handleBackButton();
- }
- }
-
- this.handleBackButton = function(){
- var last = this.historyStack.pop();
- if(!last){ return; }
- if(last["callback"]){
- last.callback();
- }else if(last.kwArgs["backButton"]){
- last.kwArgs["backButton"]();
- }else if(last.kwArgs["back"]){
- last.kwArgs["back"]();
- }else if(last.kwArgs["handle"]){
- last.kwArgs.handle("back");
- }
- this.forwardStack.push(last);
- }
-
- this.handleForwardButton = function(){
- // FIXME: should we build in support for re-issuing the bind() call here?
- // alert("alert we found a forward button call");
- var last = this.forwardStack.pop();
- if(!last){ return; }
- if(last.kwArgs["forward"]){
- last.kwArgs.forward();
- }else if(last.kwArgs["forwardButton"]){
- last.kwArgs.forwardButton();
- }else if(last.kwArgs["handle"]){
- last.kwArgs.handle("forward");
- }
- this.historyStack.push(last);
- }
-
this.inFlight = [];
this.inFlightTimer = null;
this.startWatchingInFlight = function(){
if(!this.inFlightTimer){
- this.inFlightTimer = setInterval("dojo.io.XMLHTTPTransport.watchInFlight();", 10);
+ // setInterval broken in mozilla x86_64 in some circumstances, see
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=344439
+ // using setTimeout instead
+ this.inFlightTimer = setTimeout("dojo.io.XMLHTTPTransport.watchInFlight();", 10);
}
}
this.watchInFlight = function(){
- for(var x=this.inFlight.length-1; x>=0; x--){
- var tif = this.inFlight[x];
- if(!tif){ this.inFlight.splice(x, 1); continue; }
- if(4==tif.http.readyState){
- // remove it so we can clean refs
- this.inFlight.splice(x, 1);
- doLoad(tif.req, tif.http, tif.url, tif.query, tif.useCache);
- if(this.inFlight.length == 0){
- clearInterval(this.inFlightTimer);
- this.inFlightTimer = null;
+ var now = null;
+ // make sure sync calls stay thread safe, if this callback is called during a sync call
+ // and this results in another sync call before the first sync call ends the browser hangs
+ if(!dojo.hostenv._blockAsync && !_this._blockAsync){
+ for(var x=this.inFlight.length-1; x>=0; x--){
+ try{
+ var tif = this.inFlight[x];
+ if(!tif || tif.http._aborted || !tif.http.readyState){
+ this.inFlight.splice(x, 1); continue;
+ }
+ if(4==tif.http.readyState){
+ // remove it so we can clean refs
+ this.inFlight.splice(x, 1);
+ doLoad(tif.req, tif.http, tif.url, tif.query, tif.useCache);
+ }else if (tif.startTime){
+ //See if this is a timeout case.
+ if(!now){
+ now = (new Date()).getTime();
+ }
+ if(tif.startTime + (tif.req.timeoutSeconds * 1000) < now){
+ //Stop the request.
+ if(typeof tif.http.abort == "function"){
+ tif.http.abort();
+ }
+
+ // remove it so we can clean refs
+ this.inFlight.splice(x, 1);
+ tif.req[(typeof tif.req.timeout == "function") ? "timeout" : "handle"]("timeout", null, tif.http, tif.req);
+ }
+ }
+ }catch(e){
+ try{
+ var errObj = new dojo.io.Error("XMLHttpTransport.watchInFlight Error: " + e);
+ tif.req[(typeof tif.req.error == "function") ? "error" : "handle"]("error", errObj, tif.http, tif.req);
+ }catch(e2){
+ dojo.debug("XMLHttpTransport error callback failed: " + e2);
+ }
}
- } // FIXME: need to implement a timeout param here!
+ }
+ }
+
+ clearTimeout(this.inFlightTimer);
+ if(this.inFlight.length == 0){
+ this.inFlightTimer = null;
+ return;
}
+ this.inFlightTimer = setTimeout("dojo.io.XMLHTTPTransport.watchInFlight();", 10);
}
var hasXmlHttp = dojo.hostenv.getXmlhttpObject() ? true : false;
@@ -428,8 +365,7 @@
// multi-part mime encoded and avoid using this transport for those
// requests.
return hasXmlHttp
- && dojo.lang.inArray((kwArgs["mimetype"]||"".toLowerCase()), ["text/plain", "text/html", "application/xml", "text/xml", "text/javascript", "text/json"])
- && dojo.lang.inArray(kwArgs["method"].toLowerCase(), ["post", "get", "head"])
+ && dojo.lang.inArray(["text/plain", "text/html", "application/xml", "text/xml", "text/javascript", "text/json", "application/json"], (kwArgs["mimetype"].toLowerCase()||""))
&& !( kwArgs["formNode"] && dojo.io.formHasFile(kwArgs["formNode"]) );
}
@@ -441,7 +377,9 @@
if( !kwArgs["formNode"]
&& (kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"] || kwArgs["watchForURL"])
&& (!djConfig.preventBackButtonFix)) {
- this.addToHistory(kwArgs);
+ dojo.deprecated("Using dojo.io.XMLHTTPTransport.bind() to add to browser history without doing an IO request",
+ "Use dojo.undo.browser.addToHistory() instead.", "0.4");
+ dojo.undo.browser.addToHistory(kwArgs);
return true;
}
}
@@ -454,7 +392,7 @@
if((ta)&&(!kwArgs["url"])){ url = ta; }
var tp = kwArgs.formNode.getAttribute("method");
if((tp)&&(!kwArgs["method"])){ kwArgs.method = tp; }
- query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding);
+ query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding, kwArgs["formFilter"]);
}
if(url.indexOf("#") > -1) {
@@ -471,7 +409,7 @@
kwArgs.method = "get";
}
- // guess the multipart value
+ // guess the multipart value
if(kwArgs.method.toLowerCase() == "get"){
// GET cannot use multipart
kwArgs.multipart = false;
@@ -486,7 +424,7 @@
}
if(kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"]){
- this.addToHistory(kwArgs);
+ dojo.undo.browser.addToHistory(kwArgs);
}
var content = kwArgs["content"] || {};
@@ -572,29 +510,45 @@
// much of this is from getText, but reproduced here because we need
// more flexibility
- var http = dojo.hostenv.getXmlhttpObject();
+ var http = dojo.hostenv.getXmlhttpObject(kwArgs);
var received = false;
// build a handler function that calls back to the handler obj
if(async){
+ var startTime =
// FIXME: setting up this callback handler leaks on IE!!!
this.inFlight.push({
"req": kwArgs,
"http": http,
- "url": url,
+ "url": url,
"query": query,
- "useCache": useCache
+ "useCache": useCache,
+ "startTime": kwArgs.timeoutSeconds ? (new Date()).getTime() : 0
});
this.startWatchingInFlight();
+ }else{
+ // block async callbacks until sync is in, needed in khtml, others?
+ _this._blockAsync = true;
}
if(kwArgs.method.toLowerCase() == "post"){
// FIXME: need to hack in more flexible Content-Type setting here!
- http.open("POST", url, async);
+ if (!kwArgs.user) {
+ http.open("POST", url, async);
+ }else{
+ http.open("POST", url, async, kwArgs.user, kwArgs.password);
+ }
setHeaders(http, kwArgs);
http.setRequestHeader("Content-Type", kwArgs.multipart ? ("multipart/form-data; boundary=" + this.multipartBoundary) :
(kwArgs.contentType || "application/x-www-form-urlencoded"));
- http.send(query);
+ try{
+ http.send(query);
+ }catch(e){
+ if(typeof http.abort == "function"){
+ http.abort();
+ }
+ doLoad(kwArgs, {status: 404}, url, query, useCache);
+ }
}else{
var tmpUrl = url;
if(query != "") {
@@ -604,16 +558,31 @@
tmpUrl += (dojo.string.endsWithAny(tmpUrl, "?", "&")
? "" : (tmpUrl.indexOf("?") > -1 ? "&" : "?")) + "dojo.preventCache=" + new Date().valueOf();
}
- http.open(kwArgs.method.toUpperCase(), tmpUrl, async);
+ if (!kwArgs.user) {
+ http.open(kwArgs.method.toUpperCase(), tmpUrl, async);
+ }else{
+ http.open(kwArgs.method.toUpperCase(), tmpUrl, async, kwArgs.user, kwArgs.password);
+ }
setHeaders(http, kwArgs);
- http.send(null);
+ try {
+ http.send(null);
+ }catch(e) {
+ if(typeof http.abort == "function"){
+ http.abort();
+ }
+ doLoad(kwArgs, {status: 404}, url, query, useCache);
+ }
}
if( !async ) {
doLoad(kwArgs, http, url, query, useCache);
+ _this._blockAsync = false;
}
kwArgs.abort = function(){
+ try{// khtml doesent reset readyState on abort, need this workaround
+ http._aborted = true;
+ }catch(e){/*squelsh*/}
return http.abort();
}
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/IframeIO.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/IframeIO.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/IframeIO.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/IframeIO.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -12,23 +12,30 @@
dojo.require("dojo.io.BrowserIO");
dojo.require("dojo.uri.*");
-dojo.io.createIFrame = function(fname, onloadstr){
+// FIXME: is it possible to use the Google htmlfile hack to prevent the
+// background click with this transport?
+
+dojo.io.createIFrame = function(fname, onloadstr, uri){
if(window[fname]){ return window[fname]; }
if(window.frames[fname]){ return window.frames[fname]; }
var r = dojo.render.html;
var cframe = null;
- var turi = dojo.uri.dojoUri("iframe_history.html?noInit=true");
- var ifrstr = ((r.ie)&&(dojo.render.os.win)) ? "<iframe name='"+fname+"' src='"+turi+"' onload='"+onloadstr+"'>" : "iframe";
+ var turi = uri||dojo.uri.dojoUri("iframe_history.html?noInit=true");
+ var ifrstr = ((r.ie)&&(dojo.render.os.win)) ? '<iframe name="'+fname+'" src="'+turi+'" onload="'+onloadstr+'">' : 'iframe';
cframe = document.createElement(ifrstr);
with(cframe){
name = fname;
setAttribute("name", fname);
id = fname;
}
- (document.body||document.getElementsByTagName("body")[0]).appendChild(cframe);
+ dojo.body().appendChild(cframe);
window[fname] = cframe;
+
with(cframe.style){
- position = "absolute";
+ if(!r.safari){
+ //We can't change the src in Safari 2.0.3 if absolute position. Bizarro.
+ position = "absolute";
+ }
left = top = "0px";
height = width = "1px";
visibility = "hidden";
@@ -46,31 +53,10 @@
dojo.io.setIFrameSrc(cframe, turi, true);
cframe.onload = new Function(onloadstr);
}
+
return cframe;
}
-// thanks burstlib!
-dojo.io.iframeContentWindow = function(iframe_el) {
- var win = iframe_el.contentWindow || // IE
- dojo.io.iframeContentDocument(iframe_el).defaultView || // Moz, opera
- // Moz. TODO: is this available when defaultView isn't?
- dojo.io.iframeContentDocument(iframe_el).__parent__ ||
- (iframe_el.name && document.frames[iframe_el.name]) || null;
- return win;
-}
-
-dojo.io.iframeContentDocument = function(iframe_el){
- var doc = iframe_el.contentDocument || // W3
- (
- (iframe_el.contentWindow)&&(iframe_el.contentWindow.document)
- ) || // IE
- (
- (iframe_el.name)&&(document.frames[iframe_el.name])&&
- (document.frames[iframe_el.name].document)
- ) || null;
- return doc;
-}
-
dojo.io.IframeTransport = new function(){
var _this = this;
this.currentRequest = null;
@@ -78,68 +64,68 @@
this.iframeName = "dojoIoIframe";
this.fireNextRequest = function(){
- if((this.currentRequest)||(this.requestQueue.length == 0)){ return; }
- // dojo.debug("fireNextRequest");
- var cr = this.currentRequest = this.requestQueue.shift();
- var fn = cr["formNode"];
- var content = cr["content"] || {};
- if(cr.sendTransport) {
- content["dojo.transport"] = "iframe";
- }
- if(fn){
- if(content){
- // if we have things in content, we need to add them to the form
- // before submission
- for(var x in content){
- if(!fn[x]){
- var tn;
- if(dojo.render.html.ie){
- tn = document.createElement("<input type='hidden' name='"+x+"' value='"+content[x]+"'>");
- fn.appendChild(tn);
+ try{
+ if((this.currentRequest)||(this.requestQueue.length == 0)){ return; }
+ // dojo.debug("fireNextRequest");
+ var cr = this.currentRequest = this.requestQueue.shift();
+ cr._contentToClean = [];
+ var fn = cr["formNode"];
+ var content = cr["content"] || {};
+ if(cr.sendTransport) {
+ content["dojo.transport"] = "iframe";
+ }
+ if(fn){
+ if(content){
+ // if we have things in content, we need to add them to the form
+ // before submission
+ for(var x in content){
+ if(!fn[x]){
+ var tn;
+ if(dojo.render.html.ie){
+ tn = document.createElement("<input type='hidden' name='"+x+"' value='"+content[x]+"'>");
+ fn.appendChild(tn);
+ }else{
+ tn = document.createElement("input");
+ fn.appendChild(tn);
+ tn.type = "hidden";
+ tn.name = x;
+ tn.value = content[x];
+ }
+ cr._contentToClean.push(x);
}else{
- tn = document.createElement("input");
- fn.appendChild(tn);
- tn.type = "hidden";
- tn.name = x;
- tn.value = content[x];
+ fn[x].value = content[x];
}
- }else{
- fn[x].value = content[x];
}
}
+ if(cr["url"]){
+ cr._originalAction = fn.getAttribute("action");
+ fn.setAttribute("action", cr.url);
+ }
+ if(!fn.getAttribute("method")){
+ fn.setAttribute("method", (cr["method"]) ? cr["method"] : "post");
+ }
+ cr._originalTarget = fn.getAttribute("target");
+ fn.setAttribute("target", this.iframeName);
+ fn.target = this.iframeName;
+ fn.submit();
+ }else{
+ // otherwise we post a GET string by changing URL location for the
+ // iframe
+ var query = dojo.io.argsFromMap(this.currentRequest.content);
+ var tmpUrl = cr.url + (cr.url.indexOf("?") > -1 ? "&" : "?") + query;
+ dojo.io.setIFrameSrc(this.iframe, tmpUrl, true);
}
- if(cr["url"]){
- fn.setAttribute("action", cr.url);
- }
- if(!fn.getAttribute("method")){
- fn.setAttribute("method", (cr["method"]) ? cr["method"] : "post");
- }
- fn.setAttribute("target", this.iframeName);
- fn.target = this.iframeName;
- fn.submit();
- }else{
- // otherwise we post a GET string by changing URL location for the
- // iframe
- var query = dojo.io.argsFromMap(this.currentRequest.content);
- var tmpUrl = (cr.url.indexOf("?") > -1 ? "&" : "?") + query;
- dojo.io.setIFrameSrc(this.iframe, tmpUrl, true);
+ }catch(e){
+ this.iframeOnload(e);
}
}
this.canHandle = function(kwArgs){
return (
(
- // FIXME: can we really handle text/plain and
- // text/javascript requests?
- dojo.lang.inArray(kwArgs["mimetype"],
- [ "text/plain", "text/html",
- "application/xml", "text/xml",
- "text/javascript", "text/json"])
+ dojo.lang.inArray([ "text/plain", "text/html", "text/javascript", "text/json", "application/json"], kwArgs["mimetype"])
)&&(
- // make sur we really only get used in file upload cases
- (kwArgs["formNode"])&&(dojo.io.checkChildrenForFile(kwArgs["formNode"]))
- )&&(
- dojo.lang.inArray(kwArgs["method"].toLowerCase(), ["post", "get"])
+ dojo.lang.inArray(["post", "get"], kwArgs["method"].toLowerCase())
)&&(
// never handle a sync request
! ((kwArgs["sync"])&&(kwArgs["sync"] == true))
@@ -148,6 +134,7 @@
}
this.bind = function(kwArgs){
+ if(!this["iframe"]){ this.setUpIframe(); }
this.requestQueue.push(kwArgs);
this.fireNextRequest();
return;
@@ -160,48 +147,97 @@
this.iframe = dojo.io.createIFrame(this.iframeName, "dojo.io.IframeTransport.iframeOnload();");
}
- this.iframeOnload = function(){
+ this.iframeOnload = function(errorObject /* Object */){
if(!_this.currentRequest){
_this.fireNextRequest();
return;
}
- var ifr = _this.iframe;
- var ifw = dojo.io.iframeContentWindow(ifr);
- // handle successful returns
- // FIXME: how do we determine success for iframes? Is there an equiv of
- // the "status" property?
+
+ var req = _this.currentRequest;
+
+ if(req.formNode){
+ // remove all the hidden content inputs
+ var toClean = req._contentToClean;
+ for(var i = 0; i < toClean.length; i++) {
+ var key = toClean[i];
+ if(dojo.render.html.safari){
+ //In Safari (at least 2.0.3), can't use formNode[key] syntax to find the node,
+ //for nodes that were dynamically added.
+ var fNode = req.formNode;
+ for(var j = 0; j < fNode.childNodes.length; j++){
+ var chNode = fNode.childNodes[j];
+ if(chNode.name == key){
+ var pNode = chNode.parentNode;
+ pNode.removeChild(chNode);
+ break;
+ }
+ }
+ }else{
+ var input = req.formNode[key];
+ req.formNode.removeChild(input);
+ req.formNode[key] = null;
+ }
+ }
+
+ // restore original action + target
+ if(req["_originalAction"]){
+ req.formNode.setAttribute("action", req._originalAction);
+ }
+ if(req["_originalTarget"]){
+ req.formNode.setAttribute("target", req._originalTarget);
+ req.formNode.target = req._originalTarget;
+ }
+ }
+
+ var contentDoc = function(iframe_el){
+ var doc = iframe_el.contentDocument || // W3
+ (
+ (iframe_el.contentWindow)&&(iframe_el.contentWindow.document)
+ ) || // IE
+ (
+ (iframe_el.name)&&(document.frames[iframe_el.name])&&
+ (document.frames[iframe_el.name].document)
+ ) || null;
+ return doc;
+ };
+
var value;
var success = false;
- try{
- var cmt = _this.currentRequest.mimetype;
- if((cmt == "text/javascript")||(cmt == "text/json")){
- // FIXME: not sure what to do here? try to pull some evalulable
- // text from a textarea or cdata section?
- // how should we set up the contract for that?
- var cd = dojo.io.iframeContentDocument(_this.iframe);
- var js = cd.getElementsByTagName("textarea")[0].value;
- if(cmt == "text/json") { js = "(" + js + ")"; }
- value = dj_eval(js);
- }else if((cmt == "application/xml")||(cmt == "text/xml")){
- value = dojo.io.iframeContentDocument(_this.iframe);
- }else{ // text/plain
- value = ifw.innerHTML;
- }
- success = true;
- }catch(e){
- // looks like we didn't get what we wanted!
- var errObj = new dojo.io.Error("IframeTransport Error");
- if(dojo.lang.isFunction(_this.currentRequest["error"])){
- _this.currentRequest.error("error", errObj, _this.currentRequest);
+ if (errorObject){
+ this._callError(req, "IframeTransport Request Error: " + errorObject);
+ }else{
+ var ifd = contentDoc(_this.iframe);
+ // handle successful returns
+ // FIXME: how do we determine success for iframes? Is there an equiv of
+ // the "status" property?
+
+ try{
+ var cmt = req.mimetype;
+ if((cmt == "text/javascript")||(cmt == "text/json")||(cmt == "application/json")){
+ // FIXME: not sure what to do here? try to pull some evalulable
+ // text from a textarea or cdata section?
+ // how should we set up the contract for that?
+ var js = ifd.getElementsByTagName("textarea")[0].value;
+ if(cmt == "text/json" || cmt == "application/json") { js = "(" + js + ")"; }
+ value = dj_eval(js);
+ }else if(cmt == "text/html"){
+ value = ifd;
+ }else{ // text/plain
+ value = ifd.getElementsByTagName("textarea")[0].value;
+ }
+ success = true;
+ }catch(e){
+ // looks like we didn't get what we wanted!
+ this._callError(req, "IframeTransport Error: " + e);
}
}
// don't want to mix load function errors with processing errors, thus
// a separate try..catch
try {
- if(success && dojo.lang.isFunction(_this.currentRequest["load"])){
- _this.currentRequest.load("load", value, _this.currentRequest);
+ if(success && dojo.lang.isFunction(req["load"])){
+ req.load("load", value, req);
}
} catch(e) {
throw e;
@@ -210,10 +246,13 @@
_this.fireNextRequest();
}
}
+
+ this._callError = function(req /* Object */, message /* String */){
+ var errObj = new dojo.io.Error(message);
+ if(dojo.lang.isFunction(req["error"])){
+ req.error("error", errObj, req);
+ }
+ }
dojo.io.transports.addTransport("IframeTransport");
}
-
-dojo.addOnLoad(function(){
- dojo.io.IframeTransport.setUpIframe();
-});
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RepubsubIO.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RepubsubIO.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RepubsubIO.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RepubsubIO.js Mon Nov 13 14:54:45 2006
@@ -1,20 +1,10 @@
-/*
- Copyright (c) 2004-2005, The Dojo Foundation
- All Rights Reserved.
+// Copyright (c) 2004 Friendster Inc., Licensed under the Academic Free
+// License version 2.0 or later
- Licensed under the Academic Free License version 2.1 or above OR the
- modified BSD license. For more information on Dojo licensing, see:
-
- http://dojotoolkit.org/community/licensing.shtml
-*/
-
-dojo.require("dojo.event.Event");
-dojo.require("dojo.event.BrowserEvent");
+dojo.require("dojo.event.*");
dojo.require("dojo.io.BrowserIO");
dojo.provide("dojo.io.RepubsubIO");
-dojo.provide("dojo.io.repubsub");
-dojo.provide("dojo.io.repubsubTransport");
dojo.io.repubsubTranport = new function(){
var rps = dojo.io.repubsub;
@@ -57,7 +47,7 @@
kwArgs.rpsLoad = function(evt){
kwArgs.load("load", evt);
}
- rps.subscribe = function(kwArgs.url, kwArgs, "rpsLoad");
+ rps.subscribe(kwArgs.url, kwArgs, "rpsLoad");
}
if(kwArgs["content"]){
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RhinoIO.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RhinoIO.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RhinoIO.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/RhinoIO.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -10,13 +10,138 @@
dojo.provide("dojo.io.RhinoIO");
-// TODO: this doesn't execute
-/*dojo.io.SyncHTTPRequest = function(){
- dojo.io.SyncRequest.call(this);
+dojo.require("dojo.io.common");
+dojo.require("dojo.lang.func");
+dojo.require("dojo.lang.array");
+dojo.require("dojo.string.extras");
+
+dojo.io.RhinoHTTPTransport = new function(){
+ this.canHandle = function(req){
+ // We have to limit to text types because Rhino doesnt support
+ // a W3C dom implementation out of the box. In the future we
+ // should provide some kind of hook to inject your own, because
+ // in all my projects I use XML for Script to provide a W3C DOM.
+ if(!dojo.lang.inArray((req.mimetype.toLowerCase() || ""),
+ ["text/plain", "text/html", "text/javascript", "text/json", "application/json"])){
+ return false;
+ }
+
+ // We only handle http requests! Unfortunately, because the method is
+ // protected, I can't directly create a java.net.HttpURLConnection, so
+ // this is the only way to test.
+ if(req.url.substr(0, 7) != "http://"){
+ return false;
+ }
+
+ return true;
+ }
+
+ function doLoad(req, conn){
+ var ret;
+ if (req.method.toLowerCase() == "head"){
+ // TODO: return the headers
+ }else{
+ var stream = conn.getContent();
+ var reader = new java.io.BufferedReader(new java.io.InputStreamReader(stream));
+
+ // read line-by-line because why not?
+ var text = "";
+ var line = null;
+ while((line = reader.readLine()) != null){
+ text += line;
+ }
+
+ if(req.mimetype == "text/javascript"){
+ try{
+ ret = dj_eval(text);
+ }catch(e){
+ dojo.debug(e);
+ dojo.debug(text);
+ ret = null;
+ }
+ }else if(req.mimetype == "text/json" || req.mimetype == "application/json"){
+ try{
+ ret = dj_eval("("+text+")");
+ }catch(e){
+ dojo.debug(e);
+ dojo.debug(text);
+ ret = false;
+ }
+ }else{
+ ret = text;
+ }
+ }
+
+ req.load("load", ret, req);
+ }
+
+ function connect(req){
+ var content = req.content || {};
+ var query;
+
+ if (req.sendTransport){
+ content["dojo.transport"] = "rhinohttp";
+ }
+
+ if(req.postContent){
+ query = req.postContent;
+ }else{
+ query = dojo.io.argsFromMap(content, req.encoding);
+ }
+
+ var url_text = req.url;
+ if(req.method.toLowerCase() == "get" && query != ""){
+ url_text = url_text + "?" + query;
+ }
+
+ var url = new java.net.URL(url_text);
+ var conn = url.openConnection();
+
+ //
+ // configure the connection
+ //
+
+ conn.setRequestMethod(req.method.toUpperCase());
+
+ if(req.headers){
+ for(var header in req.headers){
+ if(header.toLowerCase() == "content-type" && !req.contentType){
+ req.contentType = req.headers[header];
+ }else{
+ conn.setRequestProperty(header, req.headers[header]);
+ }
+ }
+ }
+ if(req.contentType){
+ conn.setRequestProperty("Content-Type", req.contentType);
+ }
+
+ if(req.method.toLowerCase() == "post"){
+ conn.setDoOutput(true);
+
+ // write the post data
+ var output_stream = conn.getOutputStream();
+ var byte_array = (new java.lang.String(query)).getBytes();
+ output_stream.write(byte_array, 0, byte_array.length);
+ }
+
+ // do it to it!
+ conn.connect();
+
+ // perform the load
+ doLoad(req, conn);
+ }
+
+ this.bind = function(req){
+ var async = req["sync"] ? false : true;
+ if (async){
+ setTimeout(dojo.lang.hitch(this, function(){
+ connect(req);
+ }), 1);
+ } else {
+ connect(req);
+ }
+ }
- this.send = function(URI){
- }
+ dojo.io.transports.addTransport("RhinoHTTPTransport");
}
-
-dojo.inherits(dojo.io.SyncHTTPRequest, dojo.io.SyncRequest);
-*/
Added: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/ScriptSrcIO.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/ScriptSrcIO.js?view=auto&rev=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/ScriptSrcIO.js (added)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/ScriptSrcIO.js Mon Nov 13 14:54:45 2006
@@ -0,0 +1,458 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.io.ScriptSrcIO");
+dojo.require("dojo.io.BrowserIO");
+dojo.require("dojo.undo.browser");
+
+//FIXME: should constantParams be JS object?
+//FIXME: check dojo.io calls. Can we move the BrowserIO defined calls somewhere
+// else so that we don't depend on BrowserIO at all? The dependent calls
+// have to do with dealing with forms and making query params from JS object.
+/**
+ * See test_ScriptSrcIO.html for usage information.
+ * Notes:
+ * - The watchInFlight timer is set to 100 ms instead of 10ms (which is what BrowserIO.js uses).
+ */
+dojo.io.ScriptSrcTransport = new function(){
+ this.preventCache = false; // if this is true, we'll always force GET requests to not cache
+ this.maxUrlLength = 1000; //Used to calculate if script request should be multipart.
+ this.inFlightTimer = null;
+
+ this.DsrStatusCodes = {
+ Continue: 100,
+ Ok: 200,
+ Error: 500
+ };
+
+ this.startWatchingInFlight = function(){
+ if(!this.inFlightTimer){
+ this.inFlightTimer = setInterval("dojo.io.ScriptSrcTransport.watchInFlight();", 100);
+ }
+ }
+
+ this.watchInFlight = function(){
+ var totalCount = 0;
+ var doneCount = 0;
+ for(var param in this._state){
+ totalCount++;
+ var currentState = this._state[param];
+ if(currentState.isDone){
+ doneCount++;
+ delete this._state[param];
+ }else if(!currentState.isFinishing){
+ var listener = currentState.kwArgs;
+ try{
+ if(currentState.checkString && eval("typeof(" + currentState.checkString + ") != 'undefined'")){
+ currentState.isFinishing = true;
+ this._finish(currentState, "load");
+ doneCount++;
+ delete this._state[param];
+ }else if(listener.timeoutSeconds && listener.timeout){
+ if(currentState.startTime + (listener.timeoutSeconds * 1000) < (new Date()).getTime()){
+ currentState.isFinishing = true;
+ this._finish(currentState, "timeout");
+ doneCount++;
+ delete this._state[param];
+ }
+ }else if(!listener.timeoutSeconds){
+ //Increment the done count if no timeout is specified, so
+ //that we turn off the timer if all that is left in the state
+ //list are things we can't clean up because they fail without
+ //getting a callback.
+ doneCount++;
+ }
+ }catch(e){
+ currentState.isFinishing = true;
+ this._finish(currentState, "error", {status: this.DsrStatusCodes.Error, response: e});
+ }
+ }
+ }
+
+ if(doneCount >= totalCount){
+ clearInterval(this.inFlightTimer);
+ this.inFlightTimer = null;
+ }
+ }
+
+ this.canHandle = function(kwArgs){
+ return dojo.lang.inArray(["text/javascript", "text/json", "application/json"], (kwArgs["mimetype"].toLowerCase()))
+ && (kwArgs["method"].toLowerCase() == "get")
+ && !(kwArgs["formNode"] && dojo.io.formHasFile(kwArgs["formNode"]))
+ && (!kwArgs["sync"] || kwArgs["sync"] == false)
+ && !kwArgs["file"]
+ && !kwArgs["multipart"];
+ }
+
+ /**
+ * Removes any script tags from the DOM that may have been added by ScriptSrcTransport.
+ * Be careful though, by removing them from the script, you may invalidate some
+ * script objects that were defined by the js file that was pulled in as the
+ * src of the script tag. Test carefully if you decide to call this method.
+ *
+ * In MSIE 6 (and probably 5.x), if you removed the script element while
+ * part of the script is still executing, the browser will crash.
+ */
+ this.removeScripts = function(){
+ var scripts = document.getElementsByTagName("script");
+ for(var i = 0; scripts && i < scripts.length; i++){
+ var scriptTag = scripts[i];
+ if(scriptTag.className == "ScriptSrcTransport"){
+ var parent = scriptTag.parentNode;
+ parent.removeChild(scriptTag);
+ i--; //Set the index back one since we removed an item.
+ }
+ }
+ }
+
+ this.bind = function(kwArgs){
+ //START duplication from BrowserIO.js (some changes made)
+ var url = kwArgs.url;
+ var query = "";
+
+ if(kwArgs["formNode"]){
+ var ta = kwArgs.formNode.getAttribute("action");
+ if((ta)&&(!kwArgs["url"])){ url = ta; }
+ var tp = kwArgs.formNode.getAttribute("method");
+ if((tp)&&(!kwArgs["method"])){ kwArgs.method = tp; }
+ query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding, kwArgs["formFilter"]);
+ }
+
+ if(url.indexOf("#") > -1) {
+ dojo.debug("Warning: dojo.io.bind: stripping hash values from url:", url);
+ url = url.split("#")[0];
+ }
+
+ //Break off the domain/path of the URL.
+ var urlParts = url.split("?");
+ if(urlParts && urlParts.length == 2){
+ url = urlParts[0];
+ query += (query ? "&" : "") + urlParts[1];
+ }
+
+ if(kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"]){
+ dojo.undo.browser.addToHistory(kwArgs);
+ }
+
+ //Create an ID for the request.
+ var id = kwArgs["apiId"] ? kwArgs["apiId"] : "id" + this._counter++;
+
+ //Fill out any other content pieces.
+ var content = kwArgs["content"];
+ var jsonpName = kwArgs.jsonParamName;
+ if(kwArgs.sendTransport || jsonpName) {
+ if (!content){
+ content = {};
+ }
+ if(kwArgs.sendTransport){
+ content["dojo.transport"] = "scriptsrc";
+ }
+
+ if(jsonpName){
+ content[jsonpName] = "dojo.io.ScriptSrcTransport._state." + id + ".jsonpCall";
+ }
+ }
+
+ if(kwArgs.postContent){
+ query = kwArgs.postContent;
+ }else if(content){
+ query += ((query) ? "&" : "") + dojo.io.argsFromMap(content, kwArgs.encoding, jsonpName);
+ }
+ //END duplication from BrowserIO.js
+
+ //START DSR
+
+ //If an apiId is specified, then we want to make sure useRequestId is true.
+ if(kwArgs["apiId"]){
+ kwArgs["useRequestId"] = true;
+ }
+
+ //Set up the state for this request.
+ var state = {
+ "id": id,
+ "idParam": "_dsrid=" + id,
+ "url": url,
+ "query": query,
+ "kwArgs": kwArgs,
+ "startTime": (new Date()).getTime(),
+ "isFinishing": false
+ };
+
+ if(!url){
+ //Error. An URL is needed.
+ this._finish(state, "error", {status: this.DsrStatusCodes.Error, statusText: "url.none"});
+ return;
+ }
+
+ //If this is a jsonp request, intercept the jsonp callback
+ if(content && content[jsonpName]){
+ state.jsonp = content[jsonpName];
+ state.jsonpCall = function(data){
+ if(data["Error"]||data["error"]){
+ if(dojo["json"] && dojo["json"]["serialize"]){
+ dojo.debug(dojo.json.serialize(data));
+ }
+ dojo.io.ScriptSrcTransport._finish(this, "error", data);
+ }else{
+ dojo.io.ScriptSrcTransport._finish(this, "load", data);
+ }
+ };
+ }
+
+ //Only store the request state on the state tracking object if a callback
+ //is expected or if polling on a checkString will be done.
+ if(kwArgs["useRequestId"] || kwArgs["checkString"] || state["jsonp"]){
+ this._state[id] = state;
+ }
+
+ //A checkstring is a string that if evaled will not be undefined once the
+ //script src loads. Used as an alternative to depending on a callback from
+ //the script file. If this is set, then multipart is not assumed to be used,
+ //since multipart requires a specific callback. With checkString we will be doing
+ //polling.
+ if(kwArgs["checkString"]){
+ state.checkString = kwArgs["checkString"];
+ }
+
+ //Constant params are parameters that should always be sent with each
+ //part of a multipart URL.
+ state.constantParams = (kwArgs["constantParams"] == null ? "" : kwArgs["constantParams"]);
+
+ if(kwArgs["preventCache"] ||
+ (this.preventCache == true && kwArgs["preventCache"] != false)){
+ state.nocacheParam = "dojo.preventCache=" + new Date().valueOf();
+ }else{
+ state.nocacheParam = "";
+ }
+
+ //Get total length URL, if we were to do it as one URL.
+ //Add some padding, extra & separators.
+ var urlLength = state.url.length + state.query.length + state.constantParams.length
+ + state.nocacheParam.length + this._extraPaddingLength;
+
+ if(kwArgs["useRequestId"]){
+ urlLength += state.idParam.length;
+ }
+
+ if(!kwArgs["checkString"] && kwArgs["useRequestId"]
+ && !state["jsonp"] && !kwArgs["forceSingleRequest"]
+ && urlLength > this.maxUrlLength){
+ if(url > this.maxUrlLength){
+ //Error. The URL domain and path are too long. We can't
+ //segment that, so return an error.
+ this._finish(state, "error", {status: this.DsrStatusCodes.Error, statusText: "url.tooBig"});
+ return;
+ }else{
+ //Start the multiple requests.
+ this._multiAttach(state, 1);
+ }
+ }else{
+ //Send one URL.
+ var queryParams = [state.constantParams, state.nocacheParam, state.query];
+ if(kwArgs["useRequestId"] && !state["jsonp"]){
+ queryParams.unshift(state.idParam);
+ }
+ var finalUrl = this._buildUrl(state.url, queryParams);
+
+ //Track the final URL in case we need to use that instead of api ID when receiving
+ //the load callback.
+ state.finalUrl = finalUrl;
+
+ this._attach(state.id, finalUrl);
+ }
+ //END DSR
+
+ this.startWatchingInFlight();
+ }
+
+ //Private properties/methods
+ this._counter = 1;
+ this._state = {};
+ this._extraPaddingLength = 16;
+
+ //Is there a dojo function for this already?
+ this._buildUrl = function(url, nameValueArray){
+ var finalUrl = url;
+ var joiner = "?";
+ for(var i = 0; i < nameValueArray.length; i++){
+ if(nameValueArray[i]){
+ finalUrl += joiner + nameValueArray[i];
+ joiner = "&";
+ }
+ }
+
+ return finalUrl;
+ }
+
+ this._attach = function(id, url){
+ //Attach the script to the DOM.
+ var element = document.createElement("script");
+ element.type = "text/javascript";
+ element.src = url;
+ element.id = id;
+ element.className = "ScriptSrcTransport";
+ document.getElementsByTagName("head")[0].appendChild(element);
+ }
+
+ this._multiAttach = function(state, part){
+ //Check to make sure we still have a query to send up. This is mostly
+ //a protection from a goof on the server side when it sends a part OK
+ //response instead of a final response.
+ if(state.query == null){
+ this._finish(state, "error", {status: this.DsrStatusCodes.Error, statusText: "query.null"});
+ return;
+ }
+
+ if(!state.constantParams){
+ state.constantParams = "";
+ }
+
+ //How much of the query can we take?
+ //Add a padding constant to account for _part and a couple extra amperstands.
+ //Also add space for id since we'll need it now.
+ var queryMax = this.maxUrlLength - state.idParam.length
+ - state.constantParams.length - state.url.length
+ - state.nocacheParam.length - this._extraPaddingLength;
+
+ //Figure out if this is the last part.
+ var isDone = state.query.length < queryMax;
+
+ //Break up the query string if necessary.
+ var currentQuery;
+ if(isDone){
+ currentQuery = state.query;
+ state.query = null;
+ }else{
+ //Find the & or = nearest the max url length.
+ var ampEnd = state.query.lastIndexOf("&", queryMax - 1);
+ var eqEnd = state.query.lastIndexOf("=", queryMax - 1);
+
+ //See if & is closer, or if = is right at the edge,
+ //which means we should put it on the next URL.
+ if(ampEnd > eqEnd || eqEnd == queryMax - 1){
+ //& is nearer the end. So just chop off from there.
+ currentQuery = state.query.substring(0, ampEnd);
+ state.query = state.query.substring(ampEnd + 1, state.query.length) //strip off amperstand with the + 1.
+ }else{
+ //= is nearer the end. Take the max amount possible.
+ currentQuery = state.query.substring(0, queryMax);
+
+ //Find the last query name in the currentQuery so we can prepend it to
+ //ampEnd. Could be -1 (not there), so account for that.
+ var queryName = currentQuery.substring((ampEnd == -1 ? 0 : ampEnd + 1), eqEnd);
+ state.query = queryName + "=" + state.query.substring(queryMax, state.query.length);
+ }
+ }
+
+ //Now send a part of the script
+ var queryParams = [currentQuery, state.idParam, state.constantParams, state.nocacheParam];
+ if(!isDone){
+ queryParams.push("_part=" + part);
+ }
+
+ var url = this._buildUrl(state.url, queryParams);
+
+ this._attach(state.id + "_" + part, url);
+ }
+
+ this._finish = function(state, callback, event){
+ if(callback != "partOk" && !state.kwArgs[callback] && !state.kwArgs["handle"]){
+ //Ignore "partOk" because that is an internal callback.
+ if(callback == "error"){
+ state.isDone = true;
+ throw event;
+ }
+ }else{
+ switch(callback){
+ case "load":
+ var response = event ? event.response : null;
+ if(!response){
+ response = event;
+ }
+ state.kwArgs[(typeof state.kwArgs.load == "function") ? "load" : "handle"]("load", response, event, state.kwArgs);
+ state.isDone = true;
+ break;
+ case "partOk":
+ var part = parseInt(event.response.part, 10) + 1;
+ //Update the constant params, if any.
+ if(event.response.constantParams){
+ state.constantParams = event.response.constantParams;
+ }
+ this._multiAttach(state, part);
+ state.isDone = false;
+ break;
+ case "error":
+ state.kwArgs[(typeof state.kwArgs.error == "function") ? "error" : "handle"]("error", event.response, event, state.kwArgs);
+ state.isDone = true;
+ break;
+ default:
+ state.kwArgs[(typeof state.kwArgs[callback] == "function") ? callback : "handle"](callback, event, event, state.kwArgs);
+ state.isDone = true;
+ }
+ }
+ }
+
+ dojo.io.transports.addTransport("ScriptSrcTransport");
+}
+
+//Define callback handler.
+window.onscriptload = function(event){
+ var state = null;
+ var transport = dojo.io.ScriptSrcTransport;
+
+ //Find the matching state object for event ID.
+ if(transport._state[event.id]){
+ state = transport._state[event.id];
+ }else{
+ //The ID did not match directly to an entry in the state list.
+ //Try searching the state objects for a matching original URL.
+ var tempState;
+ for(var param in transport._state){
+ tempState = transport._state[param];
+ if(tempState.finalUrl && tempState.finalUrl == event.id){
+ state = tempState;
+ break;
+ }
+ }
+
+ //If no matching original URL is found, then use the URL that was actually used
+ //in the SCRIPT SRC attribute.
+ if(state == null){
+ var scripts = document.getElementsByTagName("script");
+ for(var i = 0; scripts && i < scripts.length; i++){
+ var scriptTag = scripts[i];
+ if(scriptTag.getAttribute("class") == "ScriptSrcTransport"
+ && scriptTag.src == event.id){
+ state = transport._state[scriptTag.id];
+ break;
+ }
+ }
+ }
+
+ //If state is still null, then throw an error.
+ if(state == null){
+ throw "No matching state for onscriptload event.id: " + event.id;
+ }
+ }
+
+ var callbackName = "error";
+ switch(event.status){
+ case dojo.io.ScriptSrcTransport.DsrStatusCodes.Continue:
+ //A part of a multipart request.
+ callbackName = "partOk";
+ break;
+ case dojo.io.ScriptSrcTransport.DsrStatusCodes.Ok:
+ //Successful reponse.
+ callbackName = "load";
+ break;
+ }
+
+ transport._finish(state, callbackName, event);
+};
Propchange: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/ScriptSrcIO.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/XhrIframeProxy.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/XhrIframeProxy.js?view=auto&rev=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/XhrIframeProxy.js (added)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/XhrIframeProxy.js Mon Nov 13 14:54:45 2006
@@ -0,0 +1,211 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.io.XhrIframeProxy");
+
+dojo.require("dojo.experimental");
+dojo.experimental("dojo.io.XhrIframeProxy");
+
+dojo.require("dojo.io.IframeIO");
+dojo.require("dojo.html.iframe");
+dojo.require("dojo.dom");
+dojo.require("dojo.uri.Uri");
+
+/*
+TODO: This page might generate a "loading unsecure items on a secure page"
+popup in browsers if it is served on a https URL, given that we are not
+setting a src on the iframe element.
+//TODO: Document that it doesn't work from local disk in Safari.
+
+*/
+
+dojo.io.XhrIframeProxy = new function(){
+ this.xipClientUrl = dojo.uri.dojoUri("src/io/xip_client.html");
+
+ this._state = {};
+ this._stateIdCounter = 0;
+
+ this.send = function(facade){
+ var stateId = "XhrIframeProxy" + (this._stateIdCounter++);
+ facade._stateId = stateId;
+
+ this._state[stateId] = {
+ facade: facade,
+ stateId: stateId,
+ clientFrame: dojo.io.createIFrame(stateId,
+ "dojo.io.XhrIframeProxy.clientFrameLoaded('" + stateId + "');",
+ this.xipClientUrl)
+ };
+ }
+
+ this.receive = function(stateId, urlEncodedData){
+ /* urlEncodedData should have the following params:
+ - responseHeaders
+ - status
+ - statusText
+ - responseText
+ */
+ //Decode response data.
+ var response = {};
+ var nvPairs = urlEncodedData.split("&");
+ for(var i = 0; i < nvPairs.length; i++){
+ if(nvPairs[i]){
+ var nameValue = nvPairs[i].split("=");
+ response[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
+ }
+ }
+
+ //Set data on facade object.
+ var state = this._state[stateId];
+ var facade = state.facade;
+
+ facade._setResponseHeaders(response.responseHeaders);
+ if(response.status == 0 || response.status){
+ facade.status = parseInt(response.status, 10);
+ }
+ if(response.statusText){
+ facade.statusText = response.statusText;
+ }
+ if(response.responseText){
+ facade.responseText = response.responseText;
+
+ //Fix responseXML.
+ var contentType = facade.getResponseHeader("Content-Type");
+ if(contentType && (contentType == "application/xml" || contentType == "text/xml")){
+ facade.responseXML = dojo.dom.createDocumentFromText(response.responseText, contentType);
+ }
+ }
+ facade.readyState = 4;
+
+ this.destroyState(stateId);
+ }
+
+ this.clientFrameLoaded = function(stateId){
+ var state = this._state[stateId];
+ var facade = state.facade;
+ var clientWindow = dojo.html.iframeContentWindow(state.clientFrame);
+
+ var reqHeaders = [];
+ for(var param in facade._requestHeaders){
+ reqHeaders.push(param + ": " + facade._requestHeaders[param]);
+ }
+
+ var requestData = {
+ uri: facade._uri
+ };
+ if(reqHeaders.length > 0){
+ requestData.requestHeaders = reqHeaders.join("\r\n");
+ }
+ if(facade._method){
+ requestData.method = facade._method;
+ }
+ if(facade._bodyData){
+ requestData.data = facade._bodyData;
+ }
+
+ clientWindow.send(stateId, facade._ifpServerUrl, dojo.io.argsFromMap(requestData, "utf8"));
+ }
+
+ this.destroyState = function(stateId){
+ var state = this._state[stateId];
+ if(state){
+ delete this._state[stateId];
+ var parentNode = state.clientFrame.parentNode;
+ parentNode.removeChild(state.clientFrame);
+ state.clientFrame = null;
+ state = null;
+ }
+ }
+
+ this.createFacade = function(){
+ if(arguments && arguments[0] && arguments[0]["iframeProxyUrl"]){
+ return new dojo.io.XhrIframeFacade(arguments[0]["iframeProxyUrl"]);
+ }else{
+ return dojo.io.XhrIframeProxy.oldGetXmlhttpObject.apply(dojo.hostenv, arguments);
+ }
+ }
+}
+
+//Replace the normal XHR factory with the proxy one.
+dojo.io.XhrIframeProxy.oldGetXmlhttpObject = dojo.hostenv.getXmlhttpObject;
+dojo.hostenv.getXmlhttpObject = dojo.io.XhrIframeProxy.createFacade;
+
+/**
+ Using this a reference: http://www.w3.org/TR/XMLHttpRequest/
+
+ Does not implement the onreadystate callback since dojo.io.BrowserIO does
+ not use it.
+*/
+dojo.io.XhrIframeFacade = function(ifpServerUrl){
+ this._requestHeaders = {};
+ this._allResponseHeaders = null;
+ this._responseHeaders = {};
+ this._method = null;
+ this._uri = null;
+ this._bodyData = null;
+ this.responseText = null;
+ this.responseXML = null;
+ this.status = null;
+ this.statusText = null;
+ this.readyState = 0;
+
+ this._ifpServerUrl = ifpServerUrl;
+ this._stateId = null;
+}
+
+dojo.lang.extend(dojo.io.XhrIframeFacade, {
+ //The open method does not properly reset since Dojo does not reuse XHR objects.
+ open: function(method, uri){
+ this._method = method;
+ this._uri = uri;
+
+ this.readyState = 1;
+ },
+
+ setRequestHeader: function(header, value){
+ this._requestHeaders[header] = value;
+ },
+
+ send: function(stringData){
+ this._bodyData = stringData;
+
+ dojo.io.XhrIframeProxy.send(this);
+
+ this.readyState = 2;
+ },
+ abort: function(){
+ dojo.io.XhrIframeProxy.destroyState(this._stateId);
+ },
+
+ getAllResponseHeaders: function(){
+ return this._allResponseHeaders;
+
+ },
+
+ getResponseHeader: function(header){
+ return this._responseHeaders[header];
+ },
+
+ _setResponseHeaders: function(allHeaders){
+ if(allHeaders){
+ this._allResponseHeaders = allHeaders;
+
+ //Make sure ther are now CR characters in the headers.
+ allHeaders = allHeaders.replace(/\r/g, "");
+ var nvPairs = allHeaders.split("\n");
+ for(var i = 0; i < nvPairs.length; i++){
+ if(nvPairs[i]){
+ var nameValue = nvPairs[i].split(": ");
+ this._responseHeaders[nameValue[0]] = nameValue[1];
+ }
+ }
+ }
+ }
+});
Propchange: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/XhrIframeProxy.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/__package__.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/__package__.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/__package__.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/io/__package__.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -8,9 +8,10 @@
http://dojotoolkit.org/community/licensing.shtml
*/
-dojo.hostenv.conditionalLoadModule({
- common: ["dojo.io", false, false],
- rhino: ["dojo.io.RhinoIO", false, false],
- browser: [["dojo.io.BrowserIO", false, false], ["dojo.io.cookie", false, false]]
+dojo.kwCompoundRequire({
+ common: ["dojo.io.common"],
+ rhino: ["dojo.io.RhinoIO"],
+ browser: ["dojo.io.BrowserIO", "dojo.io.cookie"],
+ dashboard: ["dojo.io.BrowserIO", "dojo.io.cookie"]
});
-dojo.hostenv.moduleLoaded("dojo.io.*");
+dojo.provide("dojo.io.*");