Opened 13 years ago

Closed 13 years ago

#1323 closed defect (fixed)

hostenv_rhino.js: dojo.hostenv.loadUri and readText don't handle URLs

Reported by: tim@… Owned by: Adam Peller
Priority: high Milestone:
Component: BuildTools Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

dojo.hostenv.loadUri contains the following line:

(new java.io.URL(uri)).openStream();

There is no such thing as java.io.URL; that should be java.net.URL

Later on in the same file, the readText function only looks for a local file. It would be useful (and consistent) if it behaved like dojo.hostenv.loadUri and loaded resources via URL, too. The following code would do just that:

function readText(uri){
	// NOTE: we intentionally avoid handling exceptions, since the caller will
	// want to know
	var sb = new java.lang.StringBuffer();
	var reader;
	try {
		// try loading it as an external resource first
		reader = new java.io.InputStreamReader((new java.net.URL(uri)).openStream());
	}
	catch (e) {
 		// fallback on loading it as a local file
 		reader = new java.io.FileReader(new java.io.File(uri));
	}
	var input = new java.io.BufferedReader(reader);
	var line = "";
	while((line = input.readLine()) != null){
		sb.append(line);
		sb.append(java.lang.System.getProperty("line.separator"));
	}
	return sb.toString();
}

Change History (3)

comment:1 Changed 13 years ago by guest

Summary: hostenv_rhino: dojo.hostenv.loadUri and readText don't handle URLshostenv_rhino.js: dojo.hostenv.loadUri and readText don't handle URLs

comment:2 Changed 13 years ago by Adam Peller

Owner: changed from alex to Adam Peller

I fixed the java.io.URL reference and tried to implement uri and local uri loading in r5009. Please re-open if that doesn't work for you or you think improvements can still be made. I also tried to accomodate explicit UTF-8 encoding as well as the new loadUri arguments. I would have liked to just use the new built-in Rhino features to read uris and files, but that's a 1.6 thing. Perhaps we can put in something so it uses that feature if it's available?

comment:3 Changed 13 years ago by Adam Peller

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.