Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.render.name = dojo.hostenv.name_ = "dashboard";
13
dojo.render.name = dojo.hostenv.name_ = "dashboard";
12
dojo.hostenv.println = function (message) {
14
dojo.hostenv.println = function (message) {
13
	return alert(message);
15
	return alert(message);
14
};
16
};
15
dojo.hostenv.getXmlhttpObject = function (kwArgs) {
17
dojo.hostenv.getXmlhttpObject = function (kwArgs) {
16
	if (widget.system && kwArgs) {
18
	if (widget.system && kwArgs) {
17
		if ((kwArgs.contentType && kwArgs.contentType.indexOf("text/") != 0) || (kwArgs.headers && kwArgs.headers["content-type"] && kwArgs.headers["content-type"].indexOf("text/") != 0)) {
19
		if ((kwArgs.contentType && kwArgs.contentType.indexOf("text/") != 0) || (kwArgs.headers && kwArgs.headers["content-type"] && kwArgs.headers["content-type"].indexOf("text/") != 0)) {
18
			var curl = new dojo.hostenv.CurlRequest;
20
			var curl = new dojo.hostenv.CurlRequest;
19
			curl._save = true;
21
			curl._save = true;
20
			return curl;
22
			return curl;
21
		} else {
23
		} else {
22
			if (kwArgs.method && kwArgs.method.toUpperCase() == "HEAD") {
24
			if (kwArgs.method && kwArgs.method.toUpperCase() == "HEAD") {
23
				return new dojo.hostenv.CurlRequest;
25
				return new dojo.hostenv.CurlRequest;
24
			} else {
26
			} else {
25
				if (kwArgs.headers && kwArgs.header.referer) {
27
				if (kwArgs.headers && kwArgs.header.referer) {
26
					return new dojo.hostenv.CurlRequest;
28
					return new dojo.hostenv.CurlRequest;
27
				}
29
				}
28
			}
30
			}
29
		}
31
		}
30
	}
32
	}
31
	return new XMLHttpRequest;
33
	return new XMLHttpRequest;
32
};
34
};
33
dojo.hostenv.CurlRequest = function () {
35
dojo.hostenv.CurlRequest = function () {
34
	this.onreadystatechange = null;
36
	this.onreadystatechange = null;
35
	this.readyState = 0;
37
	this.readyState = 0;
36
	this.responseText = "";
38
	this.responseText = "";
37
	this.responseXML = null;
39
	this.responseXML = null;
38
	this.status = 0;
40
	this.status = 0;
39
	this.statusText = "";
41
	this.statusText = "";
40
	this._method = "";
42
	this._method = "";
41
	this._url = "";
43
	this._url = "";
42
	this._async = true;
44
	this._async = true;
43
	this._referrer = "";
45
	this._referrer = "";
44
	this._headers = [];
46
	this._headers = [];
45
	this._save = false;
47
	this._save = false;
46
	this._responseHeader = "";
48
	this._responseHeader = "";
47
	this._responseHeaders = {};
49
	this._responseHeaders = {};
48
	this._fileName = "";
50
	this._fileName = "";
49
	this._username = "";
51
	this._username = "";
50
	this._password = "";
52
	this._password = "";
51
};
53
};
52
dojo.hostenv.CurlRequest.prototype.open = function (method, url, async, username, password) {
54
dojo.hostenv.CurlRequest.prototype.open = function (method, url, async, username, password) {
53
	this._method = method;
55
	this._method = method;
54
	this._url = url;
56
	this._url = url;
55
	if (async) {
57
	if (async) {
56
		this._async = async;
58
		this._async = async;
57
	}
59
	}
58
	if (username) {
60
	if (username) {
59
		this._username = username;
61
		this._username = username;
60
	}
62
	}
61
	if (password) {
63
	if (password) {
62
		this._password = password;
64
		this._password = password;
63
	}
65
	}
64
};
66
};
65
dojo.hostenv.CurlRequest.prototype.setRequestHeader = function (label, value) {
67
dojo.hostenv.CurlRequest.prototype.setRequestHeader = function (label, value) {
66
	switch (label) {
68
	switch (label) {
67
	  case "Referer":
69
	  case "Referer":
68
		this._referrer = value;
70
		this._referrer = value;
69
		break;
71
		break;
70
	  case "content-type":
72
	  case "content-type":
71
		break;
73
		break;
72
	  default:
74
	  default:
73
		this._headers.push(label + "=" + value);
75
		this._headers.push(label + "=" + value);
74
		break;
76
		break;
75
	}
77
	}
76
};
78
};
77
dojo.hostenv.CurlRequest.prototype.getAllResponseHeaders = function () {
79
dojo.hostenv.CurlRequest.prototype.getAllResponseHeaders = function () {
78
	return this._responseHeader;
80
	return this._responseHeader;
79
};
81
};
80
dojo.hostenv.CurlRequest.prototype.getResponseHeader = function (headerLabel) {
82
dojo.hostenv.CurlRequest.prototype.getResponseHeader = function (headerLabel) {
81
	return this._responseHeaders[headerLabel];
83
	return this._responseHeaders[headerLabel];
82
};
84
};
83
dojo.hostenv.CurlRequest.prototype.send = function (content) {
85
dojo.hostenv.CurlRequest.prototype.send = function (content) {
84
	this.readyState = 1;
86
	this.readyState = 1;
85
	if (this.onreadystatechange) {
87
	if (this.onreadystatechange) {
86
		this.onreadystatechange.call(this);
88
		this.onreadystatechange.call(this);
87
	}
89
	}
88
	var query = {sS:""};
90
	var query = {sS:""};
89
	if (this._referrer) {
91
	if (this._referrer) {
90
		query.e = this._referrer;
92
		query.e = this._referrer;
91
	}
93
	}
92
	if (this._headers.length) {
94
	if (this._headers.length) {
93
		query.H = this._headers.join("&");
95
		query.H = this._headers.join("&");
94
	}
96
	}
95
	if (this._username) {
97
	if (this._username) {
96
		if (this._password) {
98
		if (this._password) {
97
			query.u = this._username + ":" + this._password;
99
			query.u = this._username + ":" + this._password;
98
		} else {
100
		} else {
99
			query.u = this._username;
101
			query.u = this._username;
100
		}
102
		}
101
	}
103
	}
102
	if (content) {
104
	if (content) {
103
		query.d = this.content;
105
		query.d = this.content;
104
		if (this._method != "POST") {
106
		if (this._method != "POST") {
105
			query.G = "";
107
			query.G = "";
106
		}
108
		}
107
	}
109
	}
108
	if (this._method == "HEAD") {
110
	if (this._method == "HEAD") {
109
		query.I = "";
111
		query.I = "";
110
	} else {
112
	} else {
111
		if (this._save) {
113
		if (this._save) {
112
			query.I = "";
114
			query.I = "";
113
		} else {
115
		} else {
114
			query.i = "";
116
			query.i = "";
115
		}
117
		}
116
	}
118
	}
117
	var system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
119
	var system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
118
	this.readyState = 2;
120
	this.readyState = 2;
119
	if (this.onreadystatechange) {
121
	if (this.onreadystatechange) {
120
		this.onreadystatechange.call(this);
122
		this.onreadystatechange.call(this);
121
	}
123
	}
122
	if (system.errorString) {
124
	if (system.errorString) {
123
		this.responseText = system.errorString;
125
		this.responseText = system.errorString;
124
		this.status = 0;
126
		this.status = 0;
125
	} else {
127
	} else {
126
		if (this._save) {
128
		if (this._save) {
127
			this._responseHeader = system.outputString;
129
			this._responseHeader = system.outputString;
128
		} else {
130
		} else {
129
			var split = system.outputString.replace(/\r/g, "").split("\n\n", 2);
131
			var split = system.outputString.replace(/\r/g, "").split("\n\n", 2);
130
			this._responseHeader = split[0];
132
			this._responseHeader = split[0];
131
			this.responseText = split[1];
133
			this.responseText = split[1];
132
		}
134
		}
133
		split = this._responseHeader.split("\n");
135
		split = this._responseHeader.split("\n");
134
		this.statusText = split.shift();
136
		this.statusText = split.shift();
135
		this.status = this.statusText.split(" ")[1];
137
		this.status = this.statusText.split(" ")[1];
136
		for (var i = 0, header; header = split[i]; i++) {
138
		for (var i = 0, header; header = split[i]; i++) {
137
			var header_split = header.split(": ", 2);
139
			var header_split = header.split(": ", 2);
138
			this._responseHeaders[header_split[0]] = header_split[1];
140
			this._responseHeaders[header_split[0]] = header_split[1];
139
		}
141
		}
140
		if (this._save) {
142
		if (this._save) {
141
			widget.system("/bin/mkdir cache", null);
143
			widget.system("/bin/mkdir cache", null);
142
			this._fileName = this._url.split("/").pop().replace(/\W/g, "");
144
			this._fileName = this._url.split("/").pop().replace(/\W/g, "");
143
			this._fileName += "." + this._responseHeaders["Content-Type"].replace(/[\r\n]/g, "").split("/").pop();
145
			this._fileName += "." + this._responseHeaders["Content-Type"].replace(/[\r\n]/g, "").split("/").pop();
144
			delete query.I;
146
			delete query.I;
145
			query.o = "cache/" + this._fileName;
147
			query.o = "cache/" + this._fileName;
146
			system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
148
			system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
147
			if (!system.errorString) {
149
			if (!system.errorString) {
148
				this.responseText = "cache/" + this._fileName;
150
				this.responseText = "cache/" + this._fileName;
149
			}
151
			}
150
		} else {
152
		} else {
151
			if (this._method == "HEAD") {
153
			if (this._method == "HEAD") {
152
				this.responseText = this._responseHeader;
154
				this.responseText = this._responseHeader;
153
			}
155
			}
154
		}
156
		}
155
	}
157
	}
156
	this.readyState = 4;
158
	this.readyState = 4;
157
	if (this.onreadystatechange) {
159
	if (this.onreadystatechange) {
158
		this.onreadystatechange.call(this);
160
		this.onreadystatechange.call(this);
159
	}
161
	}
160
};
162
};
161
dojo.hostenv.CurlRequest._formatCall = function (query, url) {
163
dojo.hostenv.CurlRequest._formatCall = function (query, url) {
162
	var call = ["/usr/bin/curl"];
164
	var call = ["/usr/bin/curl"];
163
	for (var key in query) {
165
	for (var key in query) {
164
		if (query[key] != "") {
166
		if (query[key] != "") {
165
			call.push("-" + key + " '" + query[key].replace(/'/g, "'") + "'");
167
			call.push("-" + key + " '" + query[key].replace(/'/g, "'") + "'");
166
		} else {
168
		} else {
167
			call.push("-" + key);
169
			call.push("-" + key);
168
		}
170
		}
169
	}
171
	}
170
	call.push("'" + url.replace(/'/g, "'") + "'");
172
	call.push("'" + url.replace(/'/g, "'") + "'");
171
	return call.join(" ");
173
	return call.join(" ");
172
};
174
};
173
dojo.hostenv.exit = function () {
175
dojo.hostenv.exit = function () {
174
	if (widget.system) {
176
	if (widget.system) {
175
		widget.system("/bin/rm -rf cache/*", null);
177
		widget.system("/bin/rm -rf cache/*", null);
176
	}
178
	}
177
};
179
};
178
 
180