[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit ReceivedPage.java,1.12,1.13 WebResponse.j
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-10-25 14:16:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10521/src/com/meterware/httpunit
Modified Files:
ReceivedPage.java WebResponse.java
Log Message:
Benoit Xhenseval: Added getStylesheet and getMetaTagContent
Index: ReceivedPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ReceivedPage.java 2001/02/02 14:34:29 1.12
+++ ReceivedPage.java 2001/10/25 14:15:59 1.13
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000, 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
@@ -36,6 +36,9 @@
/**
* This class represents an HTML page returned from a request.
+ *
+ * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
class ReceivedPage extends ParsedHTML {
@@ -56,6 +59,47 @@
return nl.item(0).getFirstChild().getNodeValue();
}
+ /**
+ * Returns the location of the linked stylesheet in the head
+ * <code>
+ * <link type="text/css" rel="stylesheet" href="/mystyle.css" />
+ * </code>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
+ public String getExternalStyleSheet() throws SAXException {
+ NodeList nl = ((Document) getDOM()).getElementsByTagName( "link" );
+ if (nl.getLength() == 0) return "";
+ if ("stylesheet".equalsIgnoreCase(NodeUtils.getNodeAttribute( nl.item(0), "rel" )))
+ return NodeUtils.getNodeAttribute( nl.item(0), "href" );
+ return "";
+ }
+
+
+ /**
+ * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue.
+ * <code>
+ * <meta name="robots" content="index,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"
+ * </code>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
+ public String getMetaTagContent(String attribute, String attributeValue) {
+ 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");
+ }
+ }
+ return "";
+ }
private static Node getDOM( String pageText ) throws SAXException {
try {
@@ -85,7 +129,7 @@
NodeList nl = ((Document) getDOM()).getElementsByTagName( "base" );
if (nl.getLength() == 0) return;
try {
- applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ),
+ applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ),
NodeUtils.getNodeAttribute( nl.item(0), "target" ) );
} catch (MalformedURLException e) {
throw new RuntimeException( "Unable to set document base: " + e );
@@ -105,7 +149,7 @@
private static Tidy getParser() {
Tidy tidy = new Tidy();
- tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
+ tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
tidy.setQuiet( true );
tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() );
return tidy;
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- WebResponse.java 2001/10/16 16:21:25 1.48
+++ WebResponse.java 2001/10/25 14:15:59 1.49
@@ -55,6 +55,7 @@
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
* @author <a href="mailto:DRE...@or...">Drew Varner</a>
* @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
abstract
public class WebResponse implements HTMLSegment {
@@ -92,6 +93,37 @@
return getReceivedPage().getTitle();
}
+
+ /**
+ * Returns the stylesheet linked in the head of the page.
+ * <code>
+ * <link type="text/css" rel="stylesheet" href="/mystyle.css" />
+ * </code>
+ * will return "/mystyle.css".
+ * @exception SAXException thrown if there is an error parsing this response
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
+ public String getExternalStyleSheet() throws SAXException {
+ return getReceivedPage().getExternalStyleSheet();
+ }
+
+ /**
+ * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue.
+ * <code>
+ * <meta name="robots" content="index,follow" />
+ * <meta http-equiv="Expires" content="now" />
+ * </code>
+ * can be used as follows:
+ * <code>
+ * 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 {
+ return getReceivedPage().getMetaTagContent(attribute, attributeValue);
+ }
/**
* Returns the target of the page.
|