Added better support for local file XHR, added document.innerHTML, change .valueOf() to be .outerHTML.
This commit is contained in:
parent
0bb035a1ab
commit
7c85d973bf
|
@ -187,6 +187,9 @@ var window = this;
|
||||||
return "Document" + (typeof this._file == "string" ?
|
return "Document" + (typeof this._file == "string" ?
|
||||||
": " + this._file : "");
|
": " + this._file : "");
|
||||||
},
|
},
|
||||||
|
get innerHTML(){
|
||||||
|
return this.documentElement.outerHTML;
|
||||||
|
},
|
||||||
|
|
||||||
get defaultView(){
|
get defaultView(){
|
||||||
return {
|
return {
|
||||||
|
@ -239,9 +242,9 @@ var window = this;
|
||||||
return "[ " +
|
return "[ " +
|
||||||
Array.prototype.join.call( this, ", " ) + " ]";
|
Array.prototype.join.call( this, ", " ) + " ]";
|
||||||
},
|
},
|
||||||
valueOf: function(){
|
get outerHTML(){
|
||||||
return Array.prototype.map.call(
|
return Array.prototype.map.call(
|
||||||
this, function(node){return node.valueOf();}).join('');
|
this, function(node){return node.outerHTML;}).join('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -282,7 +285,7 @@ var window = this;
|
||||||
toString: function(){
|
toString: function(){
|
||||||
return '"' + this.nodeValue + '"';
|
return '"' + this.nodeValue + '"';
|
||||||
},
|
},
|
||||||
valueOf: function(){
|
get outerHTML(){
|
||||||
return this.nodeValue;
|
return this.nodeValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -316,14 +319,14 @@ var window = this;
|
||||||
toString: function(){
|
toString: function(){
|
||||||
return "<" + this.tagName + (this.id ? "#" + this.id : "" ) + ">";
|
return "<" + this.tagName + (this.id ? "#" + this.id : "" ) + ">";
|
||||||
},
|
},
|
||||||
valueOf: function(){
|
get outerHTML(){
|
||||||
var ret = "<" + this.tagName, attr = this.attributes;
|
var ret = "<" + this.tagName, attr = this.attributes;
|
||||||
|
|
||||||
for ( var i in attr )
|
for ( var i in attr )
|
||||||
ret += " " + i + "='" + attr[i] + "'";
|
ret += " " + i + "='" + attr[i] + "'";
|
||||||
|
|
||||||
if ( this.childNodes.length || this.nodeName == "SCRIPT" )
|
if ( this.childNodes.length || this.nodeName == "SCRIPT" )
|
||||||
ret += ">" + this.childNodes.valueOf() +
|
ret += ">" + this.childNodes.outerHTML +
|
||||||
"</" + this.tagName + ">";
|
"</" + this.tagName + ">";
|
||||||
else
|
else
|
||||||
ret += "/>";
|
ret += "/>";
|
||||||
|
@ -341,7 +344,7 @@ var window = this;
|
||||||
},
|
},
|
||||||
|
|
||||||
get innerHTML(){
|
get innerHTML(){
|
||||||
return this.childNodes.valueOf();
|
return this.childNodes.outerHTML;
|
||||||
},
|
},
|
||||||
set innerHTML(html){
|
set innerHTML(html){
|
||||||
html = html.replace(/<\/?([A-Z]+)/g, function(m){
|
html = html.replace(/<\/?([A-Z]+)/g, function(m){
|
||||||
|
@ -579,47 +582,71 @@ var window = this;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
function makeRequest(){
|
function makeRequest(){
|
||||||
var url = new java.net.URL(curLocation, self.url),
|
var url = new java.net.URL(curLocation, self.url);
|
||||||
connection = url.openConnection();
|
|
||||||
|
|
||||||
// Add headers to Java connection
|
if ( url.getProtocol() == "file" ) {
|
||||||
for (var header in self.headers)
|
if ( self.method == "PUT" ) {
|
||||||
connection.addRequestProperty(header, self.headers[header]);
|
var out = new java.io.FileWriter(
|
||||||
|
new java.io.File( new java.net.URI( url.toString() ) ) ),
|
||||||
connection.connect();
|
text = new java.lang.String( data || "" );
|
||||||
|
|
||||||
// Stick the response headers into responseHeaders
|
out.write( text, 0, text.length() );
|
||||||
for (var i=0; ; i++) {
|
out.flush();
|
||||||
var headerName = connection.getHeaderFieldKey(i);
|
out.close();
|
||||||
var headerValue = connection.getHeaderField(i);
|
} else if ( self.method == "DELETE" ) {
|
||||||
if (!headerName && !headerValue) break;
|
var file = new java.io.File( new java.net.URI( url.toString() ) );
|
||||||
if (headerName)
|
file["delete"]();
|
||||||
self.responseHeaders[headerName] = headerValue;
|
} else {
|
||||||
}
|
var connection = url.openConnection();
|
||||||
|
connection.connect();
|
||||||
self.readyState = 4;
|
handleResponse();
|
||||||
self.status = parseInt(connection.responseCode);
|
}
|
||||||
self.statusText = connection.responseMessage;
|
} else {
|
||||||
|
var connection = url.openConnection();
|
||||||
var stream = new java.io.InputStreamReader(
|
|
||||||
connection.getInputStream()),
|
|
||||||
buffer = new java.io.BufferedReader(stream),
|
|
||||||
line;
|
|
||||||
|
|
||||||
while ((line = buffer.readLine()) != null)
|
|
||||||
self.responseText += line;
|
|
||||||
|
|
||||||
self.responseXML = null;
|
connection.setRequestMethod( self.method );
|
||||||
|
|
||||||
|
// Add headers to Java connection
|
||||||
|
for (var header in self.headers)
|
||||||
|
connection.addRequestProperty(header, self.headers[header]);
|
||||||
|
|
||||||
if ( self.responseText.match(/^\s*</) ) {
|
connection.connect();
|
||||||
try {
|
|
||||||
self.responseXML = new DOMDocument(
|
// Stick the response headers into responseHeaders
|
||||||
new java.io.ByteArrayInputStream(
|
for (var i = 0; ; i++) {
|
||||||
(new java.lang.String(
|
var headerName = connection.getHeaderFieldKey(i);
|
||||||
self.responseText)).getBytes("UTF8")));
|
var headerValue = connection.getHeaderField(i);
|
||||||
} catch(e) {}
|
if (!headerName && !headerValue) break;
|
||||||
|
if (headerName)
|
||||||
|
self.responseHeaders[headerName] = headerValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleResponse(){
|
||||||
|
self.readyState = 4;
|
||||||
|
self.status = parseInt(connection.responseCode) || undefined;
|
||||||
|
self.statusText = connection.responseMessage || "";
|
||||||
|
|
||||||
|
var stream = new java.io.InputStreamReader(connection.getInputStream()),
|
||||||
|
buffer = new java.io.BufferedReader(stream), line;
|
||||||
|
|
||||||
|
while ((line = buffer.readLine()) != null)
|
||||||
|
self.responseText += line;
|
||||||
|
|
||||||
|
self.responseXML = null;
|
||||||
|
|
||||||
|
if ( self.responseText.match(/^\s*</) ) {
|
||||||
|
try {
|
||||||
|
self.responseXML = new DOMDocument(
|
||||||
|
new java.io.ByteArrayInputStream(
|
||||||
|
(new java.lang.String(
|
||||||
|
self.responseText)).getBytes("UTF8")));
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.onreadystatechange();
|
self.onreadystatechange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue