Subversion Repositories Applications.papyrus

Rev

Rev 1372 | 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.hostenv.println = function (line) {
13
dojo.hostenv.println = function (line) {
12
	if (arguments.length > 0) {
14
	if (arguments.length > 0) {
13
		print(arguments[0]);
15
		print(arguments[0]);
14
		for (var i = 1; i < arguments.length; i++) {
16
		for (var i = 1; i < arguments.length; i++) {
15
			var valid = false;
17
			var valid = false;
16
			for (var p in arguments[i]) {
18
			for (var p in arguments[i]) {
17
				valid = true;
19
				valid = true;
18
				break;
20
				break;
19
			}
21
			}
20
			if (valid) {
22
			if (valid) {
21
				dojo.debugShallow(arguments[i]);
23
				dojo.debugShallow(arguments[i]);
22
			}
24
			}
23
		}
25
		}
24
	} else {
26
	} else {
25
		print(line);
27
		print(line);
26
	}
28
	}
27
};
29
};
28
dojo.locale = dojo.locale || java.util.Locale.getDefault().toString().replace("_", "-").toLowerCase();
30
dojo.locale = dojo.locale || java.util.Locale.getDefault().toString().replace("_", "-").toLowerCase();
29
dojo.render.name = dojo.hostenv.name_ = "rhino";
31
dojo.render.name = dojo.hostenv.name_ = "rhino";
30
dojo.hostenv.getVersion = function () {
32
dojo.hostenv.getVersion = function () {
31
	return version();
33
	return version();
32
};
34
};
33
if (dj_undef("byId")) {
35
if (dj_undef("byId")) {
34
	dojo.byId = function (id, doc) {
36
	dojo.byId = function (id, doc) {
35
		if (id && (typeof id == "string" || id instanceof String)) {
37
		if (id && (typeof id == "string" || id instanceof String)) {
36
			if (!doc) {
38
			if (!doc) {
37
				doc = document;
39
				doc = document;
38
			}
40
			}
39
			return doc.getElementById(id);
41
			return doc.getElementById(id);
40
		}
42
		}
41
		return id;
43
		return id;
42
	};
44
	};
43
}
45
}
44
dojo.hostenv.loadUri = function (uri, cb) {
46
dojo.hostenv.loadUri = function (uri, cb) {
45
	try {
47
	try {
46
		var local = (new java.io.File(uri)).exists();
48
		var local = (new java.io.File(uri)).exists();
47
		if (!local) {
49
		if (!local) {
48
			try {
50
			try {
49
				var stream = (new java.net.URL(uri)).openStream();
51
				var stream = (new java.net.URL(uri)).openStream();
50
				stream.close();
52
				stream.close();
51
			}
53
			}
52
			catch (e) {
54
			catch (e) {
53
				return false;
55
				return false;
54
			}
56
			}
55
		}
57
		}
56
		if (cb) {
58
		if (cb) {
57
			var contents = (local ? readText : readUri)(uri, "UTF-8");
59
			var contents = (local ? readText : readUri)(uri, "UTF-8");
58
			cb(eval("(" + contents + ")"));
60
			cb(eval("(" + contents + ")"));
59
		} else {
61
		} else {
60
			load(uri);
62
			load(uri);
61
		}
63
		}
62
		return true;
64
		return true;
63
	}
65
	}
64
	catch (e) {
66
	catch (e) {
65
		dojo.debug("rhino load('" + uri + "') failed. Exception: " + e);
67
		dojo.debug("rhino load('" + uri + "') failed. Exception: " + e);
66
		return false;
68
		return false;
67
	}
69
	}
68
};
70
};
69
dojo.hostenv.exit = function (exitcode) {
71
dojo.hostenv.exit = function (exitcode) {
70
	quit(exitcode);
72
	quit(exitcode);
71
};
73
};
72
function dj_rhino_current_script_via_java(depth) {
74
function dj_rhino_current_script_via_java(depth) {
73
	var optLevel = Packages.org.mozilla.javascript.Context.getCurrentContext().getOptimizationLevel();
75
	var optLevel = Packages.org.mozilla.javascript.Context.getCurrentContext().getOptimizationLevel();
74
	var caw = new java.io.CharArrayWriter();
76
	var caw = new java.io.CharArrayWriter();
75
	var pw = new java.io.PrintWriter(caw);
77
	var pw = new java.io.PrintWriter(caw);
76
	var exc = new java.lang.Exception();
78
	var exc = new java.lang.Exception();
77
	var s = caw.toString();
79
	var s = caw.toString();
78
	var matches = s.match(/[^\(]*\.js\)/gi);
80
	var matches = s.match(/[^\(]*\.js\)/gi);
79
	if (!matches) {
81
	if (!matches) {
80
		throw Error("cannot parse printStackTrace output: " + s);
82
		throw Error("cannot parse printStackTrace output: " + s);
81
	}
83
	}
82
	var fname = ((typeof depth != "undefined") && (depth)) ? matches[depth + 1] : matches[matches.length - 1];
84
	var fname = ((typeof depth != "undefined") && (depth)) ? matches[depth + 1] : matches[matches.length - 1];
83
	var fname = matches[3];
85
	var fname = matches[3];
84
	if (!fname) {
86
	if (!fname) {
85
		fname = matches[1];
87
		fname = matches[1];
86
	}
88
	}
87
	if (!fname) {
89
	if (!fname) {
88
		throw Error("could not find js file in printStackTrace output: " + s);
90
		throw Error("could not find js file in printStackTrace output: " + s);
89
	}
91
	}
90
	return fname;
92
	return fname;
91
}
93
}
92
function readText(path, encoding) {
94
function readText(path, encoding) {
93
	encoding = encoding || "utf-8";
95
	encoding = encoding || "utf-8";
94
	var jf = new java.io.File(path);
96
	var jf = new java.io.File(path);
95
	var is = new java.io.FileInputStream(jf);
97
	var is = new java.io.FileInputStream(jf);
96
	return dj_readInputStream(is, encoding);
98
	return dj_readInputStream(is, encoding);
97
}
99
}
98
function readUri(uri, encoding) {
100
function readUri(uri, encoding) {
99
	var conn = (new java.net.URL(uri)).openConnection();
101
	var conn = (new java.net.URL(uri)).openConnection();
100
	encoding = encoding || conn.getContentEncoding() || "utf-8";
102
	encoding = encoding || conn.getContentEncoding() || "utf-8";
101
	var is = conn.getInputStream();
103
	var is = conn.getInputStream();
102
	return dj_readInputStream(is, encoding);
104
	return dj_readInputStream(is, encoding);
103
}
105
}
104
function dj_readInputStream(is, encoding) {
106
function dj_readInputStream(is, encoding) {
105
	var input = new java.io.BufferedReader(new java.io.InputStreamReader(is, encoding));
107
	var input = new java.io.BufferedReader(new java.io.InputStreamReader(is, encoding));
106
	try {
108
	try {
107
		var sb = new java.lang.StringBuffer();
109
		var sb = new java.lang.StringBuffer();
108
		var line = "";
110
		var line = "";
109
		while ((line = input.readLine()) !== null) {
111
		while ((line = input.readLine()) !== null) {
110
			sb.append(line);
112
			sb.append(line);
111
			sb.append(java.lang.System.getProperty("line.separator"));
113
			sb.append(java.lang.System.getProperty("line.separator"));
112
		}
114
		}
113
		return sb.toString();
115
		return sb.toString();
114
	}
116
	}
115
	finally {
117
	finally {
116
		input.close();
118
		input.close();
117
	}
119
	}
118
}
120
}
119
if (!djConfig.libraryScriptUri.length) {
121
if (!djConfig.libraryScriptUri.length) {
120
	try {
122
	try {
121
		djConfig.libraryScriptUri = dj_rhino_current_script_via_java(1);
123
		djConfig.libraryScriptUri = dj_rhino_current_script_via_java(1);
122
	}
124
	}
123
	catch (e) {
125
	catch (e) {
124
		if (djConfig["isDebug"]) {
126
		if (djConfig["isDebug"]) {
125
			print("\n");
127
			print("\n");
126
			print("we have no idea where Dojo is located.");
128
			print("we have no idea where Dojo is located.");
127
			print("Please try loading rhino in a non-interpreted mode or set a");
129
			print("Please try loading rhino in a non-interpreted mode or set a");
128
			print("\n\tdjConfig.libraryScriptUri\n");
130
			print("\n\tdjConfig.libraryScriptUri\n");
129
			print("Setting the dojo path to './'");
131
			print("Setting the dojo path to './'");
130
			print("This is probably wrong!");
132
			print("This is probably wrong!");
131
			print("\n");
133
			print("\n");
132
			print("Dojo will try to load anyway");
134
			print("Dojo will try to load anyway");
133
		}
135
		}
134
		djConfig.libraryScriptUri = "./";
136
		djConfig.libraryScriptUri = "./";
135
	}
137
	}
136
}
138
}
137
dojo.doc = function () {
139
dojo.doc = function () {
138
	return document;
140
	return document;
139
};
141
};
140
dojo.body = function () {
142
dojo.body = function () {
141
	return document.body;
143
	return document.body;
142
};
144
};
143
function setTimeout(func, delay) {
145
function setTimeout(func, delay) {
144
	var def = {sleepTime:delay, hasSlept:false, run:function () {
146
	var def = {sleepTime:delay, hasSlept:false, run:function () {
145
		if (!this.hasSlept) {
147
		if (!this.hasSlept) {
146
			this.hasSlept = true;
148
			this.hasSlept = true;
147
			java.lang.Thread.currentThread().sleep(this.sleepTime);
149
			java.lang.Thread.currentThread().sleep(this.sleepTime);
148
		}
150
		}
149
		try {
151
		try {
150
			func();
152
			func();
151
		}
153
		}
152
		catch (e) {
154
		catch (e) {
153
			dojo.debug("Error running setTimeout thread:" + e);
155
			dojo.debug("Error running setTimeout thread:" + e);
154
		}
156
		}
155
	}};
157
	}};
156
	var runnable = new java.lang.Runnable(def);
158
	var runnable = new java.lang.Runnable(def);
157
	var thread = new java.lang.Thread(runnable);
159
	var thread = new java.lang.Thread(runnable);
158
	thread.start();
160
	thread.start();
159
}
161
}
160
dojo.requireIf((djConfig["isDebug"] || djConfig["debugAtAllCosts"]), "dojo.debug");
162
dojo.requireIf((djConfig["isDebug"] || djConfig["debugAtAllCosts"]), "dojo.debug");
161
 
163