[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit Button.java,1.9,1.10 HTMLSegment.java,1.9
Brought to you by:
russgold
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv1669/src/com/meterware/httpunit
Modified Files:
Button.java HTMLSegment.java ParsedHTML.java WebClient.java
WebForm.java WebLink.java WebResponse.java
Log Message:
Resolve several feature requests
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Button.java 23 May 2003 03:09:27 -0000 1.9
+++ Button.java 23 Jun 2003 23:54:03 -0000 1.10
@@ -64,7 +64,16 @@
* For a submit button this typically submits the form.
*/
public void click() throws IOException, SAXException {
+ if (isDisabled()) throw new IllegalStateException( "Button" + (getName().length() == 0 ? "" : " '" + getName() + "'") + " is disabled and may not be clicked." );
if (doOnClickEvent()) doButtonAction();
+ }
+
+
+ /**
+ * Returns true if this button is disabled, meaning that it cannot be clicked.
+ **/
+ public boolean isDisabled() {
+ return super.isDisabled();
}
Index: HTMLSegment.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLSegment.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HTMLSegment.java 4 Apr 2003 14:51:27 -0000 1.9
+++ HTMLSegment.java 23 Jun 2003 23:54:03 -0000 1.10
@@ -58,6 +58,20 @@
/**
+ * Returns the first form found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebForm getFirstMatchingForm( HTMLElementPredicate predicate, Object value ) throws SAXException;
+
+
+ /**
+ * Returns all forms found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebForm[] getMatchingForms( HTMLElementPredicate predicate, Object criteria ) throws SAXException;
+
+
+ /**
* Returns the links found in this HTML segment in the order in which they appear.
* @exception SAXException thrown if there is an error parsing the segment.
**/
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- ParsedHTML.java 4 Apr 2003 14:51:27 -0000 1.48
+++ ParsedHTML.java 23 Jun 2003 23:54:03 -0000 1.49
@@ -222,14 +222,35 @@
/**
- * Returns the form found in the page with the specified name.
- **/
- public WebForm getFormWithName( String name ) {
+ * Returns the first link found in the page matching the specified criteria.
+ **/
+ public WebForm getFirstMatchingForm( HTMLElementPredicate predicate, Object criteria ) {
WebForm[] forms = getForms();
for (int i = 0; i < forms.length; i++) {
- if (HttpUnitUtils.matches( name, forms[i].getName() )) return forms[i];
+ if (predicate.matchesCriteria( forms[i], criteria )) return forms[i];
}
return null;
+ }
+
+
+ /**
+ * Returns all links found in the page matching the specified criteria.
+ **/
+ public WebForm[] getMatchingForms( HTMLElementPredicate predicate, Object criteria ) {
+ ArrayList matches = new ArrayList();
+ WebForm[] forms = getForms();
+ for (int i = 0; i < forms.length; i++) {
+ if (predicate.matchesCriteria( forms[i], criteria )) matches.add( forms[i] );
+ }
+ return (WebForm[]) matches.toArray( new WebForm[ matches.size() ] );
+ }
+
+
+ /**
+ * Returns the form found in the page with the specified name.
+ **/
+ public WebForm getFormWithName( String name ) {
+ return getFirstMatchingForm( WebForm.MATCH_NAME, name );
}
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- WebClient.java 16 Mar 2003 17:22:38 -0000 1.50
+++ WebClient.java 23 Jun 2003 23:54:03 -0000 1.51
@@ -220,6 +220,15 @@
/**
+ * Clears the proxy server settings. Note that at present this is global to all web clients in the VM.
+ */
+ public void clearProxyServer() {
+ System.getProperties().remove( "proxyHost" );
+ System.getProperties().remove( "proxyPort" );
+ }
+
+
+ /**
* Returns the name of the active proxy server.
*/
public String getProxyHost() {
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- WebForm.java 23 May 2003 03:09:27 -0000 1.84
+++ WebForm.java 23 Jun 2003 23:54:03 -0000 1.85
@@ -46,6 +46,9 @@
private Button[] _buttons;
+ /** Predicate to match a link's name. **/
+ public final static HTMLElementPredicate MATCH_NAME;
+
/**
* Submits this form using the web client from which it was originally obtained.
**/
@@ -748,6 +751,17 @@
}
}
+
+ static {
+ MATCH_NAME = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object htmlElement, Object criteria ) {
+ return HttpUnitUtils.matches( ((WebForm) htmlElement).getName(), (String) criteria );
+ };
+ };
+
+ }
+
+
//===========================---===== exception class NoSuchParameterException =========================================
@@ -829,7 +843,7 @@
/**
* This exception is thrown on an attempt to define a form request with a button not defined on that form.
**/
- class DisabledSubmitButtonException extends IllegalRequestParameterException {
+ class DisabledSubmitButtonException extends IllegalStateException {
DisabledSubmitButtonException( SubmitButton button ) {
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- WebLink.java 14 Mar 2003 17:41:28 -0000 1.40
+++ WebLink.java 23 Jun 2003 23:54:03 -0000 1.41
@@ -42,6 +42,9 @@
/** Predicate to match part or all of a link's URL string. **/
public final static HTMLElementPredicate MATCH_URL_STRING;
+ /** Predicate to match a link's text exactly. **/
+ public final static HTMLElementPredicate MATCH_TEXT;
+
/** Predicate to match part or all of a link's contained text. **/
public final static HTMLElementPredicate MATCH_CONTAINED_TEXT;
@@ -178,6 +181,14 @@
return HttpUnitUtils.contains( ((WebLink) htmlElement).getURLString(), (String) criteria );
};
};
+
+
+ MATCH_TEXT = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object htmlElement, Object criteria ) {
+ return HttpUnitUtils.matches( ((WebLink) htmlElement).asText(), (String) criteria );
+ };
+ };
+
MATCH_CONTAINED_TEXT = new HTMLElementPredicate() {
public boolean matchesCriteria( Object htmlElement, Object criteria ) {
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -r1.119 -r1.120
--- WebResponse.java 4 May 2003 15:38:03 -0000 1.119
+++ WebResponse.java 23 Jun 2003 23:54:03 -0000 1.120
@@ -315,6 +315,24 @@
/**
+ * Returns the first form found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebForm getFirstMatchingForm( HTMLElementPredicate predicate, Object criteria ) throws SAXException {
+ return getReceivedPage().getFirstMatchingForm( predicate, criteria );
+ }
+
+
+ /**
+ * Returns all forms found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebForm[] getMatchingForms( HTMLElementPredicate predicate, Object criteria ) throws SAXException {
+ return getReceivedPage().getMatchingForms( predicate, criteria );
+ }
+
+
+ /**
* Returns the links found in the page in the order in which they appear.
* @exception SAXException thrown if there is an error parsing the response.
**/
|