[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLElementScriptable.java,NONE,1.1 FormC
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-12-30 21:47:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv25347/src/com/meterware/httpunit
Modified Files:
FormControl.java HTMLElementBase.java HTMLPage.java
ParsedHTML.java TableCell.java WebApplet.java WebForm.java
WebLink.java WebTable.java
Added Files:
HTMLElementScriptable.java
Log Message:
Added document.getElementByID support
***** Error reading new file[Errno 2] No such file or directory: 'HTMLElementScriptable.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- FormControl.java 26 Dec 2002 18:55:18 -0000 1.32
+++ FormControl.java 30 Dec 2002 21:46:54 -0000 1.33
@@ -49,10 +49,7 @@
private final String _onClickEvent;
private final WebForm _form;
- private Scriptable _scriptable;
-
-
- FormControl( WebForm form ) {
+ FormControl( WebForm form ) {
super( newEmptyNode( form ) );
_form = form;
_valueAttribute = "";
@@ -100,15 +97,8 @@
}
- /**
- * Returns a scriptable object which can act as a proxy for this control.
- */
- public ScriptableDelegate getScriptableDelegate() {
- if (_scriptable == null) {
- _scriptable = newScriptable();
- _scriptable.setScriptEngine( getForm().getScriptableObject().getScriptEngine( _scriptable ) );
- }
- return _scriptable;
+ protected ScriptableDelegate getParentDelegate() {
+ return getForm().getScriptableDelegate();
}
@@ -234,7 +224,7 @@
* Creates and returns a scriptable object for this control. Subclasses should override this if they use a different
* implementation of Scriptable.
*/
- protected Scriptable newScriptable() {
+ protected ScriptableDelegate newScriptable() {
return new Scriptable();
}
@@ -304,7 +294,7 @@
}
- class Scriptable extends ScriptableDelegate implements Input {
+ class Scriptable extends HTMLElementScriptable implements Input {
public String getName() {
return FormControl.this.getName();
@@ -327,6 +317,11 @@
super.set( propertyName, value );
}
}
+
+
+ public Scriptable() {
+ super( FormControl.this );
+ }
}
}
@@ -340,7 +335,7 @@
private final boolean _isCheckedDefault;
- protected FormControl.Scriptable newScriptable() {
+ protected ScriptableDelegate newScriptable() {
return new Scriptable();
}
@@ -615,7 +610,7 @@
}
- protected FormControl.Scriptable newScriptable() {
+ protected ScriptableDelegate newScriptable() {
return new Scriptable();
}
@@ -723,7 +718,7 @@
private UploadFileSpec _fileToUpload;
- protected FormControl.Scriptable newScriptable() {
+ protected ScriptableDelegate newScriptable() {
return new Scriptable();
}
@@ -857,7 +852,7 @@
}
- protected FormControl.Scriptable newScriptable() {
+ protected ScriptableDelegate newScriptable() {
return new Scriptable();
}
Index: HTMLElementBase.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLElementBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HTMLElementBase.java 26 Dec 2002 04:59:35 -0000 1.1
+++ HTMLElementBase.java 30 Dec 2002 21:46:54 -0000 1.2
@@ -19,9 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import com.meterware.httpunit.scripting.ScriptableDelegate;
-
import org.w3c.dom.Node;
+import com.meterware.httpunit.scripting.ScriptableDelegate;
/**
@@ -33,6 +32,8 @@
class HTMLElementBase implements HTMLElement {
private Node _node;
+ private ScriptableDelegate _scriptable;
+
public String getID() {
@@ -51,10 +52,14 @@
/**
- * Returns the delegate which supports scripting this element.
+ * Returns a scriptable object which can act as a proxy for this control.
*/
public ScriptableDelegate getScriptableDelegate() {
- throw new RuntimeException( "No scripting support for " + getClass().getName() );
+ if (_scriptable == null) {
+ _scriptable = newScriptable();
+ _scriptable.setScriptEngine( getParentDelegate().getScriptEngine( _scriptable ) );
+ }
+ return _scriptable;
}
@@ -76,4 +81,19 @@
protected Node getNode() {
return _node;
}
+
+
+ /**
+ * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different
+ * implementation of Scriptable.
+ */
+ abstract protected ScriptableDelegate newScriptable();
+
+
+ /**
+ * Returns the scriptable delegate which can provide the scriptable delegate for this element.
+ */
+ abstract protected ScriptableDelegate getParentDelegate();
+
+
}
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- HTMLPage.java 25 Dec 2002 15:23:11 -0000 1.21
+++ HTMLPage.java 30 Dec 2002 21:46:54 -0000 1.22
@@ -248,6 +248,12 @@
public String getCookie() {
return getResponse().getCookieHeader();
}
+
+
+ public ScriptableDelegate getElementWithID( String id ) {
+ final HTMLElement elementWithID = HTMLPage.this.getElementWithID( id );
+ return elementWithID == null ? null : elementWithID.getScriptableDelegate();
+ }
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- ParsedHTML.java 26 Dec 2002 20:50:48 -0000 1.42
+++ ParsedHTML.java 30 Dec 2002 21:46:54 -0000 1.43
@@ -28,6 +28,8 @@
import java.util.Iterator;
import java.util.Arrays;
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
/**
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
@@ -226,6 +228,25 @@
}
+ static class DefaultElementFactory extends HTMLElementFactory {
+
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ if (element.getAttribute( "id" ).equals( "" )) return null;
+ return parsedHTML.toDefaultElement( element );
+ }
+
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {}
+ }
+
+
+ private HTMLElement toDefaultElement( Element element ) {
+ return new HTMLElementBase( element ) {
+ protected ScriptableDelegate newScriptable() { return new HTMLElementScriptable( this ); }
+ protected ScriptableDelegate getParentDelegate() { return getResponse().getScriptableObject().getDocument(); }
+ };
+ }
+
+
static class WebFormFactory extends HTMLElementFactory {
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebForm( element );
@@ -257,6 +278,7 @@
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebApplet( element );
}
+ protected boolean addToContext() { return true; }
}
@@ -319,6 +341,7 @@
private static HashMap _htmlFactoryClasses = new HashMap();
+ private static HTMLElementFactory _defaultFactory = new DefaultElementFactory();
static {
_htmlFactoryClasses.put( "a", new WebLinkFactory() );
@@ -337,7 +360,8 @@
}
private static HTMLElementFactory getHTMLElementFactory( String tagName ) {
- return (HTMLElementFactory) _htmlFactoryClasses.get( tagName );
+ final HTMLElementFactory factory = (HTMLElementFactory) _htmlFactoryClasses.get( tagName );
+ return factory != null ? factory : _defaultFactory;
}
Index: TableCell.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TableCell.java 26 Dec 2002 15:33:56 -0000 1.9
+++ TableCell.java 30 Dec 2002 21:46:54 -0000 1.10
@@ -32,7 +32,9 @@
**/
public class TableCell extends ParsedHTML implements HTMLSegment, HTMLElement {
-
+ private ScriptableDelegate _scriptable;
+
+
/**
* Returns the number of columns spanned by this cell.
**/
@@ -96,7 +98,11 @@
* Returns the delegate which supports scripting this element.
*/
public ScriptableDelegate getScriptableDelegate() {
- throw new RuntimeException( "No scripting support for " + getClass().getName() );
+ if (_scriptable == null) {
+ _scriptable = new HTMLElementScriptable( this );
+ _scriptable.setScriptEngine( getResponse().getScriptableObject().getDocument().getScriptEngine( _scriptable ) );
+ }
+ return _scriptable;
}
Index: WebApplet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebApplet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebApplet.java 26 Dec 2002 04:59:35 -0000 1.4
+++ WebApplet.java 30 Dec 2002 21:46:54 -0000 1.5
@@ -34,6 +34,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import com.meterware.httpunit.scripting.ScriptableDelegate;
/**
@@ -205,6 +206,16 @@
throw new RuntimeException( e.toString() );
} catch (SAXException e) {
}
+ }
+
+
+ protected ScriptableDelegate newScriptable() {
+ return new HTMLElementScriptable( this );
+ }
+
+
+ protected ScriptableDelegate getParentDelegate() {
+ return _response.getScriptableObject().getDocument();
}
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- WebForm.java 27 Dec 2002 05:09:38 -0000 1.74
+++ WebForm.java 30 Dec 2002 21:46:55 -0000 1.75
@@ -510,7 +510,7 @@
}
- public class Scriptable extends ScriptableDelegate implements NamedDelegate {
+ public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; }
@@ -535,7 +535,7 @@
return getTarget();
} else {
final FormParameter parameter = getParameter( propertyName );
- return parameter == UNKNOWN_PARAMETER ? null : parameter.getScriptableObject();
+ return parameter == UNKNOWN_PARAMETER ? super.get( propertyName ) : parameter.getScriptableObject();
}
}
@@ -570,6 +570,11 @@
result[i] = controls[i].getScriptableDelegate();
}
return result;
+ }
+
+
+ Scriptable() {
+ super( WebForm.this );
}
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- WebLink.java 26 Dec 2002 15:33:56 -0000 1.37
+++ WebLink.java 30 Dec 2002 21:46:55 -0000 1.38
@@ -101,7 +101,12 @@
}
- public class Scriptable extends ScriptableDelegate implements NamedDelegate {
+ public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
+
+ public Scriptable() {
+ super( WebLink.this );
+ }
+
public String getName() {
return WebLink.this.getName();
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- WebTable.java 26 Dec 2002 15:33:56 -0000 1.23
+++ WebTable.java 30 Dec 2002 21:46:55 -0000 1.24
@@ -24,6 +24,7 @@
import java.util.*;
import org.w3c.dom.*;
+import com.meterware.httpunit.scripting.ScriptableDelegate;
/**
* This class represents a table in an HTML page.
@@ -226,6 +227,16 @@
}
+ protected ScriptableDelegate newScriptable() {
+ return new HTMLElementScriptable( this );
+ }
+
+
+ protected ScriptableDelegate getParentDelegate() {
+ return _response.getScriptableObject().getDocument();
+ }
+
+
//----------------------------------- private members -----------------------------------
private Element _dom;
@@ -331,6 +342,15 @@
_cells.add( cell );
}
+
+ protected ScriptableDelegate newScriptable() {
+ return new HTMLElementScriptable( this );
+ }
+
+
+ protected ScriptableDelegate getParentDelegate() {
+ return _response.getScriptableObject().getDocument();
+ }
}
|