[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLParser.java,NONE,1.1 JTidyHTMLParser.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-10-14 04:19:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10393/src/com/meterware/httpunit
Modified Files:
FormControl.java HTMLPage.java HttpUnitOptions.java
NodeUtils.java ParsedHTML.java WebLink.java WebResponse.java
Added Files:
HTMLParser.java JTidyHTMLParser.java NekoHTMLParser.java
Log Message:
Added NekoHTML support
***** Error reading new file[Errno 2] No such file or directory: 'HTMLParser.java'
***** Error reading new file[Errno 2] No such file or directory: 'JTidyHTMLParser.java'
***** Error reading new file[Errno 2] No such file or directory: 'NekoHTMLParser.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- FormControl.java 13 Oct 2002 23:53:48 -0000 1.28
+++ FormControl.java 14 Oct 2002 04:19:06 -0000 1.29
@@ -272,9 +272,9 @@
static FormControl newFormParameter( WebForm form, Node node ) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
- } else if (node.getNodeName().equals( "textarea" )) {
+ } else if (node.getNodeName().equalsIgnoreCase( "textarea" )) {
return new TextAreaFormControl( form, node );
- } else if (node.getNodeName().equals( "select" )) {
+ } else if (node.getNodeName().equalsIgnoreCase( "select" )) {
return new SelectionFormControl( form, node );
} else if (node.getNodeName().equalsIgnoreCase( "button" )) {
final String type = NodeUtils.getNodeAttribute( node, "type", "submit" );
@@ -285,7 +285,7 @@
} else {
return new Button( form, node );
}
- } else if (!node.getNodeName().equals( "input" )) {
+ } else if (!node.getNodeName().equalsIgnoreCase( "input" )) {
return null;
} else {
final String type = NodeUtils.getNodeAttribute( node, "type", "text" );
@@ -991,8 +991,9 @@
_options = new Option[ nl.getLength() ];
for (int i = 0; i < _options.length; i++) {
- _options[i] = new Option( getValue( nl.item(i).getFirstChild() ),
- getOptionValue( nl.item(i) ),
+ final String displayedText = getValue( nl.item(i).getFirstChild() ).trim();
+ _options[i] = new Option( displayedText,
+ getOptionValue( nl.item(i), displayedText ),
nl.item(i).getAttributes().getNamedItem( "selected" ) != null );
_options[i].setIndex( this, i );
}
@@ -1136,12 +1137,12 @@
}
- private String getOptionValue( Node optionNode ) {
+ private String getOptionValue( Node optionNode, String displayedText ) {
NamedNodeMap nnm = optionNode.getAttributes();
if (nnm.getNamedItem( "value" ) != null) {
return getValue( nnm.getNamedItem( "value" ) );
} else {
- return getValue( optionNode.getFirstChild() );
+ return displayedText;
}
}
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HTMLPage.java 13 Oct 2002 23:53:48 -0000 1.12
+++ HTMLPage.java 14 Oct 2002 04:19:06 -0000 1.13
@@ -21,22 +21,18 @@
*******************************************************************************************************************/
import com.meterware.httpunit.scripting.NamedDelegate;
import com.meterware.httpunit.scripting.ScriptableDelegate;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Vector;
-import java.util.ArrayList;
-
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Vector;
+
/**
* This class represents an HTML page returned from a request.
@@ -49,7 +45,7 @@
private Scriptable _scriptable;
- public HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws SAXException {
+ HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws IOException, SAXException {
super( response, url, parentTarget, getDOM( url, pageText ), characterSet );
setBaseAttributes();
}
@@ -239,24 +235,8 @@
//---------------------------------- private members --------------------------------
- private static Node getDOM( URL url, String pageText ) throws SAXException {
- try {
- return getParser( url ).parseDOM( new ByteArrayInputStream( pageText.getBytes( getUTFEncodingName() ) ), null );
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException( "UTF-8 encoding failed" );
- }
- }
-
-
- private static String _utfEncodingName;
-
- private static String getUTFEncodingName() {
- if (_utfEncodingName == null) {
- String versionNum = System.getProperty( "java.version" );
- if (versionNum.startsWith( "1.1" )) _utfEncodingName = "UTF8";
- else _utfEncodingName = "UTF-8";
- }
- return _utfEncodingName;
+ private static Node getDOM( URL url, String pageText ) throws IOException, SAXException {
+ return HttpUnitOptions.getHTMLParser().getDocument( url, pageText );
}
@@ -281,16 +261,5 @@
}
}
-
- private static Tidy getParser( URL url ) {
- Tidy tidy = new Tidy();
- tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
- tidy.setQuiet( true );
- tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() );
- if (!HttpUnitOptions.getHtmlErrorListeners().isEmpty()) {
- tidy.setErrout(new JTidyPrintWriter( url ));
- }
- return tidy;
- }
}
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- HttpUnitOptions.java 9 Oct 2002 13:50:07 -0000 1.29
+++ HttpUnitOptions.java 14 Oct 2002 04:19:06 -0000 1.30
@@ -27,7 +27,7 @@
/**
* A collection of global options to control HttpUnit's behavior.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
@@ -61,6 +61,11 @@
}
+ public static HTMLParser getHTMLParser() {
+ return _htmlParser;
+ }
+
+
/**
* Returns true if HttpUnit is accepting and saving cookies. The default is to accept them.
*/
@@ -506,10 +511,30 @@
private static boolean _exceptionsThrownOnScriptError = true;
+ private static HTMLParser _htmlParser;
+ private static HTMLParser _jtidyParser;
+
+ private static HTMLParser _nekoParser;
static {
_listeners = new Vector();
reset();
+
+ try {
+ _jtidyParser = (HTMLParser) Class.forName( "com.meterware.httpunit.JTidyHTMLParser" ).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+
+ try {
+ _nekoParser = (HTMLParser) Class.forName( "com.meterware.httpunit.NekoHTMLParser" ).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+
+ _htmlParser = (_nekoParser == null) ? _jtidyParser : _nekoParser;
}
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NodeUtils.java 5 Aug 2002 15:21:19 -0000 1.12
+++ NodeUtils.java 14 Oct 2002 04:19:06 -0000 1.13
@@ -109,7 +109,7 @@
return true;
}
public void processTextNodeValue( String value ) {
- sb.append( convertNBSP( value ) );
+ sb.append( HttpUnitOptions.getHTMLParser().getCleanedText( value ) );
}
} );
return sb.toString();
@@ -136,15 +136,6 @@
pushNodeList( node.getChildNodes(), pendingNodes );
}
- }
-
-
- final static private char NBSP = (char) 160; // non-breaking space, defined by JTidy
-
-
- private static String convertNBSP( String text ) {
- if (text == null) return "";
- return text.replace( NBSP, ' ' );
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- ParsedHTML.java 4 Oct 2002 02:16:00 -0000 1.30
+++ ParsedHTML.java 14 Oct 2002 04:19:06 -0000 1.31
@@ -27,7 +27,7 @@
import org.w3c.dom.*;
/**
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
class ParsedHTML {
@@ -375,7 +375,7 @@
private boolean isLinkAnchor( Node node ) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return false;
- } else if (!node.getNodeName().equals( "a" ) && !node.getNodeName().equals( "area" )) {
+ } else if (!node.getNodeName().equalsIgnoreCase( "a" ) && !node.getNodeName().equalsIgnoreCase( "area" )) {
return false;
} else {
return (node.getAttributes().getNamedItem( "href" ) != null);
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- WebLink.java 13 Oct 2002 23:53:48 -0000 1.32
+++ WebLink.java 14 Oct 2002 04:19:06 -0000 1.33
@@ -66,7 +66,7 @@
* Returns the text value of this link.
**/
public String asText() {
- if (getNode().getNodeName().equals( "area" )) {
+ if (getNode().getNodeName().equalsIgnoreCase( "area" )) {
return getAttribute( "alt" );
} else if (!getNode().hasChildNodes()) {
return "";
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -r1.91 -r1.92
--- WebResponse.java 13 Oct 2002 23:53:48 -0000 1.91
+++ WebResponse.java 14 Oct 2002 04:19:06 -0000 1.92
@@ -39,7 +39,7 @@
/**
* A response to a web request from a web server.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">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>
@@ -1088,7 +1088,8 @@
if (!isHTML()) throw new NotHTMLException( getContentType() );
_page = new HTMLPage( this, _url, _frameName, getText(), getCharacterSet() );
} catch (IOException e) {
- throw new SAXException( e );
+ e.printStackTrace();
+ throw new RuntimeException( e.toString() );
}
}
return _page;
|