[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit/javascript JavaScript.java,1.39,1.40
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-11-17 16:43:44
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv24639/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
Added support for Document.open / close
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- JavaScript.java 15 Nov 2002 03:06:10 -0000 1.39
+++ JavaScript.java 17 Nov 2002 16:43:41 -0000 1.40
@@ -119,17 +119,18 @@
handleScriptException( e, "Script '" + script + "'" );
return "";
} finally {
- Context.getCurrentContext().removeThreadLocal( "stream" );
+ discardDocumentWriteBuffer();
}
}
+
protected StringBuffer getDocumentWriteBuffer() {
- StringBuffer buffer = (StringBuffer) Context.getCurrentContext().getThreadLocal( "stream" );
- if (buffer == null) {
- buffer = new StringBuffer();
- Context.getCurrentContext().putThreadLocal( "stream", buffer );
- }
- return buffer;
+ throw new IllegalStateException( "may not run executeScript() from " + getClass() );
+ }
+
+
+ protected void discardDocumentWriteBuffer() {
+ throw new IllegalStateException( "may not run executeScript() from " + getClass() );
}
@@ -267,6 +268,11 @@
}
+ protected static String toStringIfNotUndefined( Object object ) {
+ return (object == null || Undefined.instance.equals( object )) ? null : object.toString();
+ }
+
+
/**
* Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable.
**/
@@ -429,8 +435,13 @@
}
- private String toStringIfNotUndefined( Object object ) {
- return (object == null || Undefined.instance.equals( object )) ? null : object.toString();
+ protected StringBuffer getDocumentWriteBuffer() {
+ return jsGet_document().getWriteBuffer();
+ }
+
+
+ protected void discardDocumentWriteBuffer() {
+ jsGet_document().clearWriteBuffer();
}
@@ -445,6 +456,8 @@
private ElementArray _forms;
private ElementArray _links;
private ElementArray _images;
+ private StringBuffer _writeBuffer;
+ private String _mimeType;
public String getClassName() {
@@ -490,15 +503,34 @@
}
+ public void jsFunction_open( Object mimeType ) {
+ _mimeType = toStringIfNotUndefined( mimeType );
+ }
+
+
+ public void jsFunction_close() {
+ getDelegate().replaceText( getWriteBuffer().toString(), _mimeType == null ? "text/html" : _mimeType );
+ }
+
+
public void jsFunction_write( String string ) {
- final StringBuffer documentWriteBuffer = getDocumentWriteBuffer();
- documentWriteBuffer.append( string );
+ getWriteBuffer().append( string );
}
public void jsFunction_writeln( String string ) {
- final StringBuffer documentWriteBuffer = getDocumentWriteBuffer();
- documentWriteBuffer.append( string ).append( (char) 0x0D ).append( (char) 0x0A );
+ getWriteBuffer().append( string ).append( (char) 0x0D ).append( (char) 0x0A );
+ }
+
+
+ protected StringBuffer getWriteBuffer() {
+ if (_writeBuffer == null) _writeBuffer = new StringBuffer();
+ return _writeBuffer;
+ }
+
+
+ protected void clearWriteBuffer() {
+ _writeBuffer = null;
}
|