[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit ParsedHTML.java,1.17,1.18 ReceivedPage.ja
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-10-25 14:51:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv19806/src/com/meterware/httpunit
Modified Files:
ParsedHTML.java ReceivedPage.java WebForm.java
WebRequestSource.java WebResponse.java
Log Message:
Added search for link by name and id
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ParsedHTML.java 2001/07/31 16:08:59 1.17
+++ ParsedHTML.java 2001/10/25 14:51:05 1.18
@@ -57,7 +57,8 @@
public WebForm getFormWithID( String ID ) {
WebForm[] forms = getForms();
for (int i = 0; i < forms.length; i++) {
- if (forms[i].getID().equalsIgnoreCase( ID )) return forms[i];
+ if (forms[i].getID().equals( ID )) return forms[i];
+ else if (HttpUnitOptions.getMatchesIgnoreCase() && forms[i].getID().equalsIgnoreCase( ID )) return forms[i];
}
return null;
}
@@ -70,7 +71,8 @@
public WebForm getFormWithName( String name ) {
WebForm[] forms = getForms();
for (int i = 0; i < forms.length; i++) {
- if (forms[i].getName().equalsIgnoreCase( name )) return forms[i];
+ if (forms[i].getName().equals( name )) return forms[i];
+ else if (HttpUnitOptions.getMatchesIgnoreCase() && forms[i].getName().equalsIgnoreCase( name )) return forms[i];
}
return null;
}
@@ -130,6 +132,34 @@
return links[i];
}
}
+ }
+ return null;
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified ID.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebLink getLinkWithID( String ID ) {
+ WebLink[] links = getLinks();
+ for (int i = 0; i < links.length; i++) {
+ if (links[i].getID().equals( ID )) return links[i];
+ else if (HttpUnitOptions.getMatchesIgnoreCase() && links[i].getID().equalsIgnoreCase( ID )) return links[i];
+ }
+ return null;
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified name.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebLink getLinkWithName( String name ) {
+ WebLink[] links = getLinks();
+ for (int i = 0; i < links.length; i++) {
+ if (links[i].getName().equals( name )) return links[i];
+ else if (HttpUnitOptions.getMatchesIgnoreCase() && links[i].getName().equalsIgnoreCase( name )) return links[i];
}
return null;
}
Index: ReceivedPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ReceivedPage.java 2001/10/25 14:15:59 1.13
+++ ReceivedPage.java 2001/10/25 14:51:05 1.14
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* 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
@@ -76,30 +76,33 @@
/**
- * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue.
+ * Retrieves the "content" of the meta tags for a key pair attribute-attributeValue.
* <code>
- * <meta name="robots" content="index,follow" />
- <meta http-equiv="Expires" content="now" />
+ * <meta name="robots" content="index" />
+ * <meta name="robots" content="follow" />
+ * <meta http-equiv="Expires" content="now" />
* </code>
* this can be used like this
* <code>
- * getMetaTagContent("name","robots") will return "index,follow"
- * getMetaTagContent("http-equiv","Expires") will return "now"
+ * getMetaTagContent("name","robots") will return { "index","follow" }
+ * getMetaTagContent("http-equiv","Expires") will return { "now" }
* </code>
- * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
- public String getMetaTagContent(String attribute, String attributeValue) {
+ public String[] getMetaTagContent(String attribute, String attributeValue) {
+ Vector matches = new Vector();
NodeList nl = ((Document) getDOM()).getElementsByTagName("meta");
int length = nl.getLength();
- if (length == 0) return "";
for (int i = 0; i < length; i++) {
if (attributeValue.equalsIgnoreCase(NodeUtils.getNodeAttribute(nl.item(i), attribute))) {
- return NodeUtils.getNodeAttribute(nl.item(i), "content");
+ matches.addElement( NodeUtils.getNodeAttribute( nl.item(i), "content" ) );
}
}
- return "";
+ String result[] = new String[ matches.size() ];
+ matches.copyInto( result );
+ return result;
}
+
private static Node getDOM( String pageText ) throws SAXException {
try {
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- WebForm.java 2001/10/19 19:16:57 1.27
+++ WebForm.java 2001/10/25 14:51:05 1.28
@@ -57,14 +57,6 @@
}
- /**
- * Returns the name of the form.
- **/
- public String getName() {
- return NodeUtils.getNodeAttribute( getNode(), "name" );
- }
-
-
/**
* Returns an array containing the names of the parameters defined for this form,
* in the order in which they appear.
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebRequestSource.java 2001/07/31 16:08:59 1.1
+++ WebRequestSource.java 2001/10/25 14:51:05 1.2
@@ -37,6 +37,14 @@
/**
+ * Returns the name associated with this request source.
+ **/
+ public String getName() {
+ return NodeUtils.getNodeAttribute( _node, "name" );
+ }
+
+
+ /**
* Returns the target for this request source.
**/
public String getTarget() {
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- WebResponse.java 2001/10/25 14:15:59 1.49
+++ WebResponse.java 2001/10/25 14:51:05 1.50
@@ -108,20 +108,20 @@
}
/**
- * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue.
+ * Retrieves the "content" of the meta tags for a key pair attribute-attributeValue.
* <code>
- * <meta name="robots" content="index,follow" />
- * <meta http-equiv="Expires" content="now" />
+ * <meta name="robots" content="index" />
+ * <meta name="robots" content="follow" />
+ * <meta http-equiv="Expires" content="now" />
* </code>
- * can be used as follows:
+ * this can be used like this
* <code>
- * getMetaTagContent("name","robots") will return "index,follow"
- * getMetaTagContent("http-equiv","Expires") will return "now"
+ * getMetaTagContent("name","robots") will return { "index","follow" }
+ * getMetaTagContent("http-equiv","Expires") will return { "now" }
* </code>
* @exception SAXException thrown if there is an error parsing this response
- * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
- public String getMetaTagContent(String attribute, String attributeValue) throws SAXException {
+ public String[] getMetaTagContent(String attribute, String attributeValue) throws SAXException {
return getReceivedPage().getMetaTagContent(attribute, attributeValue);
}
@@ -304,6 +304,24 @@
**/
public WebLink getLinkWithImageText( String text ) throws SAXException {
return getReceivedPage().getLinkWithImageText( text );
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified name.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebLink getLinkWithName( String name ) throws SAXException {
+ return getReceivedPage().getLinkWithName( name );
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified ID.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebLink getLinkWithID( String ID ) throws SAXException {
+ return getReceivedPage().getLinkWithID( ID );
}
|