/** * JavaScript constructor. This must be declared in every JavaScript file because the rhino engine * won't walk up the hierarchy looking for constructors. * * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ public void jsConstructor( final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME) .createElement(page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (newText != null && !newText.equals("undefined")) { htmlOption.appendChild(new DomText(page, newText)); } if (newValue != null && !newValue.equals("undefined")) { htmlOption.setValueAttribute(newValue); } }
/** * Adds the option (and create the associated DOM node if needed) before the specified one or at * the end if the specified one in null. * * @param newOptionObject the new option to add * @param beforeOption the option that should be after the option to add */ protected void addBefore(final HTMLOptionElement newOptionObject, final HtmlOption beforeOption) { final HtmlSelect select = getHtmlSelect(); HtmlOption htmlOption = newOptionObject.getDomNodeOrNull(); if (htmlOption == null) { htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME) .createElement(select.getPage(), HtmlOption.TAG_NAME, null); } if (beforeOption == null) { select.appendChild(htmlOption); } else { beforeOption.insertBefore(htmlOption); } }
/** * @param xmlSample * @return * @throws MalformedURLException * @throws IOException */ protected HtmlElement createHtmlElement(String xmlSample) throws MalformedURLException, IOException { String xmlSampleWithTags = "<table><tr><div id=\"maxtest2\"" + xmlSample + "</div></tr></table>"; URL url = new URL("http://www.example.com"); StringWebResponse response = new StringWebResponse(xmlSampleWithTags, url); WebClient client = new WebClient(); HtmlPage page = HTMLParser.parseHtml(response, client.getCurrentWindow()); // HtmlElement element = page.getHtmlElementById("maxtest"); HtmlElement element = page.getHtmlElementById("maxtest2"); Iterable<HtmlElement> children = element.getChildElements(); Iterator<HtmlElement> iter = children.iterator(); return iter.next(); }
/* 141: */ /* 142: */ protected XHtmlPage createXHtmlPage(WebResponse webResponse, WebWindow webWindow) /* 143: */ throws IOException /* 144: */ { /* 145:233 */ return HTMLParser.parseXHtml(webResponse, webWindow); /* 146: */ }
/* 135: */ /* 136: */ protected HtmlPage createHtmlPage(WebResponse webResponse, WebWindow webWindow) /* 137: */ throws IOException /* 138: */ { /* 139:221 */ return HTMLParser.parseHtml(webResponse, webWindow); /* 140: */ }