[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpException.java,1.5,1.6 HttpUnitUtils.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-11-27 19:51:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv14340/src/com/meterware/httpunit
Modified Files:
HttpException.java HttpUnitUtils.java
MimeEncodedMessageBody.java NodeUtils.java ParsedHTML.java
ReceivedPage.java WebClient.java WebRequest.java
WebResponse.java WebTable.java
Log Message:
Benoit Xhenseval: optimized DOM and StringBuffer use
Index: HttpException.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpException.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpException.java 2001/11/26 14:20:12 1.5
+++ HttpException.java 2001/11/27 19:51:27 1.6
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -43,7 +43,7 @@
public String getMessage() {
- StringBuffer sb = new StringBuffer( "Error on HTTP request: " );
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE).append( "Error on HTTP request: " );
sb.append( _responseCode );
if (_responseMessage != null) {
sb.append( " " );
@@ -74,4 +74,4 @@
private String _responseMessage;
-}
+}
\ No newline at end of file
Index: HttpUnitUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpUnitUtils.java 2001/11/14 17:28:25 1.4
+++ HttpUnitUtils.java 2001/11/27 19:51:27 1.5
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -26,6 +26,9 @@
**/
public class HttpUnitUtils {
+ public static final int DEFAULT_TEXT_BUFFER_SIZE = 2048;
+ public static final int DEFAULT_BUFFER_SIZE = 128;
+
/**
* Returns the content type and encoding as a pair of strings.
* If no character set is specified, the second entry will be null.
@@ -55,8 +58,8 @@
* FIXME: currently assumes iso-8859-1 character set.
**/
public static String decode( String byteString ) {
- StringBuffer sb = new StringBuffer();
char[] chars = byteString.toCharArray();
+ StringBuffer sb = new StringBuffer(chars.length);
char[] hexNum = { '0', '0', '0' };
int i = 0;
@@ -75,5 +78,4 @@
}
return sb.toString();
}
-
-}
+}
\ No newline at end of file
Index: MimeEncodedMessageBody.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MimeEncodedMessageBody.java 2001/11/09 18:35:14 1.9
+++ MimeEncodedMessageBody.java 2001/11/27 19:51:27 1.10
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -99,8 +99,8 @@
private String encode( String string ) {
- StringBuffer sb = new StringBuffer();
char[] chars = string.toCharArray();
+ StringBuffer sb = new StringBuffer(chars.length+20);
for (int i = 0; i < chars.length; i++ ) {
if (chars[i] == '\\') {
sb.append( "\\\\" ); // accomodate MS-DOS file paths XXX is this safe??
@@ -124,4 +124,3 @@
}
-
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- NodeUtils.java 2001/11/09 18:35:14 1.7
+++ NodeUtils.java 2001/11/27 19:51:27 1.8
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -75,7 +75,7 @@
* any HTML tags.
**/
public static String asText( NodeList rootNodes ) {
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
Stack pendingNodes = new Stack();
pushNodeList( rootNodes, pendingNodes );
@@ -98,9 +98,9 @@
} else if (node.getNodeName().equalsIgnoreCase( "td" )) {
sb.append( " | " );
} else if (node.getNodeName().equalsIgnoreCase( "th" )) {
- sb.append( " | " );
+ sb.append( " | " );
} else if (node.getNodeName().equalsIgnoreCase( "img" ) && HttpUnitOptions.getImagesTreatedAsAltText()) {
- sb.append( getNodeAttribute( node, "alt" ) );
+ sb.append( getNodeAttribute( node, "alt" ) );
}
pushNodeList( node.getChildNodes(), pendingNodes );
@@ -126,4 +126,4 @@
}
}
-}
+}
\ No newline at end of file
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ParsedHTML.java 2001/10/25 14:51:05 1.18
+++ ParsedHTML.java 2001/11/27 19:51:27 1.19
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -25,6 +25,10 @@
import org.w3c.dom.*;
+/**
+ * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
class ParsedHTML {
@@ -170,7 +174,7 @@
* they appear.
**/
public WebTable[] getTables() {
- return WebTable.getTables( getDOM(), _baseURL, _baseTarget, _characterSet );
+ return WebTable.getTables( getOriginalDOM(), _baseURL, _baseTarget, _characterSet );
}
@@ -188,10 +192,10 @@
}
} );
}
-
-
+
+
/**
- * Returns the first table in the response which has the specified text as a prefix of the text
+ * Returns the first table in the response which has the specified text as a prefix of the text
* in its first non-blank row and non-blank column. Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
**/
@@ -204,10 +208,10 @@
}
} );
}
-
-
+
+
/**
- * Returns the first table in the response which has the specified text as its summary attribute.
+ * Returns the first table in the response which has the specified text as its summary attribute.
* Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
**/
@@ -218,10 +222,10 @@
}
} );
}
-
-
+
+
/**
- * Returns the first table in the response which has the specified text as its ID attribute.
+ * Returns the first table in the response which has the specified text as its ID attribute.
* Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
**/
@@ -232,8 +236,8 @@
}
} );
}
-
-
+
+
/**
* Returns a copy of the domain object model associated with this page.
**/
@@ -241,6 +245,14 @@
return _rootNode.cloneNode( /* deep */ true );
}
+ /**
+ * Returns the domain object model associated with this page, to be used internally.
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
+ Node getOriginalDOM() {
+ return _rootNode;
+ }
+
//---------------------------------- Object methods --------------------------------
@@ -371,4 +383,4 @@
return null;
}
-}
+}
\ No newline at end of file
Index: ReceivedPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ReceivedPage.java 2001/11/14 17:11:28 1.17
+++ ReceivedPage.java 2001/11/27 19:51:27 1.18
@@ -53,7 +53,7 @@
* Returns the title of the page.
**/
public String getTitle() throws SAXException {
- NodeList nl = ((Document) getDOM()).getElementsByTagName( "title" );
+ NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName( "title" );
if (nl.getLength() == 0) return "";
if (!nl.item(0).hasChildNodes()) return "";
return nl.item(0).getFirstChild().getNodeValue();
@@ -67,7 +67,7 @@
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
public String getExternalStyleSheet() throws SAXException {
- NodeList nl = ((Document) getDOM()).getElementsByTagName( "link" );
+ NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName( "link" );
int length = nl.getLength();
if (length == 0) return "";
@@ -94,7 +94,7 @@
**/
public String[] getMetaTagContent(String attribute, String attributeValue) {
Vector matches = new Vector();
- NodeList nl = ((Document) getDOM()).getElementsByTagName("meta");
+ NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName("meta");
int length = nl.getLength();
for (int i = 0; i < length; i++) {
@@ -133,7 +133,7 @@
private void setBaseAttributes() throws SAXException {
- NodeList nl = ((Document) getDOM()).getElementsByTagName( "base" );
+ NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName( "base" );
if (nl.getLength() == 0) return;
try {
applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ),
@@ -165,4 +165,4 @@
return tidy;
}
-}
+}
\ No newline at end of file
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- WebClient.java 2001/11/26 14:20:12 1.12
+++ WebClient.java 2001/11/27 19:51:27 1.13
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2001, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -39,9 +39,9 @@
*
* @author Russell Gold
* @author Jan Ohrstrom
- * @author Seth Ladd
+ * @author Seth Ladd
**/
-abstract
+abstract
public class WebClient {
@@ -121,15 +121,15 @@
return (String) _cookies.get( name );
}
-
+
/**
* Specifies the user agent identification. Used to trigger browser-specific server behavior.
- **/
+ **/
public void setUserAgent( String userAgent ) {
setHeaderField( "User-Agent", userAgent );
}
-
-
+
+
/**
* Returns the current user agent setting.
**/
@@ -178,20 +178,20 @@
**/
protected String getCookieHeaderField() {
String names[] = getCookieNames();
- if (names.length == 0) return null;
-
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < names.length; i++) {
+ if (names.length == 0) return null;
+
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
+ for (int i = 0; i < names.length; i++) {
if (i != 0) sb.append( "; " );
- String name = names[i];
- sb.append( name ).append( '=' ).append( getCookieValue( name ) );
- }
+ String name = names[i];
+ sb.append( name ).append( '=' ).append( getCookieValue( name ) );
+ }
return sb.toString();
}
/**
- * Returns the value of all current header fields.
+ * Returns the value of all current header fields.
**/
protected Dictionary getHeaderFields() {
Hashtable result = (Hashtable) _headers.clone();
@@ -375,8 +375,8 @@
}
}
-
+
//==================================================================================================
@@ -394,4 +394,3 @@
private String _frameName;
}
-
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- WebRequest.java 2001/11/26 14:20:12 1.30
+++ WebRequest.java 2001/11/27 19:51:27 1.31
@@ -333,10 +333,9 @@
return _parameters.size() == 0;
}
-
final
protected String getParameterString() {
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
Enumeration e = _parameters.keys();
while (e.hasMoreElements()) {
@@ -496,7 +495,7 @@
} else {
try {
byte[] rawBytes = source.getBytes( _sourceForm.getCharacterSet() );
- StringBuffer result = new StringBuffer();
+ StringBuffer result = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
for (int i = 0; i < rawBytes.length; i++) {
int candidate = rawBytes[i] & 0xff;
if (candidate == ' ') {
@@ -677,7 +676,7 @@
public String getMessage() {
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
sb.append( "May not set parameter '" ).append( _parameterName ).append( "' to '" );
sb.append( _badValue ).append( "'. Value must be one of: { " );
for (int i = 0; i < _allowedValues.length; i++) {
@@ -712,7 +711,7 @@
public String getMessage() {
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
sb.append( "Parameter '" ).append( _parameterName ).append( "' must have the value '" );
sb.append( _missingValue ).append( "'. Attempted to set it to: { " );
for (int i = 0; i < _proposedValues.length; i++) {
@@ -844,4 +843,3 @@
}
-
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- WebResponse.java 2001/11/14 14:40:09 1.54
+++ WebResponse.java 2001/11/27 19:51:27 1.55
@@ -776,7 +776,7 @@
private void addFrameTags( Vector list, String frameTagName ) throws SAXException {
- NodeList nl = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), frameTagName );
+ NodeList nl = NodeUtils.getElementsByTagName( getReceivedPage().getOriginalDOM(), frameTagName );
for (int i = 0; i < nl.getLength(); i++) {
Node child = nl.item(i);
list.addElement( new WebFrame( getReceivedPage().getBaseURL(), child ) );
@@ -1039,4 +1039,3 @@
private String _contentType;
}
-
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- WebTable.java 2001/10/25 17:30:03 1.14
+++ WebTable.java 2001/11/27 19:51:27 1.15
@@ -97,7 +97,7 @@
for (int i = 0; i < getRowCount(); i++) {
for (int j = 0; j < getColumnCount(); j++) {
if (_cells[i][j]!=null) {
- idToCompare = NodeUtils.getNodeAttribute( _cells[i][j].getDOM(), "id" );
+ idToCompare = NodeUtils.getNodeAttribute( _cells[i][j].getOriginalDOM(), "id" );
if (HttpUnitOptions.getMatchesIgnoreCase())
if (id.equalsIgnoreCase(idToCompare))
return _cells[i][j];
@@ -210,7 +210,7 @@
public String toString() {
String eol = System.getProperty( "line.separator" );
if (_cells == null) readTable();
- StringBuffer sb = new StringBuffer( "WebTable:" ).append( eol );
+ StringBuffer sb = new StringBuffer( HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE).append("WebTable:" ).append( eol );
for (int i = 0; i < _cells.length; i++) {
sb.append( "[" ).append( i ).append( "]: " );
for (int j = 0; j < _cells[i].length; j++) {
@@ -404,7 +404,6 @@
}
-
|