[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebResponse.java,1.58,1.59
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-02-01 14:31:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv8509/src/com/meterware/httpunit
Modified Files:
WebResponse.java
Log Message:
From Jochen Hiller: use JAXP-compliant parser
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- WebResponse.java 2002/01/10 22:18:13 1.58
+++ WebResponse.java 2002/02/01 14:31:43 1.59
@@ -355,7 +355,11 @@
if (isHTML()) {
return (Document) getReceivedPage().getDOM();
} else {
- return getXMLDOM();
+ try {
+ return HttpUnitUtils.newParser().parse( new InputSource( new StringReader( getText() ) ) );
+ } catch (IOException e) {
+ throw new SAXException( e );
+ }
}
}
@@ -797,45 +801,6 @@
return _page;
}
-
- private Document getXMLDOM() throws SAXException {
- Document doc = null;
-
- try {
- Class parserClass = Class.forName("org.apache.xerces.parsers.DOMParser");
- Constructor constructor = parserClass.getConstructor( null );
- Object parser = constructor.newInstance( null );
-
- Class[] parseMethodArgTypes = { InputSource.class };
- Object[] parseMethodArgs = { new InputSource( new StringReader( getText() ) ) };
- Method parseMethod = parserClass.getMethod( "parse", parseMethodArgTypes );
- parseMethod.invoke( parser, parseMethodArgs );
-
- Method getDocumentMethod = parserClass.getMethod( "getDocument", null );
- doc = (Document)getDocumentMethod.invoke( parser, null );
- } catch (IOException e) {
- throw new SAXException( e );
- } catch (InvocationTargetException ex) {
- Throwable tex = ex.getTargetException();
- if (tex instanceof SAXException) {
- throw (SAXException)tex;
- } else if (tex instanceof IOException) {
- throw new RuntimeException( tex.toString() );
- } else {
- throw new IllegalStateException( "unexpected exception" );
- }
- } catch (NoSuchMethodException ex) {
- throw new IllegalStateException( "parse method not found" );
- } catch (IllegalAccessException ex) {
- throw new IllegalStateException( "parse method not public" );
- } catch (InstantiationException ex) {
- throw new IllegalStateException( "error instantiating parser" );
- } catch (ClassNotFoundException ex) {
- throw new IllegalStateException( "parser class not found" );
- }
-
- return doc;
- }
private static String _defaultEncoding;
|