/** * <p>Downloads the image contained by this image element.</p> * <p><span style="color:red">POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK</span></p> * <p>If the image has not already been downloaded, this method triggers a download and caches the image.</p> * * @throws IOException if an error occurs while downloading the image */ private void downloadImageIfNeeded() throws IOException { if (!downloaded_) { // HTMLIMAGE_BLANK_SRC_AS_EMPTY final String src = getSrcAttribute(); if (!"".equals(src) && !(hasFeature(HTMLIMAGE_BLANK_SRC_AS_EMPTY) && StringUtils.isBlank(src))) { final HtmlPage page = (HtmlPage) getPage(); final WebClient webclient = page.getWebClient(); final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); request.setCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); } if (imageData_ != null) { imageData_.close(); imageData_ = null; } downloaded_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) || (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image")); } }
/** * <p>Downloads the image contained by this image element.</p> * <p><span style="color:red">POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK</span></p> * <p>If the image has not already been downloaded, this method triggers a download and caches the image.</p> * * @throws IOException if an error occurs while downloading the image */ private void downloadImageIfNeeded() throws IOException { if (!downloaded_) { // HTMLIMAGE_BLANK_SRC_AS_EMPTY final String src = getSrcAttribute(); if (!"".equals(src) && !(hasFeature(HTMLIMAGE_BLANK_SRC_AS_EMPTY) && StringUtils.isBlank(src))) { final HtmlPage page = (HtmlPage) getPage(); final WebClient webclient = page.getWebClient(); final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); request.setCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); } if (imageData_ != null) { imageData_.close(); imageData_ = null; } downloaded_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) || (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image")); } }