public void save(final HtmlPage page, final File file) throws IOException { webClient_ = page.getWebClient(); String fileName = file.getName(); if (!fileName.endsWith(".htm") && !fileName.endsWith(".html")) { fileName += ".html"; } final File outputFile = new File(file.getParentFile(), fileName); if (outputFile.exists()) { throw new IOException("File already exists: " + outputFile); } fileName = fileName.substring(0, fileName.lastIndexOf('.')); outputDir_ = new File(file.getParentFile(), fileName); FileUtils.writeStringToFile(outputFile, asXml(page.getDocumentElement())); }
private ScriptResult executeJavaScriptFunction(final Function function, final Scriptable thisObject, final Object[] args, final DomNode htmlElementScope) { final JavaScriptEngine engine = (JavaScriptEngine) getWebClient().getJavaScriptEngine(); final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope); return new ScriptResult(result); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getWebRequest()); }
private void callFunction(final Function function, final Object[] args) { if (function == null) { return; } final Scriptable scope = function.getParentScope(); final JavaScriptEngine engine = (JavaScriptEngine) containingPage_.getWebClient().getJavaScriptEngine(); engine.callFunction(containingPage_, function, scope, WebSocket.this, args); } }
/** {@inheritDoc} */ public void comment(final char[] ch, final int start, final int length) { handleCharacters(); final String data = String.valueOf(ch, start, length); if (!data.startsWith("[CDATA") || !page_.getWebClient().getBrowserVersion().isIE()) { final DomComment comment = new DomComment(page_, data); currentNode_.appendChild(comment); } }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
/** {@inheritDoc} */ public void comment(final char[] ch, final int start, final int length) { handleCharacters(); final String data = String.valueOf(ch, start, length); if (!data.startsWith("[CDATA") || !page_.getWebClient().getBrowserVersion().isIE()) { final DomComment comment = new DomComment(page_, data); currentNode_.appendChild(comment); } }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
/** {@inheritDoc} */ public void comment(final char[] ch, final int start, final int length) { handleCharacters(); final String data = String.valueOf(ch, start, length); if (!data.startsWith("[CDATA") || !page_.getWebClient().getBrowserVersion().isIE()) { final DomComment comment = new DomComment(page_, data); currentNode_.appendChild(comment); } }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
private ScriptResult executeJavaScriptFunction(final Function function, final Scriptable thisObject, final Object[] args, final DomNode htmlElementScope) { final JavaScriptEngine engine = (JavaScriptEngine) getWebClient().getJavaScriptEngine(); final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope); return new ScriptResult(result); }
private void callFunction(final Function function, final Object[] args) { if (function == null) { return; } final Scriptable scope = function.getParentScope(); final JavaScriptEngine engine = (JavaScriptEngine) containingPage_.getWebClient().getJavaScriptEngine(); engine.callFunction(containingPage_, function, scope, WebSocket.this, args); } }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getWebRequest()); }
/** * Adds a cookie, as long as cookies are enabled. * @see <a href="http://msdn.microsoft.com/en-us/library/ms533693.aspx">MSDN documentation</a> * @param newCookie in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure] */ @JsxSetter public void setCookie(final String newCookie) { final HtmlPage page = getPage(); final WebClient client = page.getWebClient(); client.addCookie(newCookie, getPage().getUrl(), this); }
/** * Adds a cookie, as long as cookies are enabled. * @see <a href="http://msdn.microsoft.com/en-us/library/ms533693.aspx">MSDN documentation</a> * @param newCookie in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure] */ @JsxSetter public void setCookie(final String newCookie) { final HtmlPage page = getPage(); final WebClient client = page.getWebClient(); client.addCookie(newCookie, getPage().getUrl(), this); }
/** * Deregister frames that are no longer in use. */ public void deregisterFramesIfNeeded() { for (final WebWindow window : getFrames()) { getWebClient().deregisterWebWindow(window); final Page page = window.getEnclosedPage(); if (page != null && page.isHtmlPage()) { // seems quite silly, but for instance if the src attribute of an iframe is not // set, the error only occurs when leaving the page ((HtmlPage) page).deregisterFramesIfNeeded(); } } }
private void fire(final Event evt) { evt.setTarget(WebSocket.this); evt.setParentScope(getParentScope()); evt.setPrototype(getPrototype(evt.getClass())); final JavaScriptEngine engine = (JavaScriptEngine) containingPage_.getWebClient().getJavaScriptEngine(); engine.getContextFactory().call(cx -> { executeEventLocally(evt); return null; }); }
private void fire(final Event evt) { evt.setTarget(WebSocket.this); evt.setParentScope(getParentScope()); evt.setPrototype(getPrototype(evt.getClass())); final JavaScriptEngine engine = (JavaScriptEngine) containingPage_.getWebClient().getJavaScriptEngine(); engine.getContextFactory().call(cx -> { executeEventLocally(evt); return null; }); }
/** * Returns an auto-refresh string if specified. This will look in both the meta * tags (taking care of <noscript> if any) and inside the HTTP response headers. * @return the auto-refresh string */ private String getRefreshStringOrNull() { final boolean javaScriptEnabled = getWebClient().isJavaScriptEnabled(); for (final HtmlMeta meta : getMetaTags("refresh")) { if ((!javaScriptEnabled || getFirstParent(meta, HtmlNoScript.TAG_NAME) == null)) { return meta.getContentAttribute(); } } return getWebResponse().getResponseHeaderValue("Refresh"); }
/** * Returns an auto-refresh string if specified. This will look in both the meta * tags (taking care of <noscript> if any) and inside the HTTP response headers. * @return the auto-refresh string */ private String getRefreshStringOrNull() { final boolean javaScriptEnabled = getWebClient().isJavaScriptEnabled(); for (final HtmlMeta meta : getMetaTags("refresh")) { if ((!javaScriptEnabled || getFirstParent(meta, HtmlNoScript.TAG_NAME) == null)) { return meta.getContentAttribute(); } } return getWebResponse().getResponseHeaderValue("Refresh"); }