/** * Contructs a web form given the URL of its source page and the DOM extracted * from that page. **/ WebForm( WebResponse response, URL baseURL, Node node, FrameSelector frame, String defaultTarget, String characterSet, ElementRegistry registry ) { super( response, node, baseURL, "action", frame, defaultTarget ); _characterSet = characterSet; _registry = registry; _domElement = (HTMLFormElement) node; }
public HTMLCollection getElements() { ArrayList elements = new ArrayList(); String[] names = new String[]{"INPUT", "TEXTAREA", "BUTTON", "SELECT"}; for (Iterator each = preOrderIteratorAfterNode(); each.hasNext();) { Node node = (Node) each.next(); if (node instanceof HTMLFormElement) break; if (node.getNodeType() != ELEMENT_NODE) continue; String tagName = ((Element) node).getTagName(); for (int i = 0; i < names.length; i++) { if (tagName.equalsIgnoreCase( names[i] )) elements.add( node ); } } return HTMLCollectionImpl.createHTMLCollectionImpl( new NodeListImpl( elements ) ); }
public HTMLFormElement getForm() { Node parent = getParentNode(); while (parent != null && !("form".equalsIgnoreCase( parent.getNodeName() ))) parent = parent.getParentNode(); if (parent != null) return (HTMLFormElement) parent; for (Iterator here = preOrderIterator(); here.hasNext();) { Object o = here.next(); if (o instanceof HTMLFormElement) return getPreviousForm( (HTMLFormElement) o ); } return getLastFormInDocument(); }
private HTMLFormElement getPreviousForm( HTMLFormElement nextForm ) { HTMLCollection forms = getHtmlDocument().getForms(); for (int i = 0; i < forms.getLength(); i++) { if (nextForm == forms.item( i )) return i == 0 ? null : (HTMLFormElement) forms.item( i-1 ); } return null; }
/** * Convenience method returns the form in which this form element is contained. * This method is exposed for form elements through the DOM API, but other * elements have no access to it through the API. */ public HTMLFormElement getForm() { Node parent = getParentNode(); while ( parent != null ) { if ( parent instanceof HTMLFormElement ) { return (HTMLFormElement) parent; } parent = parent.getParentNode(); } return null; }
@Override public Optional<Form> getForm() { if (element instanceof HTMLFormElement) { return Optional.of(new Form(this)); } return Optional.empty(); }
private HTMLFormElement getLastFormInDocument() { HTMLCollection forms = getHtmlDocument().getForms(); return forms.getLength() == 0 ? null : (HTMLFormElement) forms.item( forms.getLength()-1 ); }
@JSProperty HTMLFormElement getForm();