@Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } };
@Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } };
private Map<String, DomAttr> getAttributesFor(final BaseFrameElement frame) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(frame, "src"); final DomAttr srcAttr = map.get("src"); if (srcAttr == null) { return map; } final Page enclosedPage = frame.getEnclosedPage(); final String suffix = getFileExtension(enclosedPage); final File file = createFile(srcAttr.getValue(), "." + suffix); if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { file.delete(); // TODO: refactor as it is stupid to create empty file at one place // and then to complain that it already exists ((HtmlPage) enclosedPage).save(file); } else { try (InputStream is = enclosedPage.getWebResponse().getContentAsStream()) { try (FileOutputStream fos = new FileOutputStream(file)) { IOUtils.copyLarge(is, fos); } } } } srcAttr.setValue(file.getParentFile().getName() + FILE_SEPARATOR + file.getName()); return map; }
private Map<String, DomAttr> getAttributesFor(final BaseFrameElement frame) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(frame, DomElement.SRC_ATTRIBUTE); final DomAttr srcAttr = map.get(DomElement.SRC_ATTRIBUTE); if (srcAttr == null) { return map; } final Page enclosedPage = frame.getEnclosedPage(); final String suffix = getFileExtension(enclosedPage); final File file = createFile(srcAttr.getValue(), "." + suffix); if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { file.delete(); // TODO: refactor as it is stupid to create empty file at one place // and then to complain that it already exists ((HtmlPage) enclosedPage).save(file); } else { try (InputStream is = enclosedPage.getWebResponse().getContentAsStream()) { try (OutputStream fos = Files.newOutputStream(file.toPath())) { IOUtils.copyLarge(is, fos); } } } } srcAttr.setValue(file.getParentFile().getName() + FILE_SEPARATOR + file.getName()); return map; }
/** * Loads the content of the contained frames. This is done after the page is completely loaded, to allow script * contained in the frames to reference elements from the page located after the closing </frame> tag. * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClient#setThrowExceptionOnFailingStatusCode(boolean)} is set to {@code true} */ void loadFrames() throws FailingHttpStatusCodeException { for (final FrameWindow w : getFrames()) { final BaseFrameElement frame = w.getFrameElement(); // test if the frame should really be loaded: // if a script has already changed its content, it should be skipped // use == and not equals(...) to identify initial content (versus URL set to "about:blank") if (frame.getEnclosedWindow() != null && WebClient.URL_ABOUT_BLANK == frame.getEnclosedPage().getUrl() && !frame.isContentLoaded()) { frame.loadInnerPage(); } } }
private void loadSrc() { loadSrcWhenAddedToPage_ = false; final String src = getSrcAttribute(); final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); // When src is set from a script, loading is postponed until script finishes // in fact this implementation is probably wrong: JavaScript URL should be // first evaluated and only loading, when any, should be postponed. if (!jsEngine.isScriptRunning() || src.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { loadInnerPageIfPossible(src); } else { final Page pageInFrame = getEnclosedPage(); final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { if (!src.isEmpty() && getSrcAttribute().equals(src)) { loadInnerPage(); } } @Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } }; jsEngine.addPostponedAction(action); } }
/** * Loads the content of the contained frames. This is done after the page is completely loaded, to allow script * contained in the frames to reference elements from the page located after the closing </frame> tag. * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClient#setThrowExceptionOnFailingStatusCode(boolean)} is set to {@code true} */ void loadFrames() throws FailingHttpStatusCodeException { for (final FrameWindow w : getFrames()) { final BaseFrameElement frame = w.getFrameElement(); // test if the frame should really be loaded: // if a script has already changed its content, it should be skipped // use == and not equals(...) to identify initial content (versus URL set to "about:blank") if (frame.getEnclosedWindow() != null && WebClient.URL_ABOUT_BLANK == frame.getEnclosedPage().getUrl() && !frame.isContentLoaded()) { frame.loadInnerPage(); } } }
if (frame.getEnclosedPage() .getWebResponse() .getWebRequest() final URL url; try { url = ((HtmlPage) frame.getEnclosedPage()).getFullyQualifiedUrl(src); } catch (final MalformedURLException e) { String message = "Invalid src attribute of " + frame.getTagName() + ": url=[" return; if (isAlreadyLoadedByAncestor(url, ((HtmlPage) frame.getEnclosedPage()))) { String message = "Recursive src attribute of " + frame.getTagName() + ": url=[" + src + "]. Ignored.";
private void loadSrc() { loadSrcWhenAddedToPage_ = false; final String src = getSrcAttribute(); final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); // When src is set from a script, loading is postponed until script finishes // in fact this implementation is probably wrong: JavaScript URL should be // first evaluated and only loading, when any, should be postponed. if (!jsEngine.isScriptRunning() || src.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { loadInnerPageIfPossible(src); } else { final Page pageInFrame = getEnclosedPage(); final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { if (!src.isEmpty() && getSrcAttribute().equals(src)) { loadInnerPage(); } } @Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } }; jsEngine.addPostponedAction(action); } }
final Page enclosedPage = getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage;
final Page enclosedPage = getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage;
Iterable<DomNode> children = domNode.getChildren(); if (domNode instanceof BaseFrameElement) { final Page enclosedPage = ((BaseFrameElement) domNode).getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage;
Iterable<DomNode> children = domNode.getChildren(); if (domNode instanceof BaseFrameElement) { final Page enclosedPage = ((BaseFrameElement) domNode).getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage;