httpunit-commit Mailing List for httpunit (Page 39)
Brought to you by:
russgold
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
| 2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
| 2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
| 2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
| 2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
| 2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
| 2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
|
From: Russell G. <rus...@us...> - 2002-12-27 05:09:40
|
Update of /cvsroot/httpunit/httpunit/doc In directory sc8-pr-cvs1:/tmp/cvs-serv1498/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added JavaScript Form.target support Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- Javascript-support.html 13 Dec 2002 12:57:10 -0000 1.31 +++ Javascript-support.html 27 Dec 2002 05:09:38 -0000 1.32 @@ -103,6 +103,7 @@ <li>action - r/w the action associated with the form</li> <li>document - r/o the enclosing document</li> <li>elements - r/o an array of controls in the form</li> +<li>action - r/w the target for any response from the form</li> <li><name> - the name of a control in the form</li> </ul> <h4>events</h4> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.238 retrieving revision 1.239 diff -u -r1.238 -r1.239 --- release_notes.txt 26 Dec 2002 18:55:18 -0000 1.238 +++ release_notes.txt 27 Dec 2002 05:09:38 -0000 1.239 @@ -13,8 +13,13 @@ Revision History: 26-Dec-2002 Additions: - WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement, given its ID. - Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, FormControl, TableCell, and TableRow. + 1. WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement, given its ID. + Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, FormControl, TableCell, and TableRow. + 2. The Form.target property is now supported + +Problems fixed: + 1. Forms prematurely closed because of improper nesting will now contain any controls defined before the next form. + At present, this only works with the JTidy parser. 25-Dec-2002 Notes: |
|
From: Russell G. <rus...@us...> - 2002-12-26 20:50:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv2922/src/com/meterware/httpunit
Modified Files:
ParsedHTML.java
Log Message:
Treat controls between forms as belonging to the preceding form
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- ParsedHTML.java 26 Dec 2002 18:55:18 -0000 1.41
+++ ParsedHTML.java 26 Dec 2002 20:50:48 -0000 1.42
@@ -54,6 +54,7 @@
private ArrayList _formsList = new ArrayList();
private WebForm[] _forms;
+ private WebForm _activeForm;
private ArrayList _imagesList = new ArrayList();
private WebImage[] _images;
@@ -218,6 +219,10 @@
final protected Object getClosestContext( NodeUtils.PreOrderTraversal pot, Class aClass ) {
return pot.getClosestContext( aClass );
}
+
+ protected ParsedHTML getRootContext( NodeUtils.PreOrderTraversal pot ) {
+ return (ParsedHTML) pot.getContexts().next();
+ }
}
@@ -225,7 +230,12 @@
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebForm( element );
}
- protected boolean addToContext() { return true; }
+
+
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ super.addToLists( pot, htmlElement );
+ getRootContext( pot )._activeForm = (WebForm) htmlElement;
+ }
}
@@ -296,10 +306,11 @@
static class FormControlFactory extends HTMLElementFactory {
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
- return getForm( pot ).newFormControl( element );
+ final WebForm form = getForm( pot );
+ return form == null ? null : form.newFormControl( element );
}
private WebForm getForm( NodeUtils.PreOrderTraversal pot ) {
- return (WebForm) getClosestContext( pot, WebForm.class );
+ return getRootContext( pot )._activeForm;
}
protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
getForm( pot ).addFormControl( (FormControl) htmlElement );
|
|
From: Russell G. <rus...@us...> - 2002-12-26 18:55:22
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv13421/test/com/meterware/httpunit
Modified Files:
FormSubmitTest.java
Log Message:
form controls are now treated as HTML elements
Index: FormSubmitTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- FormSubmitTest.java 15 Nov 2002 02:53:59 -0000 1.29
+++ FormSubmitTest.java 26 Dec 2002 18:55:19 -0000 1.30
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, 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
@@ -19,16 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import com.meterware.pseudoserver.PseudoServlet;
@@ -45,7 +37,7 @@
}
- public static Test suite() {
+ public static TestSuite suite() {
return new TestSuite( FormSubmitTest.class );
}
@@ -191,6 +183,8 @@
Button reset = form.getButtonWithID( "clear" );
reset.click();
assertEquals( "Value after reset", "12", form.getParameterValue( "age" ) );
+ HTMLElement element = page.getElementWithID( "clear" );
+ assertSame( "Reset button", reset, element );
}
@@ -415,7 +409,7 @@
WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );
WebForm form = page.getForms()[0];
try {
- WebRequest request = form.getRequest();
+ form.getRequest();
fail( "Should not allow submit with unnamed button" );
} catch (IllegalRequestParameterException e) {
}
@@ -446,14 +440,14 @@
WebForm wrongForm = wrong.getForms()[0];
HttpUnitOptions.setParameterValuesValidated( true );
- WebRequest request = form.getRequest( otherForm.getSubmitButtons()[0] );
+ form.getRequest( otherForm.getSubmitButtons()[0] );
HttpUnitOptions.setParameterValuesValidated( false );
- request = form.getRequest( wrongForm.getSubmitButtons()[0] );
+ form.getRequest( wrongForm.getSubmitButtons()[0] );
HttpUnitOptions.setParameterValuesValidated( true );
try {
- request = form.getRequest( wrongForm.getSubmitButtons()[0] );
+ form.getRequest( wrongForm.getSubmitButtons()[0] );
fail( "Failed to reject illegal button" );
} catch (IllegalRequestParameterException e) {
}
|
|
From: Russell G. <rus...@us...> - 2002-12-26 18:55:22
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv13421/src/com/meterware/httpunit
Modified Files:
Button.java FormControl.java FormParameter.java
ParsedHTML.java ResetButton.java WebForm.java
Log Message:
form controls are now treated as HTML elements
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Button.java 13 Oct 2002 23:53:48 -0000 1.3
+++ Button.java 26 Dec 2002 18:55:18 -0000 1.4
@@ -64,7 +64,7 @@
final
protected boolean doOnClickEvent() {
- return _onClickEvent.length() == 0 || getScriptableObject().doEvent( _onClickEvent );
+ return _onClickEvent.length() == 0 || getScriptableDelegate().doEvent( _onClickEvent );
}
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- FormControl.java 31 Oct 2002 04:54:58 -0000 1.31
+++ FormControl.java 26 Dec 2002 18:55:18 -0000 1.32
@@ -38,12 +38,10 @@
*
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-abstract class FormControl {
+abstract class FormControl extends HTMLElementBase {
final static String[] NO_VALUE = new String[0];
- private String _name;
- private final String _id;
private String _valueAttribute;
private final boolean _readOnly;
private final boolean _disabled;
@@ -55,9 +53,8 @@
FormControl( WebForm form ) {
+ super( newEmptyNode( form ) );
_form = form;
- _id = "";
- _name = "";
_valueAttribute = "";
_readOnly = false;
_disabled = false;
@@ -66,10 +63,14 @@
}
+ private static Node newEmptyNode( WebForm form ) {
+ return form.getNode().getOwnerDocument().createElement( "httpunit-supplied" );
+ }
+
+
FormControl( WebForm form, Node node ) {
+ super( node );
_form = form;
- _id = NodeUtils.getNodeAttribute( node, "id" );
- _name = NodeUtils.getNodeAttribute( node, "name" );
_valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
_readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
_disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
@@ -79,31 +80,18 @@
/**
- * Returns the name of this control. If no name is specified, defaults to the empty string.
- **/
- public String getName() {
- return _name;
- }
-
-
- /**
- * Returns the ID associated with this control, if any.
- * @return the control ID, or an empty string if no ID is defined.
- **/
- public String getID() {
- return _id;
- }
-
-
- /**
* Returns the current value(s) associated with this control. These values will be transmitted to the server
* if the control is 'successful'.
**/
abstract String[] getValues();
+ /**
+ * Returns either a single delegate object or potentially an array of delegates as needed, given the form control.
+ * This default implementation returns the scriptable delegate for the control.
+ */
Object getDelegate() {
- return getScriptableObject();
+ return getScriptableDelegate();
}
@@ -115,7 +103,7 @@
/**
* Returns a scriptable object which can act as a proxy for this control.
*/
- ScriptableDelegate getScriptableObject() {
+ public ScriptableDelegate getScriptableDelegate() {
if (_scriptable == null) {
_scriptable = newScriptable();
_scriptable.setScriptEngine( getForm().getScriptableObject().getScriptEngine( _scriptable ) );
@@ -230,7 +218,7 @@
* Performs the 'onChange' event defined for this control.
*/
protected void sendOnChangeEvent() {
- if (_onChangeEvent.length() > 0) getScriptableObject().doEvent( _onChangeEvent );
+ if (_onChangeEvent.length() > 0) getScriptableDelegate().doEvent( _onChangeEvent );
}
@@ -238,7 +226,7 @@
* Performs the 'onClick' event defined for this control.
*/
protected void sendOnClickEvent() {
- if (_onClickEvent.length() > 0) getScriptableObject().doEvent( _onClickEvent );
+ if (_onClickEvent.length() > 0) getScriptableDelegate().doEvent( _onClickEvent );
}
@@ -268,6 +256,11 @@
}
+ static String[] getControlElementTags() {
+ return new String[] { "textarea", "select", "button", "input" };
+ }
+
+
static FormControl newFormParameter( WebForm form, Node node ) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
@@ -507,7 +500,7 @@
Object getDelegate() {
ScriptableDelegate[] delegates = new ScriptableDelegate[ getButtons().length ];
for (int i = 0; i < delegates.length; i++) {
- delegates[i] = getButtons()[i].getScriptableObject();
+ delegates[i] = getButtons()[i].getScriptableDelegate();
}
return delegates;
}
Index: FormParameter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormParameter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FormParameter.java 27 Nov 2002 01:28:34 -0000 1.3
+++ FormParameter.java 26 Dec 2002 18:55:18 -0000 1.4
@@ -66,7 +66,7 @@
ArrayList list = new ArrayList();
for (int i = 0; i < _controls.length; i++) {
FormControl control = _controls[i];
- list.add( control.getScriptableObject() );
+ list.add( control.getScriptableDelegate() );
}
return list.toArray( new ScriptableDelegate[ list.size() ] );
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- ParsedHTML.java 26 Dec 2002 15:33:56 -0000 1.40
+++ ParsedHTML.java 26 Dec 2002 18:55:18 -0000 1.41
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Arrays;
/**
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
@@ -224,6 +225,7 @@
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebForm( element );
}
+ protected boolean addToContext() { return true; }
}
@@ -291,6 +293,18 @@
}
}
+ static class FormControlFactory extends HTMLElementFactory {
+
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ return getForm( pot ).newFormControl( element );
+ }
+ private WebForm getForm( NodeUtils.PreOrderTraversal pot ) {
+ return (WebForm) getClosestContext( pot, WebForm.class );
+ }
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ getForm( pot ).addFormControl( (FormControl) htmlElement );
+ }
+ }
private static HashMap _htmlFactoryClasses = new HashMap();
@@ -305,6 +319,10 @@
_htmlFactoryClasses.put( "tr", new TableRowFactory() );
_htmlFactoryClasses.put( "td", new TableCellFactory() );
_htmlFactoryClasses.put( "th", new TableCellFactory() );
+
+ for (Iterator i = Arrays.asList( FormControl.getControlElementTags() ).iterator(); i.hasNext();) {
+ _htmlFactoryClasses.put( i.next(), new FormControlFactory() );
+ }
}
private static HTMLElementFactory getHTMLElementFactory( String tagName ) {
Index: ResetButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ResetButton.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResetButton.java 27 Aug 2002 16:26:04 -0000 1.1
+++ ResetButton.java 26 Dec 2002 18:55:18 -0000 1.2
@@ -28,13 +28,9 @@
/**
* Represents a form 'reset' button.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class ResetButton extends Button {
-
- ResetButton( WebForm form ) {
- super( form );
- }
ResetButton( WebForm form, Node node ) {
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- WebForm.java 26 Dec 2002 15:33:56 -0000 1.72
+++ WebForm.java 26 Dec 2002 18:55:18 -0000 1.73
@@ -31,7 +31,6 @@
import java.util.Vector;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
@@ -126,7 +125,7 @@
public Button getButtonWithID( String buttonID ) {
Button[] buttons = getButtons();
for (int i = 0; i < buttons.length; i++) {
- if (buttons[i].getID().equalsIgnoreCase( buttonID )) return buttons[i];
+ if (buttons[i].getID().equals( buttonID )) return buttons[i];
}
return null;
}
@@ -551,7 +550,7 @@
FormControl[] controls = getFormControls();
ScriptableDelegate[] result = new ScriptableDelegate[ controls.length ];
for (int i = 0; i < result.length; i++) {
- result[i] = controls[i].getScriptableObject();
+ result[i] = controls[i].getScriptableDelegate();
}
return result;
}
@@ -575,7 +574,7 @@
private final static String[] NO_VALUES = new String[0];
/** The attributes of the form parameters. **/
- private FormControl[] _parameters;
+ private FormControl[] _formControls;
/** The submit buttons in this form. **/
private SubmitButton[] _submitButtons;
@@ -629,18 +628,28 @@
}
+ private ArrayList _controlList = new ArrayList();
+
+ FormControl newFormControl( Node child ) {
+ return FormControl.newFormParameter( this, child );
+ }
+
+
+ void addFormControl( FormControl control ) {
+ _controlList.add( control );
+ _formControls = null;
+ _formParameters = null;
+ }
+
+
/**
* Returns an array of form parameter attributes for this form.
**/
private FormControl[] getFormControls() {
- if (_parameters == null) {
- Vector list = new Vector();
- if (getNode().hasChildNodes()) addFormParametersToList( getNode().getChildNodes(), list );
- _parameters = new FormControl[ list.size() ];
- list.copyInto( _parameters );
+ if (_formControls == null) {
+ _formControls = (FormControl[]) _controlList.toArray( new FormControl[ _controlList.size() ] );
}
-
- return _parameters;
+ return _formControls;
}
@@ -673,23 +682,6 @@
_formParameters.put( controls[i].getName(), parameter );
}
parameter.addControl( controls[i] );
- }
- }
-
-
- private void addFormParametersToList( NodeList children, Vector list ) {
- for (int i = 0; i < children.getLength(); i++) {
- addFormParametersToList( children.item(i), list );
- }
- }
-
-
- private void addFormParametersToList( Node child, Vector list ) {
- final FormControl formParameter = FormControl.newFormParameter( this, child );
- if (formParameter != null) {
- list.addElement( formParameter );
- } else if (child.hasChildNodes()) {
- addFormParametersToList( child.getChildNodes(), list );
}
}
|
|
From: Russell G. <rus...@us...> - 2002-12-26 18:55:21
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv13421/doc
Modified Files:
release_notes.txt
Log Message:
form controls are now treated as HTML elements
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -r1.237 -r1.238
--- release_notes.txt 26 Dec 2002 15:33:55 -0000 1.237
+++ release_notes.txt 26 Dec 2002 18:55:18 -0000 1.238
@@ -14,7 +14,7 @@
26-Dec-2002
Additions:
WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement, given its ID.
- Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, TableCell, and TableRow.
+ Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, FormControl, TableCell, and TableRow.
25-Dec-2002
Notes:
|
|
From: Russell G. <rus...@us...> - 2002-12-26 15:34:00
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv21758/src/com/meterware/httpunit
Modified Files:
HTMLSegment.java NodeUtils.java ParsedHTML.java TableCell.java
WebForm.java WebImage.java WebLink.java WebTable.java
Log Message:
Expanded HTMLElement support to TableRow and TableCell
Index: HTMLSegment.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLSegment.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HTMLSegment.java 12 Nov 2002 13:41:54 -0000 1.7
+++ HTMLSegment.java 26 Dec 2002 15:33:56 -0000 1.8
@@ -23,9 +23,17 @@
/**
* Represents the parse tree for a segment of HTML.
- * @author Russell Gold
+ *
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public interface HTMLSegment {
+
+
+ /**
+ * Returns the HTMLElement found in this segment with the specified ID.
+ * @exception SAXException thrown if there is an error parsing the segment.
+ */
+ public HTMLElement getElementWithID( String id ) throws SAXException;
/**
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- NodeUtils.java 26 Dec 2002 04:59:35 -0000 1.16
+++ NodeUtils.java 26 Dec 2002 15:33:56 -0000 1.17
@@ -153,6 +153,19 @@
}
+ /**
+ * Returns the most recently pushed context which implements the specified class.
+ * Will return null if no matching context is found.
+ */
+ public Object getClosestContext( Class matchingClass ) {
+ for (int i = _traversalContext.size()-1; i >= 0; i-- ) {
+ Object o = _traversalContext.elementAt( i );
+ if (matchingClass.isInstance(o)) return o;
+ }
+ return null;
+ }
+
+
public void perform( NodeAction action ) {
while (!_pendingNodes.empty()) {
final Object object = _pendingNodes.pop();
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- ParsedHTML.java 26 Dec 2002 04:59:35 -0000 1.39
+++ ParsedHTML.java 26 Dec 2002 15:33:56 -0000 1.40
@@ -185,83 +185,126 @@
abstract static class HTMLElementFactory {
- abstract HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element );
- void recordElement( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
+ abstract HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element );
+
+ void recordElement( NodeUtils.PreOrderTraversal pot, Element element, ParsedHTML parsedHTML ) {
+ HTMLElement htmlElement = toHTMLElement( pot, parsedHTML, element );
if (htmlElement != null) {
addToMaps( pot, element, htmlElement );
addToLists( pot, htmlElement );
}
}
+
+ protected boolean addToContext() { return false; }
protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
for (Iterator i = pot.getContexts(); i.hasNext();) {
Object o = i.next();
if (o instanceof ParsedHTML) ((ParsedHTML) o).addToList( htmlElement );
}
}
+
protected void addToMaps( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
for (Iterator i = pot.getContexts(); i.hasNext();) {
Object o = i.next();
if (o instanceof ParsedHTML) ((ParsedHTML) o).addToMaps( element, htmlElement );
}
}
+
+ final protected ParsedHTML getParsedHTML( NodeUtils.PreOrderTraversal pot ) {
+ return (ParsedHTML) getClosestContext( pot, ParsedHTML.class );
+ }
+
+ final protected Object getClosestContext( NodeUtils.PreOrderTraversal pot, Class aClass ) {
+ return pot.getClosestContext( aClass );
+ }
}
static class WebFormFactory extends HTMLElementFactory {
- HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebForm( element );
}
}
static class WebLinkFactory extends HTMLElementFactory {
- HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toLinkAnchor( element );
}
}
static class WebImageFactory extends HTMLElementFactory {
- HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebImage( element );
}
}
static class WebAppletFactory extends HTMLElementFactory {
- HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebApplet( element );
}
}
static class WebTableFactory extends HTMLElementFactory {
- HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebTable( element );
}
+ protected boolean addToContext() { return true; }
+
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ getParsedHTML( pot ).addToList( htmlElement );
+ }
+ }
+
+
+ static class TableRowFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ WebTable wt = getWebTable( pot );
+ if (wt == null) return null;
+ return wt.newTableRow( element );
+ }
+ private WebTable getWebTable( NodeUtils.PreOrderTraversal pot ) {
+ return (WebTable) getClosestContext( pot, WebTable.class );
+ }
+ protected boolean addToContext() { return true; }
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ getWebTable( pot ).addRow( (WebTable.TableRow) htmlElement );
+ }
+ }
-// protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
-// for (Iterator i = pot.getContexts(); i.hasNext();) {
-// Object o = i.next();
-// if (o instanceof ParsedHTML) {
-// ((ParsedHTML) o).addToList( htmlElement );
-// return;
-// }
-// }
-// }
+ static class TableCellFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ WebTable.TableRow tr = getTableRow( pot );
+ if (tr == null) return null;
+ return tr.newTableCell( element );
+ }
+ private WebTable.TableRow getTableRow( NodeUtils.PreOrderTraversal pot ) {
+ return (WebTable.TableRow) getClosestContext( pot, WebTable.TableRow.class );
+ }
+ protected boolean addToContext() { return true; }
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ getTableRow( pot ).addTableCell( (TableCell) htmlElement );
+ }
}
+
private static HashMap _htmlFactoryClasses = new HashMap();
static {
- _htmlFactoryClasses.put( "a", new WebLinkFactory() );
- _htmlFactoryClasses.put( "area", new WebLinkFactory() );
- _htmlFactoryClasses.put( "form", new WebFormFactory() );
- _htmlFactoryClasses.put( "img", new WebImageFactory() );
+ _htmlFactoryClasses.put( "a", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "area", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "form", new WebFormFactory() );
+ _htmlFactoryClasses.put( "img", new WebImageFactory() );
_htmlFactoryClasses.put( "applet", new WebAppletFactory() );
- _htmlFactoryClasses.put( "table", new WebTableFactory() );
+ _htmlFactoryClasses.put( "table", new WebTableFactory() );
+ _htmlFactoryClasses.put( "tr", new TableRowFactory() );
+ _htmlFactoryClasses.put( "td", new TableCellFactory() );
+ _htmlFactoryClasses.put( "th", new TableCellFactory() );
}
private static HTMLElementFactory getHTMLElementFactory( String tagName ) {
@@ -274,10 +317,11 @@
NodeUtils.NodeAction action = new NodeUtils.NodeAction() {
public boolean processElement( NodeUtils.PreOrderTraversal pot, Element element ) {
- if (_elements.containsKey( element )) return true;
-
HTMLElementFactory factory = getHTMLElementFactory( element.getNodeName().toLowerCase() );
- if (factory != null) factory.recordElement( pot, element, factory.toHTMLElement( ParsedHTML.this, element ) );
+ if (factory == null) return true;
+
+ if (!_elements.containsKey( element )) factory.recordElement( pot, element, ParsedHTML.this );
+ if (factory.addToContext()) pot.pushContext( _elements.get( element ) );
return true;
}
@@ -298,7 +342,12 @@
private WebLink toLinkAnchor( Element child ) {
- return (!isLinkAnchor( child )) ? null : new WebLink( _response, _baseURL, _baseTarget, child );
+ return (!isWebLink( child )) ? null : new WebLink( _response, _baseURL, _baseTarget, child );
+ }
+
+
+ private boolean isWebLink( Node node ) {
+ return (node.getAttributes().getNamedItem( "href" ) != null);
}
@@ -313,7 +362,6 @@
private WebTable toWebTable( Element element ) {
- if (!WebTable.isTopLevelTable( element, getRootNode() )) return null;
return new WebTable( _response, element, _baseURL, _baseTarget, _characterSet );
}
@@ -539,22 +587,6 @@
if (_rootNode == null) throw new IllegalStateException( "The root node has not been specified" );
return _rootNode;
}
-
-
-
- /**
- * Returns true if the node is a link anchor node.
- **/
- private boolean isLinkAnchor( Node node ) { // XXX do we really need all these tests any more?
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- return false;
- } else if (!node.getNodeName().equalsIgnoreCase( "a" ) && !node.getNodeName().equalsIgnoreCase( "area" )) {
- return false;
- } else {
- return (node.getAttributes().getNamedItem( "href" ) != null);
- }
- }
-
/**
Index: TableCell.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TableCell.java 1 Aug 2002 14:58:59 -0000 1.8
+++ TableCell.java 26 Dec 2002 15:33:56 -0000 1.9
@@ -19,6 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
import java.net.URL;
import org.w3c.dom.Element;
@@ -28,7 +30,7 @@
/**
* A single cell in an HTML table.
**/
-public class TableCell extends ParsedHTML implements HTMLSegment {
+public class TableCell extends ParsedHTML implements HTMLSegment, HTMLElement {
/**
@@ -63,6 +65,46 @@
}
+//-------------------------------- HTMLElement methods ---------------------------------------
+
+
+ /**
+ * Returns the ID associated with this element. IDs are unique throughout the HTML document.
+ **/
+ public String getID() {
+ return getAttribute( "id" );
+ }
+
+
+ /**
+ * Returns the name associated with this element.
+ **/
+ public String getName() {
+ return getAttribute( "name" );
+ }
+
+
+ /**
+ * Returns the title associated with this element.
+ **/
+ public String getTitle() {
+ return getAttribute( "title" );
+ }
+
+
+ /**
+ * Returns the delegate which supports scripting this element.
+ */
+ public ScriptableDelegate getScriptableDelegate() {
+ throw new RuntimeException( "No scripting support for " + getClass().getName() );
+ }
+
+
+ private String getAttribute( final String name ) {
+ return NodeUtils.getNodeAttribute( _element, name );
+ }
+
+
//---------------------------------------- package methods -----------------------------------------
@@ -96,7 +138,6 @@
private int getAttributeValue( Node node, String attributeName, int defaultValue ) {
return NodeUtils.getAttributeValue( node, attributeName, defaultValue );
}
-
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- WebForm.java 13 Dec 2002 12:59:41 -0000 1.71
+++ WebForm.java 26 Dec 2002 15:33:56 -0000 1.72
@@ -425,7 +425,7 @@
* Returns the scriptable delegate.
*/
- ScriptableDelegate getScriptableDelegate() {
+ public ScriptableDelegate getScriptableDelegate() {
return getScriptableObject();
}
Index: WebImage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebImage.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebImage.java 13 Oct 2002 23:53:48 -0000 1.8
+++ WebImage.java 26 Dec 2002 15:33:56 -0000 1.9
@@ -34,7 +34,6 @@
**/
public class WebImage extends FixedURLWebRequestSource {
- private URL _baseURL;
private Node _node;
private ParsedHTML _parsedHTML;
private Scriptable _scriptable;
@@ -44,7 +43,6 @@
WebImage( WebResponse response, ParsedHTML parsedHTML, URL baseURL, Node node, String parentTarget ) {
super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "src" ), parentTarget );
- _baseURL = baseURL;
_node = node;
_parsedHTML = parsedHTML;
_src = NodeUtils.getNodeAttribute( _node, "src" );
@@ -125,7 +123,7 @@
* Returns the scriptable delegate.
*/
- ScriptableDelegate getScriptableDelegate() {
+ public ScriptableDelegate getScriptableDelegate() {
return getScriptableObject();
}
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- WebLink.java 17 Nov 2002 13:57:47 -0000 1.36
+++ WebLink.java 26 Dec 2002 15:33:56 -0000 1.37
@@ -142,7 +142,7 @@
/**
* Returns the scriptable delegate.
*/
- ScriptableDelegate getScriptableDelegate() {
+ public ScriptableDelegate getScriptableDelegate() {
return getScriptableObject();
}
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- WebTable.java 26 Dec 2002 04:59:35 -0000 1.22
+++ WebTable.java 26 Dec 2002 15:33:56 -0000 1.23
@@ -28,7 +28,7 @@
/**
* This class represents a table in an HTML page.
*
- * @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>
**/
public class WebTable extends HTMLElementBase {
@@ -51,8 +51,14 @@
* Returns the number of rows in the table.
**/
public int getRowCount() {
+ return getCells().length;
+ }
+
+
+ private TableCell[][] getCells() {
if (_cells == null) readTable();
- return _cells.length;
+ return _cells;
+
}
@@ -60,9 +66,8 @@
* Returns the number of columns in the table.
**/
public int getColumnCount() {
- if (_cells == null) readTable();
- if (_cells.length == 0) return 0;
- return _cells[0].length;
+ if (getCells().length == 0) return 0;
+ return getCells()[0].length;
}
@@ -94,8 +99,7 @@
* @throws IndexOutOfBoundsException if the specified cell numbers are not valid
**/
public TableCell getTableCell( int row, int column ) {
- if (_cells == null) readTable();
- return _cells[ row ][ column ];
+ return getCells()[ row ][ column ];
}
@@ -104,14 +108,10 @@
* @return TableCell with given ID or null if ID is not found.
**/
public TableCell getTableCellWithID( String id ) {
- if (_cells == null) readTable();
- String idToCompare;
for (int i = 0; i < getRowCount(); i++) {
for (int j = 0; j < getColumnCount(); j++) {
- if (_cells[i][j]!=null) {
- idToCompare = NodeUtils.getNodeAttribute( _cells[i][j].getOriginalDOM(), "id" );
- if (HttpUnitUtils.matches( id, idToCompare )) return _cells[i][j];
- }
+ final TableCell tableCell = getCells()[i][j];
+ if (tableCell!=null && tableCell.getID().equals( id )) return tableCell;
}
}
return null;
@@ -209,16 +209,15 @@
public String toString() {
String eol = System.getProperty( "line.separator" );
- if (_cells == null) readTable();
StringBuffer sb = new StringBuffer( HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE).append("WebTable:" ).append( eol );
- for (int i = 0; i < _cells.length; i++) {
+ for (int i = 0; i < getCells().length; i++) {
sb.append( "[" ).append( i ).append( "]: " );
- for (int j = 0; j < _cells[i].length; j++) {
+ for (int j = 0; j < getCells()[i].length; j++) {
sb.append( " [" ).append( j ).append( "]=" );
- if (_cells[i][j] == null) {
+ if (getCells()[i][j] == null) {
sb.append( "null" );
} else {
- sb.append( _cells[i][j].asText() );
+ sb.append( getCells()[i][j].asText() );
}
}
sb.append( eol );
@@ -284,106 +283,56 @@
}
-
private void placeCell( int row, int column, TableCell cell ) {
while (_cells[ row ][ column ] != null) column++;
_cells[ row ][ column ] = cell;
}
- /**
- * Returns true if the specified table node is not nested within another one.
- **/
- static boolean isTopLevelTable( Node tableNode, Node root ) {
- return isMoreCloselyNested( tableNode, root, "table" );
- }
+ private ArrayList _rows = new ArrayList();
- /**
- * Returns true if the desiredParentTag is found in the tree above this node more closely nested than
- * the undesiredParentTag, or if the top of the tree is found before the undesired tag.
- **/
- private static boolean isMoreCloselyNested( Node node, Node desiredParentNode, String undesiredParentTag ) {
- node = node.getParentNode();
- while (true) {
- if (node == desiredParentNode) {
- return true;
- } else if (node.getNodeName().equalsIgnoreCase( undesiredParentTag )) {
- return false;
- } else if (node.getParentNode() == null) {
- return true;
- }
- node = node.getParentNode();
- }
+ void addRow( TableRow tableRow ) {
+ _cells = null;
+ _rows.add( tableRow );
}
+ TableRow newTableRow( Element element ) {
+ return new TableRow( element );
+ }
+
private TableRow[] getRows() {
- final Vector rows = new Vector();
+ return (TableRow[]) _rows.toArray( new TableRow[ _rows.size() ] );
+ }
- processChildren( _dom, "table", new ElementHandler() {
- public void handleElement( Element element ) {
- rows.addElement( new TableRow( element ) );
- }
- public boolean shouldHandleElement( String tagName ) {
- return tagName.equalsIgnoreCase( "tr" );
- }
- } );
- TableRow[] result = new TableRow[ rows.size() ];
- rows.copyInto( result );
- return result;
- }
+ class TableRow extends HTMLElementBase {
+ private ArrayList _cells = new ArrayList();
- class TableRow {
- Element getElement() {
- return _element;
+ TableRow( Element rowNode ) {
+ super( rowNode );
}
+
TableCell[] getCells() {
- final Vector cells = new Vector();
+ return (TableCell[]) _cells.toArray( new TableCell[ _cells.size() ]);
+ }
- processChildren( _element, "table", new ElementHandler() {
- public void handleElement( Element element ) {
- cells.addElement( new TableCell( _response, element, _url, _parentTarget, _characterSet ) );
- }
- public boolean shouldHandleElement( String tagName ) {
- return tagName.equalsIgnoreCase( "th" ) || tagName.equalsIgnoreCase( "td" );
- }
- } );
- TableCell[] result = new TableCell[ cells.size() ];
- cells.copyInto( result );
- return result;
+ TableCell newTableCell( Element element ) {
+ return new TableCell( _response, element, _url, _parentTarget, _characterSet );
}
- private Element _element;
- TableRow( Element rowNode ) {
- _element = rowNode;
+ void addTableCell( TableCell cell ) {
+ _cells.add( cell );
}
- }
-
- interface ElementHandler {
- public void handleElement( Element element );
- public boolean shouldHandleElement( String tagName );
}
-
- static void processChildren( Element root, String avoidingParentTag, ElementHandler handler ) {
-
- for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child instanceof Element) {
- Element element = (Element) child;
- String name = child.getNodeName();
- if (handler.shouldHandleElement( name )) handler.handleElement( element );
- if (!name.equalsIgnoreCase( avoidingParentTag )) processChildren( element, avoidingParentTag, handler );
- }
- }
- }
static {
MATCH_FIRST_NONBLANK_CELL = new HTMLElementPredicate() { // XXX find a way to do this w/o purging the table cells
|
|
From: Russell G. <rus...@us...> - 2002-12-26 15:34:00
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv21758/test/com/meterware/httpunit
Modified Files:
HtmlTablesTest.java HttpUnitTest.java
Log Message:
Expanded HTMLElement support to TableRow and TableCell
Index: HtmlTablesTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- HtmlTablesTest.java 26 Dec 2002 04:59:35 -0000 1.14
+++ HtmlTablesTest.java 26 Dec 2002 15:33:57 -0000 1.15
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, 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
@@ -19,10 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -39,13 +35,13 @@
}
- public static Test suite() {
- return new TestSuite( HtmlTablesTest.class );
+ public static TestSuite suite() {
+ return new TestSuite( HtmlTablesTest.class );
}
public HtmlTablesTest( String name ) {
- super( name );
+ super( name );
}
@@ -269,7 +265,6 @@
/**
* Get a specific cell with a given id in a WebTable
- * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
public void testCellsWithID() throws Exception {
defineWebPage( "Default", "<h2>Interesting data</h2>" +
@@ -293,16 +288,8 @@
cell = table.getTableCellWithID("nonExistingID");
assertNull("cell id2",cell);
- // check the ignore case.TRUE
- HttpUnitOptions.setMatchesIgnoreCase(true);
- cell = table.getTableCellWithID("iD2");
- assertNotNull("cell id2",cell);
- assertEquals("Value of cell id2","value2",cell.asText());
-
- // check the ignore case FALSE
- HttpUnitOptions.setMatchesIgnoreCase(false);
- cell = table.getTableCellWithID("iD2");
- assertNull("cell iD2",cell);
+ cell = (TableCell) page.getElementWithID( "id1" );
+ assertEquals( "value of cell found from page", "value1", cell.asText() );
}
private WebConversation _wc;
Index: HttpUnitTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- HttpUnitTest.java 25 Nov 2002 22:41:07 -0000 1.24
+++ HttpUnitTest.java 26 Dec 2002 15:33:57 -0000 1.25
@@ -30,6 +30,7 @@
public class HttpUnitTest extends HttpUserAgentTest {
private boolean _showTestName;
+ private long _startTime;
public HttpUnitTest( String name ) {
@@ -46,8 +47,21 @@
public void setUp() throws Exception {
super.setUp();
HttpUnitOptions.reset();
- if (_showTestName) System.out.println( "----------------------- " + getName() + " ------------------------");
+ if (_showTestName) {
+ System.out.println( "----------------------- " + getName() + " ------------------------");
+ _startTime = System.currentTimeMillis();
+ }
}
+
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (_showTestName) {
+ long duration = System.currentTimeMillis() - _startTime;
+ System.out.println( "... took " + duration + " msec");
+ }
+ }
+
static {
new WebConversation();
|
|
From: Russell G. <rus...@us...> - 2002-12-26 15:33:59
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv21758/doc
Modified Files:
release_notes.txt
Log Message:
Expanded HTMLElement support to TableRow and TableCell
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -r1.236 -r1.237
--- release_notes.txt 26 Dec 2002 04:59:34 -0000 1.236
+++ release_notes.txt 26 Dec 2002 15:33:55 -0000 1.237
@@ -11,6 +11,11 @@
Revision History:
+26-Dec-2002
+Additions:
+ WebResponse and TableCell now support the getElementWithID method, which returns any supported HTMLElement, given its ID.
+ Supported HTMLElement objects include WebForm, WebLink, WebTable, WebImage, WebApplet, TableCell, and TableRow.
+
25-Dec-2002
Notes:
get...WithID was incorrectly doing case insensitive matches. It is now case-sensitive, since that is the way the
|
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/test/com/meterware/httpunit
Modified Files:
HtmlTablesTest.java WebFormTest.java WebPageTest.java
XMLPageTest.java
Log Message:
Adding support for getElementWithID
Index: HtmlTablesTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HtmlTablesTest.java 25 Nov 2002 17:02:21 -0000 1.13
+++ HtmlTablesTest.java 26 Dec 2002 04:59:35 -0000 1.14
@@ -191,11 +191,17 @@
defineWebPage( "Default", "<h2>Interesting data</h2>" +
"<table id=you summary=\"outer one\">" +
"<tr><td>Here we are</td><td>" +
- "Inner Table<br>" +
- "<table id=me summary=\"inner one\">" +
+ "Inner Table 1<br>" +
+ "<table id=you summary='inner zero'>" +
" <tr><td colspan=2> </td></tr>" +
" <tr><td>Red</td><td>1</td></tr>" +
" <tr><td>Blue</td><td>2</td></tr>" +
+ "</table></td><td>" +
+ "Inner Table 2<br>" +
+ "<table id=me summary=\"inner one\">" +
+ " <tr><td colspan=2> </td></tr>" +
+ " <tr><td>Black</td><td>1</td></tr>" +
+ " <tr><td>White</td><td>2</td></tr>" +
"</table></td></tr>" +
"</table>" );
@@ -219,14 +225,14 @@
cells = wt.asText();
assertEquals( "Total rows", 3, cells.length );
assertEquals( "Total columns", 2, cells[0].length );
- assertEquals( "cell at 2,0", "Blue", cells[2][0] );
+ assertEquals( "cell at 2,0", "White", cells[2][0] );
wt = page.getTableWithID( "me" );
assertNotNull( "Did not find table with id 'me'", wt );
cells = wt.asText();
assertEquals( "Total rows", 3, cells.length );
assertEquals( "Total columns", 2, cells[0].length );
- assertEquals( "cell at 2,0", "Blue", cells[2][0] );
+ assertEquals( "cell at 2,0", "White", cells[2][0] );
}
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- WebFormTest.java 24 Oct 2002 13:28:55 -0000 1.28
+++ WebFormTest.java 26 Dec 2002 04:59:35 -0000 1.29
@@ -135,7 +135,7 @@
WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );
assertNull( "Found nonexistent form", page.getFormWithID( "nobody" ) );
- assertNotNull( "Did not find specified form", page.getFormWithID( "oneform" ) );
+ assertNotNull( "Did not find specified form", page.getFormWithID( "oneForm" ) );
}
Index: WebPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- WebPageTest.java 13 Nov 2002 14:01:24 -0000 1.26
+++ WebPageTest.java 26 Dec 2002 04:59:35 -0000 1.27
@@ -22,12 +22,14 @@
import com.meterware.pseudoserver.PseudoServlet;
import com.meterware.pseudoserver.WebResource;
+import java.io.PrintWriter;
+import java.io.FileWriter;
+import java.io.File;
+import java.io.IOException;
+
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.io.*;
-import java.net.MalformedURLException;
-
/**
@@ -44,9 +46,6 @@
public static Test suite() {
-// DefaultWebResponse blankResponse = new DefaultWebResponse( null, null, WebResponse.BLANK_HTML );
-// HttpUnitOptions.getScriptingEngine().associate( blankResponse );
-
return new TestSuite( WebPageTest.class );
}
@@ -405,5 +404,21 @@
assertEquals( "Full string", "abcdefghijklmnopqrstuvwxyz", alphabet );
} catch (IOException e) {
}
+ }
+
+
+ public void testGetElementByID() throws Exception {
+ defineResource( "SimplePage.html",
+ "<html><head><title>A Sample Page</title></head>\n" +
+ "<body><form id='aForm'><input name=color></form>" +
+ "have <a id='link1' href='/other.html'>an <b>active</b> link</A>\n" +
+ "<img id='23' src='/images/arrow.gif' ALT='Next -->' WIDTH=1 HEIGHT=4>\n" +
+ "</body></html>\n" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" );
+ WebResponse simplePage = wc.getResponse( request );
+ assertImplements( "element with id 'aForm'", simplePage.getElementWithID( "aForm" ), WebForm.class );
+ assertImplements( "element with id 'link1'", simplePage.getElementWithID( "link1" ), WebLink.class );
+ assertImplements( "element with id '23'", simplePage.getElementWithID( "23" ), WebImage.class );
}
}
Index: XMLPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/XMLPageTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLPageTest.java 2 Apr 2001 19:03:54 -0000 1.1
+++ XMLPageTest.java 26 Dec 2002 04:59:35 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, 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
@@ -19,11 +19,11 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import junit.framework.Test;
-import junit.framework.TestCase;
+import java.util.Iterator;
+
import junit.framework.TestSuite;
-import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* A test for the XML handling functionality.
@@ -35,7 +35,7 @@
}
- public static Test suite() {
+ public static TestSuite suite() {
return new TestSuite( XMLPageTest.class );
}
@@ -53,6 +53,32 @@
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.xml" );
WebResponse simplePage = wc.getResponse( request );
- Document doc = simplePage.getDOM();
+ simplePage.getDOM();
+ }
+
+
+ public void testTraversal() throws Exception {
+ defineResource( "SimplePage.xml",
+ "<?xml version='1.0' ?><zero><main><first><second/></first><main><normal/><simple/></main><after/></main><end/></zero>",
+ "text/xml" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.xml" );
+ WebResponse simplePage = wc.getResponse( request );
+ NodeUtils.PreOrderTraversal pot = new NodeUtils.PreOrderTraversal( simplePage.getDOM() );
+ final StringBuffer sb = new StringBuffer();
+ pot.perform( new NodeUtils.NodeAction() {
+ public boolean processElement( NodeUtils.PreOrderTraversal traversal, Element element ) {
+ if (element.getNodeName().equals( "main" )) {
+ traversal.pushContext( "x" );
+ } else {
+ for (Iterator i = traversal.getContexts(); i.hasNext();) sb.append( i.next() );
+ sb.append( element.getNodeName() ).append( "|" );
+ }
+ return true;
+ }
+ public void processTextNodeValue( String value ) {
+ }
+ } );
+ assertEquals( "Traversal result", "zero|xfirst|xsecond|xxnormal|xxsimple|xafter|end|", sb.toString() );
}
}
|
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing In directory sc8-pr-cvs1:/tmp/cvs-serv4153/src/com/meterware/httpunit/parsing Modified Files: HTMLParser.java HTMLParserFactory.java Log Message: Adding support for getElementWithID Index: HTMLParser.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/HTMLParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HTMLParser.java 25 Dec 2002 15:23:11 -0000 1.2 +++ HTMLParser.java 26 Dec 2002 04:59:35 -0000 1.3 @@ -27,6 +27,7 @@ /** * A front end to a DOM parser that can handle HTML. * + * @since 1.5.2 * @author <a href="mailto:rus...@ht...">Russell Gold</a> * @author <a href="mailto:bw...@xm...">Bernhard Wagner</a> **/ Index: HTMLParserFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HTMLParserFactory.java 25 Dec 2002 15:23:11 -0000 1.2 +++ HTMLParserFactory.java 26 Dec 2002 04:59:35 -0000 1.3 @@ -26,6 +26,7 @@ * Factory for creating HTML parsers. Parser customization properties can be specified but do not necessarily work * for every parser type. * + * @since 1.5.2 * @author <a href="mailto:rus...@ht...">Russell Gold</a> * @author <a href="mailto:bw...@xm...">Bernhard Wagner</a> **/ |
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/src/com/meterware/pseudoserver
Modified Files:
HttpUserAgentTest.java
Log Message:
Adding support for getElementWithID
Index: HttpUserAgentTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpUserAgentTest.java 29 Nov 2002 15:23:41 -0000 1.5
+++ HttpUserAgentTest.java 26 Dec 2002 04:59:35 -0000 1.6
@@ -127,6 +127,15 @@
}
+ protected void assertImplements( String comment, Object object, Class expectedClass ) {
+ if (object == null) {
+ fail( comment + " should be of class " + expectedClass.getName() + " but is null" );
+ } else if (!expectedClass.isInstance( object )) {
+ fail( comment + " should be of class " + expectedClass.getName() + " but is " + object.getClass().getName() );
+ }
+ }
+
+
protected void assertMatchingSet( String comment, Object[] expected, Object[] found ) {
Vector expectedItems = new Vector();
Vector foundItems = new Vector();
|
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/src/com/meterware/httpunit
Modified Files:
NodeUtils.java ParsedHTML.java WebApplet.java
WebRequestSource.java WebResponse.java WebTable.java
Added Files:
HTMLElement.java HTMLElementBase.java
Log Message:
Adding support for getElementWithID
***** Error reading new file[Errno 2] No such file or directory: 'HTMLElement.java'
***** Error reading new file[Errno 2] No such file or directory: 'HTMLElementBase.java'
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- NodeUtils.java 24 Dec 2002 17:17:02 -0000 1.15
+++ NodeUtils.java 26 Dec 2002 04:59:35 -0000 1.16
@@ -26,6 +26,7 @@
import org.w3c.dom.NodeList;
import java.util.Stack;
+import java.util.Iterator;
import com.meterware.httpunit.parsing.HTMLParserFactory;
@@ -81,7 +82,7 @@
* Does appropriate processing on specified element. Will return false if the subtree below the element
* should be skipped.
*/
- public boolean processElement( Element element );
+ public boolean processElement( PreOrderTraversal traversal, Element element );
/**
* Processes a text node.
@@ -95,8 +96,8 @@
**/
public static String asText( NodeList rootNodes ) {
final StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
- processNodes( rootNodes, new NodeAction() {
- public boolean processElement( Element node ) {
+ NodeAction action = new NodeAction() {
+ public boolean processElement( PreOrderTraversal traversal, Element node ) {
if (node.getNodeName().equalsIgnoreCase( "p" )) {
sb.append( "\n" );
} else if (node.getNodeName().equalsIgnoreCase( "tr" )) {
@@ -113,41 +114,76 @@
public void processTextNodeValue( String value ) {
sb.append( HTMLParserFactory.getHTMLParser().getCleanedText( value ) );
}
- } );
+ };
+ new PreOrderTraversal( rootNodes ).perform( action );
return sb.toString();
}
- /**
- * Converts the DOM trees rooted at the specified nodes to text, ignoring
- * any HTML tags.
- **/
- public static void processNodes( NodeList rootNodes, NodeAction action ) {
- Stack pendingNodes = new Stack();
- pushNodeList( rootNodes, pendingNodes );
+ static class PreOrderTraversal {
- while (!pendingNodes.empty()) {
- Node node = (Node) pendingNodes.pop();
+ private Stack _pendingNodes = new Stack();
+ private Stack _traversalContext = new Stack();
+ private static final Object POP_CONTEXT = new Object();
- if (node.getNodeType() == Node.TEXT_NODE) {
- action.processTextNodeValue( node.getNodeValue() );
- } else if (node.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- } else
- action.processElement( (Element) node );
- pushNodeList( node.getChildNodes(), pendingNodes );
+ public PreOrderTraversal( NodeList rootNodes ) {
+ pushNodeList( rootNodes );
+ }
+
+
+ public PreOrderTraversal( Node rootNode ) {
+ pushNodeList( rootNode.getLastChild() );
+ }
+
+
+ public void pushBaseContext( Object context ) {
+ _traversalContext.push( context );
+ }
+
+
+ public void pushContext( Object context ) {
+ _traversalContext.push( context );
+ _pendingNodes.push( POP_CONTEXT );
}
- }
- private static void pushNodeList( NodeList nl, Stack stack ) {
- if (nl != null) {
- for (int i = nl.getLength()-1; i >= 0; i--) {
- stack.push( nl.item(i) );
+ public Iterator getContexts() {
+ return _traversalContext.iterator();
+ }
+
+
+ public void perform( NodeAction action ) {
+ while (!_pendingNodes.empty()) {
+ final Object object = _pendingNodes.pop();
+ if (object == POP_CONTEXT) {
+ _traversalContext.pop();
+ } else {
+ Node node = (Node) object;
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ action.processTextNodeValue( node.getNodeValue() );
+ } else if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ } else
+ action.processElement( this, (Element) node );
+ pushNodeList( node.getLastChild() );
+ }
}
}
- }
+
+ private void pushNodeList( NodeList nl ) {
+ if (nl != null) {
+ for (int i = nl.getLength()-1; i >= 0; i--) {
+ _pendingNodes.push( nl.item(i) );
+ }
+ }
+ }
+
+
+ private void pushNodeList( Node lastChild ) {
+ for (Node node = lastChild; node != null; node = node.getPreviousSibling()) { _pendingNodes.push( node ); }
+ }
+ }
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- ParsedHTML.java 24 Dec 2002 17:17:02 -0000 1.38
+++ ParsedHTML.java 26 Dec 2002 04:59:35 -0000 1.39
@@ -21,10 +21,11 @@
*******************************************************************************************************************/
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
/**
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
@@ -42,18 +43,29 @@
private WebResponse _response;
- private boolean _updateForms;
+ private boolean _updateElements = true;
+
+ /** map of element IDs to elements. **/
+ private HashMap _elementsByID = new HashMap();
+
+ /** map of DOM elements to HTML elements **/
+ private HashMap _elements = new HashMap();
+
+ private ArrayList _formsList = new ArrayList();
private WebForm[] _forms;
- private boolean _updateImages;
+ private ArrayList _imagesList = new ArrayList();
private WebImage[] _images;
- private boolean _updateLinks;
+ private ArrayList _linkList = new ArrayList();
private WebLink[] _links;
- private boolean _updateApplets;
+ private ArrayList _appletList = new ArrayList();
private WebApplet[] _applets;
+ private ArrayList _tableList = new ArrayList();
+ private WebTable[] _tables;
+
ParsedHTML( WebResponse response, URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
_response = response;
@@ -68,30 +80,95 @@
* Returns the forms found in the page in the order in which they appear.
**/
public WebForm[] getForms() {
- if (_forms == null || _updateForms) {
- NodeList forms = NodeUtils.getElementsByTagName( getRootNode(), "form" );
- WebForm[] oldForms = _forms;
- _forms = new WebForm[ forms.getLength() ];
-
- if (oldForms != null) System.arraycopy( oldForms, 0, _forms, 0, oldForms.length );
- for (int i = (oldForms == null ? 0 : oldForms.length); i < _forms.length; i++) {
- _forms[i] = new WebForm( _response, _baseURL, _baseTarget, forms.item( i ), _characterSet );
- _updateForms = false;
- }
+ if (_forms == null) {
+ loadElements();
+ _forms = (WebForm[]) _formsList.toArray( new WebForm[ _formsList.size() ] );
}
return _forms;
}
/**
- * Returns the form found in the page with the specified ID.
+ * Returns the links found in the page in the order in which they appear.
**/
- public WebForm getFormWithID( String ID ) {
- WebForm[] forms = getForms();
- for (int i = 0; i < forms.length; i++) {
- if (HttpUnitUtils.matches( ID, forms[i].getID() )) return forms[i];
+ public WebLink[] getLinks() {
+ if (_links == null) {
+ loadElements();
+ _links = (WebLink[]) _linkList.toArray( new WebLink[ _linkList.size() ] );
}
- return null;
+ return _links;
+ }
+
+
+ /**
+ * Returns a proxy for each applet found embedded in this page.
+ */
+ public WebApplet[] getApplets() {
+ if (_applets == null) {
+ loadElements();
+ _applets = (WebApplet[]) _appletList.toArray( new WebApplet[ _appletList.size() ] );
+ }
+ return _applets;
+ }
+
+
+ /**
+ * Returns the images found in the page in the order in which they appear.
+ **/
+ public WebImage[] getImages() {
+ if (_images == null) {
+ loadElements();
+ _images = (WebImage[]) _imagesList.toArray( new WebImage[ _imagesList.size() ] );
+ }
+ return _images;
+ }
+
+
+ /**
+ * Returns the top-level tables found in the page in the order in which they appear.
+ **/
+ public WebTable[] getTables() {
+ if (_tables == null) {
+ loadElements();
+ _tables = (WebTable[]) _tableList.toArray( new WebTable[ _tableList.size() ] );
+ }
+ return _tables;
+ }
+
+
+ /**
+ * Returns the HTMLElement with the specified ID.
+ */
+ public HTMLElement getElementWithID( String id ) {
+ return (HTMLElement) getElementWithID( id, HTMLElement.class );
+ }
+
+
+ /**
+ * Returns the form found in the page with the specified ID.
+ **/
+ public WebForm getFormWithID( String id ) {
+ return (WebForm) getElementWithID( id, WebForm.class );
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified ID.
+ **/
+ public WebLink getLinkWithID( String id ) {
+ return (WebLink) getElementWithID( id, WebLink.class );
+
+ }
+
+
+ private Object getElementWithID( String id, final Class klass ) {
+ loadElements();
+ return whenCast( _elementsByID.get( id ), klass );
+ }
+
+
+ private Object whenCast( Object o, Class klass ) {
+ return klass.isInstance( o ) ? o : null;
}
@@ -107,37 +184,162 @@
}
- /**
- * Returns the links found in the page in the order in which they appear.
- **/
- public WebLink[] getLinks() {
- if (_links == null || _updateLinks) {
- final ArrayList list = new ArrayList();
- NodeUtils.processNodes( getRootNode().getChildNodes(), new NodeUtils.NodeAction() {
- public boolean processElement( Element element ) {
- if (element.getNodeName().equalsIgnoreCase( "a" )) addLinkAnchor( list, element );
- else if (element.getNodeName().equalsIgnoreCase( "area" )) addLinkAnchor( list, element );
- return true;
- }
- public void processTextNodeValue( String value ) {
- }
- } );
- if (_links != null) for (int i = 0; i < _links.length; i++) list.set( i, _links[i] );
- _links = (WebLink[]) list.toArray( new WebLink[ list.size() ] );
- _updateLinks = false;
+ abstract static class HTMLElementFactory {
+ abstract HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element );
+ void recordElement( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
+ if (htmlElement != null) {
+ addToMaps( pot, element, htmlElement );
+ addToLists( pot, htmlElement );
+ }
+ }
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ for (Iterator i = pot.getContexts(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof ParsedHTML) ((ParsedHTML) o).addToList( htmlElement );
+ }
+ }
+ protected void addToMaps( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
+ for (Iterator i = pot.getContexts(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof ParsedHTML) ((ParsedHTML) o).addToMaps( element, htmlElement );
+ }
+ }
+ }
+
+
+ static class WebFormFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebForm( element );
}
+ }
- return _links;
+
+ static class WebLinkFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toLinkAnchor( element );
+ }
}
- private void addLinkAnchor( ArrayList list, Node child ) {
- if (isLinkAnchor( child )) {
- list.add( new WebLink( _response, _baseURL, _baseTarget, child ) );
+ static class WebImageFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebImage( element );
}
}
+ static class WebAppletFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebApplet( element );
+ }
+ }
+
+
+ static class WebTableFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebTable( element );
+ }
+
+
+// protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+// for (Iterator i = pot.getContexts(); i.hasNext();) {
+// Object o = i.next();
+// if (o instanceof ParsedHTML) {
+// ((ParsedHTML) o).addToList( htmlElement );
+// return;
+// }
+// }
+// }
+ }
+
+
+ private static HashMap _htmlFactoryClasses = new HashMap();
+
+ static {
+ _htmlFactoryClasses.put( "a", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "area", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "form", new WebFormFactory() );
+ _htmlFactoryClasses.put( "img", new WebImageFactory() );
+ _htmlFactoryClasses.put( "applet", new WebAppletFactory() );
+ _htmlFactoryClasses.put( "table", new WebTableFactory() );
+ }
+
+ private static HTMLElementFactory getHTMLElementFactory( String tagName ) {
+ return (HTMLElementFactory) _htmlFactoryClasses.get( tagName );
+ }
+
+
+ private void loadElements() {
+ if (!_updateElements) return;
+
+ NodeUtils.NodeAction action = new NodeUtils.NodeAction() {
+ public boolean processElement( NodeUtils.PreOrderTraversal pot, Element element ) {
+ if (_elements.containsKey( element )) return true;
+
+ HTMLElementFactory factory = getHTMLElementFactory( element.getNodeName().toLowerCase() );
+ if (factory != null) factory.recordElement( pot, element, factory.toHTMLElement( ParsedHTML.this, element ) );
+
+ return true;
+ }
+ public void processTextNodeValue( String value ) {
+ }
+ };
+ NodeUtils.PreOrderTraversal nt = new NodeUtils.PreOrderTraversal( getRootNode() );
+ nt.pushBaseContext( this );
+ nt.perform( action );
+
+ _updateElements = false;
+ }
+
+
+ private WebForm toWebForm( Element element ) {
+ return new WebForm( _response, _baseURL, _baseTarget, element, _characterSet );
+ }
+
+
+ private WebLink toLinkAnchor( Element child ) {
+ return (!isLinkAnchor( child )) ? null : new WebLink( _response, _baseURL, _baseTarget, child );
+ }
+
+
+ private WebImage toWebImage( Element child ) {
+ return new WebImage( _response, this, _baseURL, child, _baseTarget );
+ }
+
+
+ private WebApplet toWebApplet( Element element ) {
+ return new WebApplet( _response, element, _baseTarget );
+ }
+
+
+ private WebTable toWebTable( Element element ) {
+ if (!WebTable.isTopLevelTable( element, getRootNode() )) return null;
+ return new WebTable( _response, element, _baseURL, _baseTarget, _characterSet );
+ }
+
+
+ private void addToMaps( Element element, HTMLElement htmlElement ) {
+ _elements.put( element, htmlElement );
+ if (htmlElement.getID() != null) _elementsByID.put( htmlElement.getID(), htmlElement );
+ }
+
+
+ private void addToList( HTMLElement htmlElement ) {
+ ArrayList list = getListForElement( htmlElement );
+ if (list != null) list.add( htmlElement );
+ }
+
+
+ private ArrayList getListForElement( HTMLElement element ) {
+ if (element instanceof WebLink) return _linkList;
+ if (element instanceof WebForm) return _formsList;
+ if (element instanceof WebImage) return _imagesList;
+ if (element instanceof WebApplet) return _appletList;
+ if (element instanceof WebTable) return _tableList;
+ return null;
+ }
+
+
/**
* Returns the first link which contains the specified text.
**/
@@ -156,14 +358,6 @@
/**
- * Returns the link found in the page with the specified ID.
- **/
- public WebLink getLinkWithID( String ID ) {
- return getFirstMatchingLink( WebLink.MATCH_ID, ID );
- }
-
-
- /**
* Returns the link found in the page with the specified name.
**/
public WebLink getLinkWithName( String name ) {
@@ -197,25 +391,6 @@
/**
- * Returns the images found in the page in the order in which they appear.
- **/
- public WebImage[] getImages() {
- if (_images == null || _updateImages) {
- NodeList images = NodeUtils.getElementsByTagName( getRootNode(), "img" );
- WebImage[] oldImages = _images;
-
- _images = new WebImage[ images.getLength() ];
- if (oldImages != null) System.arraycopy( oldImages, 0, _images, 0, oldImages.length );
- for (int i = (oldImages == null ? 0 : oldImages.length); i < _images.length; i++) {
- _images[i] = new WebImage( _response, this, _baseURL, images.item( i ), _baseTarget );
- }
- _updateImages = false;
- }
- return _images;
- }
-
-
- /**
* Returns the image found in the page with the specified name.
**/
public WebImage getImageWithName( String name ) {
@@ -252,34 +427,6 @@
/**
- * Returns a proxy for each applet found embedded in this page.
- */
- public WebApplet[] getApplets() {
- if (_applets == null || _updateApplets) {
- NodeList applets = NodeUtils.getElementsByTagName( getRootNode(), "applet" );
- WebApplet[] oldApplets = _applets;
-
- _applets = new WebApplet[ applets.getLength() ];
- if (oldApplets != null) System.arraycopy( oldApplets, 0, _applets, 0, oldApplets.length );
- for (int i = (oldApplets == null ? 0 : oldApplets.length); i < _applets.length; i++) {
- _applets[i] = new WebApplet( _response, applets.item( i ), _baseTarget );
- }
- _updateApplets = false;
- }
- return _applets;
- }
-
-
- /**
- * Returns the top-level tables found in this page in the order in which
- * they appear.
- **/
- public WebTable[] getTables() {
- return WebTable.getTables( _response, getOriginalDOM(), _baseURL, _baseTarget, _characterSet );
- }
-
-
- /**
* Returns the first table in the response which matches the specified predicate and value.
* Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
@@ -355,8 +502,12 @@
if (_rootNode != null && rootNode != _rootNode )
throw new IllegalStateException( "The root node has already been defined as " + _rootNode + " and cannot be redefined as " + rootNode );
_rootNode = rootNode;
-
- _updateLinks = _updateForms = _updateImages = _updateApplets = true;
+ _links = null;
+ _forms = null;
+ _images = null;
+ _applets = null;
+ _tables = null;
+ _updateElements = true;
}
@@ -394,7 +545,7 @@
/**
* Returns true if the node is a link anchor node.
**/
- private boolean isLinkAnchor( Node node ) {
+ private boolean isLinkAnchor( Node node ) { // XXX do we really need all these tests any more?
if (node.getNodeType() != Node.ELEMENT_NODE) {
return false;
} else if (!node.getNodeName().equalsIgnoreCase( "a" ) && !node.getNodeName().equalsIgnoreCase( "area" )) {
Index: WebApplet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebApplet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebApplet.java 22 Nov 2002 17:19:35 -0000 1.3
+++ WebApplet.java 26 Dec 2002 04:59:35 -0000 1.4
@@ -42,10 +42,9 @@
* @author <a href="Oli...@HV...">Oliver Imbusch</a>
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-public class WebApplet {
+public class WebApplet extends HTMLElementBase {
private WebResponse _response;
- private Node _node;
private String _baseTarget;
private URL _codeBase;
@@ -58,8 +57,8 @@
public WebApplet( WebResponse response, Node rootNode, String baseTarget ) {
+ super( rootNode );
_response = response;
- _node = rootNode;
_baseTarget = baseTarget;
}
@@ -96,24 +95,6 @@
}
- String getAttribute( final String name ) {
- return NodeUtils.getNodeAttribute( _node, name );
- }
-
-
- String getAttribute( final String name, String defaultValue ) {
- return NodeUtils.getNodeAttribute( _node, name, defaultValue );
- }
-
-
- /**
- * Returns the name of the applet.
- */
- public String getName() {
- return getAttribute( "name" );
- }
-
-
/**
* Returns the width of the panel in which the applet will be drawn.
*/
@@ -171,7 +152,7 @@
private Map getParameterMap() {
if (_parameters == null) {
_parameters = new HashMap();
- NodeList nl = ((Element) _node).getElementsByTagName( "param" );
+ NodeList nl = ((Element) getNode()).getElementsByTagName( "param" );
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
_parameters.put( NodeUtils.getNodeAttribute( n, "name", "" ), NodeUtils.getNodeAttribute( n, "value", "" ) );
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- WebRequestSource.java 20 Nov 2002 13:04:16 -0000 1.20
+++ WebRequestSource.java 26 Dec 2002 04:59:35 -0000 1.21
@@ -31,7 +31,7 @@
abstract
-public class WebRequestSource extends ParameterHolder {
+public class WebRequestSource extends ParameterHolder implements HTMLElement {
/**
* Returns the ID associated with this request source.
@@ -97,13 +97,6 @@
**/
abstract
public String[] getParameterValues( String name );
-
-
- /**
- * Returns the scriptable delegate.
- */
- abstract
- ScriptableDelegate getScriptableDelegate();
/**
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- WebResponse.java 13 Dec 2002 12:57:11 -0000 1.104
+++ WebResponse.java 26 Dec 2002 04:59:35 -0000 1.105
@@ -286,6 +286,16 @@
//---------------------- HTMLSegment methods -----------------------------
+
+ /**
+ * Returns the HTMLElement with the specified ID.
+ * @throws SAXException thrown if there is an error parsing the response.
+ */
+ public HTMLElement getElementWithID( String id ) throws SAXException {
+ return getReceivedPage().getElementWithID( id );
+ }
+
+
/**
* Returns the forms found in the page in the order in which they appear.
* @exception SAXException thrown if there is an error parsing the response.
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WebTable.java 18 Dec 2002 23:58:10 -0000 1.21
+++ WebTable.java 26 Dec 2002 04:59:35 -0000 1.22
@@ -31,7 +31,7 @@
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
-public class WebTable {
+public class WebTable extends HTMLElementBase {
/** Predicate to match the complete text of a table's first non-blank cell. **/
@@ -207,14 +207,6 @@
}
- /**
- * Returns the unique ID attribute associated with this table.
- **/
- public String getID() {
- return NodeUtils.getNodeAttribute( _dom, "id" );
- }
-
-
public String toString() {
String eol = System.getProperty( "line.separator" );
if (_cells == null) readTable();
@@ -235,29 +227,6 @@
}
-//----------------------------------- package members -----------------------------------
-
-
- /**
- * Returns the top-level tables found in the specified DOM.
- **/
- static WebTable[] getTables( WebResponse response, Node domRoot, URL baseURL, String parentTarget, String characterSet ) {
- NodeList nl = NodeUtils.getElementsByTagName( domRoot, "table" );
- Vector topLevelTables = new Vector();
-
- for (int i = 0; i < nl.getLength(); i++) {
- if (isTopLevelTable( nl.item(i), domRoot )) {
- topLevelTables.addElement( new WebTable( response, nl.item(i), baseURL, parentTarget, characterSet ) );
- }
- }
-
- WebTable[] result = new WebTable[ topLevelTables.size() ];
- topLevelTables.copyInto( result );
- return result;
- }
-
-
-
//----------------------------------- private members -----------------------------------
private Element _dom;
@@ -270,7 +239,8 @@
private TableCell[][] _cells;
- private WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ super( domTreeRoot );
_response = response;
_dom = (Element) domTreeRoot;
_url = sourceURL;
@@ -324,7 +294,7 @@
/**
* Returns true if the specified table node is not nested within another one.
**/
- private static boolean isTopLevelTable( Node tableNode, Node root ) {
+ static boolean isTopLevelTable( Node tableNode, Node root ) {
return isMoreCloselyNested( tableNode, root, "table" );
}
@@ -416,7 +386,7 @@
}
static {
- MATCH_FIRST_NONBLANK_CELL = new HTMLElementPredicate() {
+ MATCH_FIRST_NONBLANK_CELL = new HTMLElementPredicate() { // XXX find a way to do this w/o purging the table cells
public boolean matchesCriteria( Object htmlElement, Object criteria ) {
WebTable table = ((WebTable) htmlElement);
table.purgeEmptyCells();
@@ -426,7 +396,7 @@
};
- MATCH_FIRST_NONBLANK_CELL_PREFIX = new HTMLElementPredicate() {
+ MATCH_FIRST_NONBLANK_CELL_PREFIX = new HTMLElementPredicate() { // XXX find a way to do this w/o purging the table cells
public boolean matchesCriteria( Object htmlElement, Object criteria ) {
WebTable table = ((WebTable) htmlElement);
table.purgeEmptyCells();
|
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/doc
Modified Files:
release_notes.txt
Log Message:
Adding support for getElementWithID
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.235
retrieving revision 1.236
diff -u -r1.235 -r1.236
--- release_notes.txt 25 Dec 2002 15:23:11 -0000 1.235
+++ release_notes.txt 26 Dec 2002 04:59:34 -0000 1.236
@@ -11,6 +11,11 @@
Revision History:
+25-Dec-2002
+Notes:
+ get...WithID was incorrectly doing case insensitive matches. It is now case-sensitive, since that is the way the
+ ID attribute is defined.
+
24-Dec-2002
Additions:
HTMLParserFactory now supports methods to explicitly select the parser without playing with the class path.
|
|
From: Russell G. <rus...@us...> - 2002-12-25 15:23:14
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing
In directory sc8-pr-cvs1:/tmp/cvs-serv12005/src/com/meterware/httpunit/parsing
Modified Files:
DocumentAdapter.java HTMLParser.java HTMLParserFactory.java
JTidyHTMLParser.java JTidyPrintWriter.java NekoHTMLParser.java
ScriptFilter.java
Added Files:
HTMLParserListener.java package.html
Log Message:
General cleanup of the parser classes
***** Error reading new file[Errno 2] No such file or directory: 'HTMLParserListener.java'
--- NEW FILE ---
<HTML><BODY>
<p>Classes to control HTML parsing. The primary access to this package is through
{@link com.meterware.httpunit.parsing.HTMLParserFactory}, which allows a user to select the HTML parser that will be used
to parse HTML pages returned by a {@link com.meterware.httpunit.WebClient}. In addition to selecting the actual class,
the factory also permits various options to be set on whichever parser is chosen - with the caveat that not every
parser supports every property. If the current parser does not in fact support a property, setting it on the factory
will have no effect.
</body></html>
Index: DocumentAdapter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/DocumentAdapter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocumentAdapter.java 24 Dec 2002 17:17:03 -0000 1.1
+++ DocumentAdapter.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -1,11 +1,4 @@
package com.meterware.httpunit.parsing;
-
-import org.w3c.dom.Node;
-
-import java.io.IOException;
-
-import com.meterware.httpunit.HTMLPage;
-
/********************************************************************************************************************
* $Id$
*
@@ -26,6 +19,12 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
+import org.w3c.dom.Node;
+
+import java.io.IOException;
+
/**
*
@@ -52,5 +51,5 @@
/**
* Returns the Scriptable object associated with the document
*/
- public HTMLPage.Scriptable getScriptableObject();
+ public ScriptableDelegate getScriptableObject();
}
Index: HTMLParser.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/HTMLParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HTMLParser.java 24 Dec 2002 17:17:03 -0000 1.1
+++ HTMLParser.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -56,4 +56,10 @@
* Returns true if this parser can return an HTMLDocument object.
*/
public boolean supportsReturnHTMLDocument();
+
+
+ /**
+ * Returns true if this parser can display parser warnings.
+ */
+ public boolean supportsParserWarnings();
}
Index: HTMLParserFactory.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HTMLParserFactory.java 24 Dec 2002 17:17:03 -0000 1.1
+++ HTMLParserFactory.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -19,10 +19,11 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import com.meterware.httpunit.parsing.HTMLParser;
+import java.util.Vector;
+
/**
- * Factory for creating HTML parsers. Parsers customization properties can be specified but do not necessarily work
+ * Factory for creating HTML parsers. Parser customization properties can be specified but do not necessarily work
* for every parser type.
*
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
@@ -30,12 +31,25 @@
**/
abstract public class HTMLParserFactory {
- private static HTMLParser _htmlParser;
+ private static Vector _listeners = new Vector();
private static HTMLParser _jtidyParser;
private static HTMLParser _nekoParser;
- private static boolean _preserveTagCase = false;
- private static boolean _returnHTMLDocument = true;
+ private static HTMLParser _htmlParser;
+ private static boolean _preserveTagCase;
+ private static boolean _returnHTMLDocument;
+ private static boolean _parserWarningsEnabled;
+
+
+ /**
+ * Resets all settings to their default values. This includes the parser selection.
+ */
+ public static void reset() {
+ _preserveTagCase = false;
+ _returnHTMLDocument = true;
+ _parserWarningsEnabled = false;
+ _htmlParser = null;
+ }
/**
@@ -119,9 +133,46 @@
}
- static {
- _jtidyParser = loadParserIfSupported( "org.w3c.tidy.Parser", "com.meterware.httpunit.parsing.JTidyHTMLParser" );
- _nekoParser = loadParserIfSupported( "org.cyberneko.html.HTMLConfiguration", "com.meterware.httpunit.parsing.NekoHTMLParser" );
+ /**
+ * Returns true if parser warnings are enabled.
+ **/
+ public static boolean isParserWarningsEnabled() {
+ return _parserWarningsEnabled && getHTMLParser().supportsParserWarnings();
+ }
+
+
+ /**
+ * If true, tells the parser to display warning messages. The default is false (warnings are not shown).
+ **/
+ public static void setParserWarningsEnabled( boolean enabled ) {
+ _parserWarningsEnabled = enabled;
+ }
+
+
+ /**
+ * Remove an HTML Parser listener.
+ **/
+ public static void removeHTMLParserListener( HTMLParserListener el ) {
+ _listeners.removeElement( el );
+ }
+
+
+ /**
+ * Add an HTML Parser listener.
+ **/
+ public static void addHTMLParserListener( HTMLParserListener el ) {
+ _listeners.addElement( el );
+ }
+
+
+//------------------------------------- package protected members ------------------------------------------------------
+
+
+ /**
+ * Get the list of Html Error Listeners
+ **/
+ static Vector getHTMLParserListeners() {
+ return _listeners;
}
@@ -137,8 +188,11 @@
}
- public static void reset() {
- _preserveTagCase = false;
- _returnHTMLDocument = true;
+ static {
+ _jtidyParser = loadParserIfSupported( "org.w3c.tidy.Parser", "com.meterware.httpunit.parsing.JTidyHTMLParser" );
+ _nekoParser = loadParserIfSupported( "org.cyberneko.html.HTMLConfiguration", "com.meterware.httpunit.parsing.NekoHTMLParser" );
+ reset();
}
+
+
}
Index: JTidyHTMLParser.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/JTidyHTMLParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JTidyHTMLParser.java 24 Dec 2002 17:17:03 -0000 1.1
+++ JTidyHTMLParser.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -27,9 +27,6 @@
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
-import com.meterware.httpunit.parsing.HTMLParser;
-import com.meterware.httpunit.HttpUnitOptions;
-
/**
*
@@ -62,6 +59,11 @@
}
+ public boolean supportsParserWarnings() {
+ return true;
+ }
+
+
final private static char NBSP = (char) 160; // non-breaking space, defined by JTidy
final private static String UTF_ENCODING = "UTF-8";
@@ -71,9 +73,9 @@
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 ));
+ tidy.setShowWarnings( HTMLParserFactory.isParserWarningsEnabled() );
+ if (!HTMLParserFactory.getHTMLParserListeners().isEmpty()) {
+ tidy.setErrout( new JTidyPrintWriter( url ) );
}
return tidy;
}
Index: JTidyPrintWriter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/JTidyPrintWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JTidyPrintWriter.java 24 Dec 2002 17:17:03 -0000 1.1
+++ JTidyPrintWriter.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001, Russell Gold
+* Copyright (c) 2001-2002, 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
@@ -19,9 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import com.meterware.httpunit.HttpUnitOptions;
-import com.meterware.httpunit.HtmlErrorListener;
-
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.io.PrintWriter;
@@ -201,17 +198,17 @@
}
private void reportError( String msg, int line, int column ) {
- Enumeration enum = HttpUnitOptions.getHtmlErrorListeners().elements();
+ Enumeration enum = HTMLParserFactory.getHTMLParserListeners().elements();
while (enum.hasMoreElements()) {
- ((HtmlErrorListener) enum.nextElement()).error( _url, msg, line, column );
+ ((HTMLParserListener) enum.nextElement()).error( _url, msg, line, column );
}
}
private void reportWarning( String msg, int line, int column ) {
- Enumeration enum = HttpUnitOptions.getHtmlErrorListeners().elements();
+ Enumeration enum = HTMLParserFactory.getHTMLParserListeners().elements();
while (enum.hasMoreElements()) {
- ((HtmlErrorListener) enum.nextElement()).warning( _url, msg, line, column );
+ ((HTMLParserListener) enum.nextElement()).warning( _url, msg, line, column );
}
}
}
Index: NekoHTMLParser.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/NekoHTMLParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NekoHTMLParser.java 24 Dec 2002 17:17:03 -0000 1.1
+++ NekoHTMLParser.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -70,6 +70,11 @@
}
+ public boolean supportsParserWarnings() {
+ return false;
+ }
+
+
final private static char NBSP = (char) 160; // non-breaking space, defined by nekoHTML
}
@@ -85,10 +90,10 @@
protected static final String FILTERS = "http://cyberneko.org/html/properties/filters";
/** Element case settings. possible values: "upper", "lower", "match" */
- protected static final String ELEMS = "http://cyberneko.org/html/properties/names/elems";
+ protected static final String TAG_NAME_CASE = "http://cyberneko.org/html/properties/names/elems";
/** Attribute case settings. possible values: "upper", "lower", "no-change" */
- protected static final String ATTRS = "http://cyberneko.org/html/properties/names/attrs";
+ protected static final String ATTRIBUTE_NAME_CASE = "http://cyberneko.org/html/properties/names/attrs";
private DocumentAdapter _documentAdapter;
@@ -101,8 +106,8 @@
final ScriptFilter javaScriptFilter = new ScriptFilter( configuration );
configuration.setProperty( FILTERS, new XMLDocumentFilter[] { javaScriptFilter } );
if (HTMLParserFactory.isPreserveTagCase()) {
- configuration.setProperty( ELEMS, "match" );
- configuration.setProperty( ATTRS, "no-change" );
+ configuration.setProperty( TAG_NAME_CASE, "match" );
+ configuration.setProperty( ATTRIBUTE_NAME_CASE, "no-change" );
}
try {
@@ -125,7 +130,7 @@
Node node = getCurrentElementNode();
while (!(node instanceof Document)) node = node.getParentNode();
_documentAdapter.setRootNode( node );
- _scriptableObject = _documentAdapter.getScriptableObject().getParent();
+ _scriptableObject = _documentAdapter.getScriptableObject();
}
return _scriptableObject;
}
Index: ScriptFilter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing/ScriptFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ScriptFilter.java 24 Dec 2002 17:17:03 -0000 1.1
+++ ScriptFilter.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -22,9 +22,6 @@
import java.io.IOException;
import java.io.StringReader;
-import org.cyberneko.html.HTMLConfiguration;
-import org.cyberneko.html.filters.DefaultFilter;
-
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
@@ -32,6 +29,8 @@
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLInputSource;
+
+import org.cyberneko.html.HTMLConfiguration;
import org.cyberneko.html.filters.DefaultFilter;
/**
|
|
From: Russell G. <rus...@us...> - 2002-12-25 15:23:14
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/parsing
In directory sc8-pr-cvs1:/tmp/cvs-serv12005/test/com/meterware/httpunit/parsing
Modified Files:
JTidyPrintWriterTest.java
Log Message:
General cleanup of the parser classes
Index: JTidyPrintWriterTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/parsing/JTidyPrintWriterTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JTidyPrintWriterTest.java 24 Dec 2002 17:17:04 -0000 1.1
+++ JTidyPrintWriterTest.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001, Russell Gold.
+* Copyright (c) 2001-2002, 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
@@ -19,22 +19,25 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.HttpUnitTest;
+import com.meterware.httpunit.HttpUnitOptions;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.GetMethodWebRequest;
import java.net.URL;
import java.io.PrintWriter;
import junit.framework.Test;
import junit.framework.TestSuite;
-import com.meterware.httpunit.parsing.JTidyPrintWriter;
-import com.meterware.httpunit.*;
/**
* Unit tests for valid HTML test. This is using the JTidy callback feature.
*
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-public class JTidyPrintWriterTest extends HttpUnitTest implements HtmlErrorListener {
+public class JTidyPrintWriterTest extends HttpUnitTest implements HTMLParserListener {
public static void main(String[] args) {
junit.textui.TestRunner.run( suite() );
@@ -52,14 +55,14 @@
public void setUp() throws Exception {
super.setUp();
- HttpUnitOptions.setParserWarningsEnabled(true);
- HttpUnitOptions.addHtmlErrorListener(this);
+ HTMLParserFactory.setParserWarningsEnabled(true);
+ HTMLParserFactory.addHTMLParserListener(this);
}
public void tearDown() throws Exception {
HttpUnitOptions.resetDefaultCharacterSet();
HttpUnitOptions.setAutoRefresh( false );
- HttpUnitOptions.removeHtmlErrorListener(this);
+ HTMLParserFactory.removeHTMLParserListener(this);
super.tearDown();
}
|
|
From: Russell G. <rus...@us...> - 2002-12-25 15:23:14
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv12005/doc
Modified Files:
release_notes.txt
Log Message:
General cleanup of the parser classes
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -r1.234 -r1.235
--- release_notes.txt 20 Dec 2002 01:59:47 -0000 1.234
+++ release_notes.txt 25 Dec 2002 15:23:11 -0000 1.235
@@ -11,7 +11,18 @@
Revision History:
-19-Dec-2001
+24-Dec-2002
+Additions:
+ HTMLParserFactory now supports methods to explicitly select the parser without playing with the class path.
+ This includes support for additional parsers not bundled with HttpUnit.
+
+22-Dec-2002
+ Thanks to John Sinclair for noting the lack of line breaks in manifest.mf and proposing a fix
+
+Problems fixed:
+ The manifest.mf file now has line breaks between properties
+
+19-Dec-2002
Thanks to Bernhard Wagner for adding some parser customization code.
Additions:
|
|
From: Russell G. <rus...@us...> - 2002-12-25 15:23:14
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv12005/src/com/meterware/httpunit
Modified Files:
HTMLPage.java HtmlErrorListener.java HttpUnitOptions.java
Removed Files:
JTidyPrintWriter.java
Log Message:
General cleanup of the parser classes
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- HTMLPage.java 24 Dec 2002 17:17:02 -0000 1.20
+++ HTMLPage.java 25 Dec 2002 15:23:11 -0000 1.21
@@ -260,12 +260,11 @@
}
-
public void parse( String text, URL pageURL ) throws SAXException, IOException {
HTMLParserFactory.getHTMLParser().parse( pageURL, text, new DocumentAdapter() {
public void setRootNode( Node rootNode ) { HTMLPage.this.setRootNode( rootNode ); }
public String getIncludedScript( String srcAttribute ) throws IOException { return HTMLPage.this.getIncludedScript( srcAttribute ); }
- public Scriptable getScriptableObject() { return HTMLPage.this.getScriptableObject(); }
+ public ScriptableDelegate getScriptableObject() { return HTMLPage.this.getScriptableObject().getParent(); }
});
}
Index: HtmlErrorListener.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HtmlErrorListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HtmlErrorListener.java 14 Nov 2001 17:11:28 -0000 1.1
+++ HtmlErrorListener.java 25 Dec 2002 15:23:11 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001, Russell Gold
+* Copyright (c) 2001-2002, 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
@@ -19,24 +19,17 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.net.URL;
+import com.meterware.httpunit.parsing.HTMLParserListener;
/**
* This interface represents a listener which can receive notification of errors and warnings during the parsing
* of an HTML page.
*
+ * @deprecated as of 1.5.2, use HTMLParserListener
+ *
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-public interface HtmlErrorListener {
-
- /**
- * callback for HTML warning.
- **/
- public void warning( URL url, String msg, int line, int column );
+public interface HtmlErrorListener extends HTMLParserListener {
- /**
- * callback for HTML errors.
- **/
- public void error( URL url, String msg, int line, int column );
}
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- HttpUnitOptions.java 20 Dec 2002 01:59:47 -0000 1.35
+++ HttpUnitOptions.java 25 Dec 2002 15:23:11 -0000 1.36
@@ -21,6 +21,8 @@
*******************************************************************************************************************/
import com.meterware.httpunit.scripting.ScriptingEngineFactory;
+import com.meterware.httpunit.parsing.HTMLParserListener;
+import com.meterware.httpunit.parsing.HTMLParserFactory;
import java.util.Vector;
@@ -40,7 +42,7 @@
* Resets all options to their default values.
*/
public static void reset() {
- _parserWarningsEnabled = false;
+ HTMLParserFactory.reset();
_exceptionsOnErrorStatus = true;
_parameterValuesValidated = true;
_imagesTreatedAsAltText = false;
@@ -182,9 +184,19 @@
/**
* Returns true if parser warnings are enabled.
+ * @deprecated as of 1.5.2, use HTMLParserFactory#isParserWarningsEnabled
**/
public static boolean getParserWarningsEnabled() {
- return _parserWarningsEnabled;
+ return HTMLParserFactory.isParserWarningsEnabled();
+ }
+
+
+ /**
+ * If true, tells the parser to display warning messages. The default is false (warnings are not shown).
+ * @deprecated as of 1.5.2, use HTMLParserFactory#setParserWarningsEnabled
+ **/
+ public static void setParserWarningsEnabled( boolean enabled ) {
+ HTMLParserFactory.setParserWarningsEnabled( enabled );
}
@@ -206,14 +218,6 @@
/**
- * If true, tells the parser to display warning messages. The default is false (warnings are not shown).
- **/
- public static void setParserWarningsEnabled( boolean enabled ) {
- _parserWarningsEnabled = enabled;
- }
-
-
- /**
* Returns true if form parameter settings are checked.
**/
public static boolean getParameterValuesValidated() {
@@ -341,25 +345,29 @@
_autoRefresh = autoRefresh;
}
+
/**
* Remove an Html error listener.
+ * @deprecated as of 1.5.2, use HTMLParserfactory#removeHTMLParserListener
**/
- public static void removeHtmlErrorListener(HtmlErrorListener el) {
- _listeners.removeElement(el);
+ public static void removeHtmlErrorListener(HTMLParserListener el) {
+ HTMLParserFactory.removeHTMLParserListener( el );
}
/**
* Add an Html error listener.
+ * @deprecated as of 1.5.2, use HTMLParserfactory#addHTMLParserListener
**/
- public static void addHtmlErrorListener(HtmlErrorListener el) {
- _listeners.addElement(el);
+ public static void addHtmlErrorListener(HTMLParserListener el) {
+ HTMLParserFactory.addHTMLParserListener( el );
}
/**
* Get the list of Html Error Listeners
+ * @deprecated as of 1.5.2, removed with no replacement
**/
public static Vector getHtmlErrorListeners() {
- return _listeners;
+ return null;
}
@@ -470,8 +478,6 @@
private static boolean _acceptCookies = true;
- private static boolean _parserWarningsEnabled;
-
private static boolean _exceptionsOnErrorStatus = true;
private static boolean _parameterValuesValidated = true;
@@ -496,8 +502,6 @@
private static String _contentType = DEFAULT_CONTENT_TYPE;
- private static Vector _listeners;
-
private static String _scriptEngineClassName;
private static ScriptingEngineFactory _scriptingEngine;
@@ -508,7 +512,6 @@
static {
- _listeners = new Vector();
reset();
}
|
|
From: Russell G. <rus...@us...> - 2002-12-24 17:17:36
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv13328/test/com/meterware/httpunit
Modified Files:
HttpUnitSuite.java
Removed Files:
JTidyPrintWriterTest.java ParserPropertiesTest.java
Log Message:
HTML parser is now settable
Index: HttpUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- HttpUnitSuite.java 20 Dec 2002 01:59:47 -0000 1.29
+++ HttpUnitSuite.java 24 Dec 2002 17:17:03 -0000 1.30
@@ -22,12 +22,10 @@
import com.meterware.pseudoserver.PseudoServerTest;
import com.meterware.httpunit.cookies.CookieTest;
import com.meterware.httpunit.javascript.NekoEnhancedScriptingTest;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
+import com.meterware.httpunit.parsing.HTMLParserFactory;
+import com.meterware.httpunit.parsing.ParsingTestSuite;
import junit.framework.TestSuite;
-import junit.framework.TestCase;
/**
@@ -57,9 +55,8 @@
result.addTest( WebClientTest.suite() );
result.addTest( MessageBodyRequestTest.suite() );
result.addTest( CookieTest.suite() );
- result.addTest( ParserPropertiesTest.suite() );
+ result.addTest( ParsingTestSuite.suite() );
- if (HTMLParserFactory.getHTMLParser().getClass().getName().indexOf("Tidy") >= 0) result.addTest( JTidyPrintWriterTest.suite() );
if (HTMLParserFactory.getHTMLParser().getClass().getName().indexOf("NekoHTML") >= 0) result.addTest( NekoEnhancedScriptingTest.suite() );
addOptionalTestCase( result, "com.meterware.httpunit.XMLPageTest" );
addOptionalTestCase( result, "com.meterware.httpunit.FileUploadTest" );
|
|
From: Russell G. <rus...@us...> - 2002-12-24 17:17:36
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv13328/src/com/meterware/httpunit
Modified Files:
HTMLPage.java NodeUtils.java ParsedHTML.java
Removed Files:
HTMLParser.java HTMLParserFactory.java JTidyHTMLParser.java
NekoHTMLParser.java ScriptFilter.java
Log Message:
HTML parser is now settable
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- HTMLPage.java 20 Dec 2002 01:59:47 -0000 1.19
+++ HTMLPage.java 24 Dec 2002 17:17:02 -0000 1.20
@@ -21,6 +21,8 @@
*******************************************************************************************************************/
import com.meterware.httpunit.scripting.NamedDelegate;
import com.meterware.httpunit.scripting.ScriptableDelegate;
+import com.meterware.httpunit.parsing.HTMLParserFactory;
+import com.meterware.httpunit.parsing.DocumentAdapter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -260,7 +262,11 @@
public void parse( String text, URL pageURL ) throws SAXException, IOException {
- HTMLParserFactory.getHTMLParser().parse( this, pageURL, text );
+ HTMLParserFactory.getHTMLParser().parse( pageURL, text, new DocumentAdapter() {
+ public void setRootNode( Node rootNode ) { HTMLPage.this.setRootNode( rootNode ); }
+ public String getIncludedScript( String srcAttribute ) throws IOException { return HTMLPage.this.getIncludedScript( srcAttribute ); }
+ public Scriptable getScriptableObject() { return HTMLPage.this.getScriptableObject(); }
+ });
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- NodeUtils.java 20 Dec 2002 01:59:47 -0000 1.14
+++ NodeUtils.java 24 Dec 2002 17:17:02 -0000 1.15
@@ -27,6 +27,8 @@
import java.util.Stack;
+import com.meterware.httpunit.parsing.HTMLParserFactory;
+
/**
* Some common utilities for manipulating DOM nodes.
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- ParsedHTML.java 18 Dec 2002 23:58:10 -0000 1.37
+++ ParsedHTML.java 24 Dec 2002 17:17:02 -0000 1.38
@@ -351,7 +351,7 @@
/**
* Specifies the root node for this HTML fragment.
*/
- protected void setRootNode( Node rootNode ) {
+ void setRootNode( Node rootNode ) {
if (_rootNode != null && rootNode != _rootNode )
throw new IllegalStateException( "The root node has already been defined as " + _rootNode + " and cannot be redefined as " + rootNode );
_rootNode = rootNode;
|
|
From: Russell G. <rus...@us...> - 2002-12-24 17:17:35
|
Update of /cvsroot/httpunit/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv13328
Modified Files:
build.xml
Log Message:
HTML parser is now settable
Index: build.xml
===================================================================
RCS file: /cvsroot/httpunit/httpunit/build.xml,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- build.xml 22 Dec 2002 13:59:08 -0000 1.61
+++ build.xml 24 Dec 2002 17:17:02 -0000 1.62
@@ -28,7 +28,7 @@
<property name="archive.dir" value="${dist.dir}/${name}-${version}" />
<property name="classpath" value="" />
<property name="web.dir" value="web" />
- <property name="packages" value="com.meterware.httpunit,com.meterware.servletunit,com.meterware.pseudoserver,com.meterware.httpunit.cookies" />
+ <property name="packages" value="com.meterware.httpunit,com.meterware.servletunit,com.meterware.pseudoserver,com.meterware.httpunit.cookies,com.meterware.httpunit.parsing" />
<property name="test.class" value="com.meterware.httpunit.HttpUnitSuite" />
<property name="servlet.test.class" value="com.meterware.servletunit.ServletUnitSuite" />
|
|
From: Russell G. <rus...@us...> - 2002-12-24 17:17:08
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/parsing In directory sc8-pr-cvs1:/tmp/cvs-serv13328/test/com/meterware/httpunit/parsing Added Files: JTidyPrintWriterTest.java ParserPropertiesTest.java ParsingTestSuite.java Log Message: HTML parser is now settable ***** Error reading new file[Errno 2] No such file or directory: 'JTidyPrintWriterTest.java' ***** Error reading new file[Errno 2] No such file or directory: 'ParserPropertiesTest.java' ***** Error reading new file[Errno 2] No such file or directory: 'ParsingTestSuite.java' |
|
From: Russell G. <rus...@us...> - 2002-12-24 17:17:06
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing In directory sc8-pr-cvs1:/tmp/cvs-serv13328/src/com/meterware/httpunit/parsing Added Files: DocumentAdapter.java HTMLParser.java HTMLParserFactory.java JTidyHTMLParser.java JTidyPrintWriter.java NekoHTMLParser.java ScriptFilter.java Log Message: HTML parser is now settable ***** Error reading new file[Errno 2] No such file or directory: 'DocumentAdapter.java' ***** Error reading new file[Errno 2] No such file or directory: 'HTMLParser.java' ***** Error reading new file[Errno 2] No such file or directory: 'HTMLParserFactory.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: 'JTidyPrintWriter.java' ***** Error reading new file[Errno 2] No such file or directory: 'NekoHTMLParser.java' ***** Error reading new file[Errno 2] No such file or directory: 'ScriptFilter.java' |
|
From: Russell G. <rus...@us...> - 2002-12-24 17:01:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/parsing In directory sc8-pr-cvs1:/tmp/cvs-serv9021/test/com/meterware/httpunit/parsing Log Message: Directory /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/parsing added to the repository |
|
From: Russell G. <rus...@us...> - 2002-12-24 17:01:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing In directory sc8-pr-cvs1:/tmp/cvs-serv9021/src/com/meterware/httpunit/parsing Log Message: Directory /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/parsing added to the repository |
|
From: Russell G. <rus...@us...> - 2002-12-24 15:17:21
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4233/src/com/meterware/httpunit
Modified Files:
Base64.java
Log Message:
Added JavaDoc
Index: Base64.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Base64.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Base64.java 21 Mar 2002 15:44:03 -0000 1.3
+++ Base64.java 24 Dec 2002 15:17:17 -0000 1.4
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2002 by 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
@@ -19,10 +19,21 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+
+/**
+ * A utility class to convert to and from base 64 encoding.
+ *
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
+ **/
public class Base64 {
final static String encodingChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ /**
+ * Returns the base 64 encoded equivalent of a supplied string.
+ * @param source the string to encode
+ */
public static String encode( String source ) {
char[] sourceBytes = getPaddedBytes( source );
int numGroups = (sourceBytes.length + 2) / 3;
@@ -60,6 +71,10 @@
}
+ /**
+ * Returns the plaintext equivalent of a base 64-encoded string.
+ * @param source a base 64 string (which must have a multiple of 4 characters)
+ */
public static String decode( String source ) {
if (source.length()%4 != 0) throw new RuntimeException( "valid Base64 codes have a multiple of 4 characters" );
int numGroups = source.length() / 4;
|