protected Map<String, DomAttr> getAttributesFor(final HtmlLink link) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(link.getAttributesMap()); final String src = map.get("href").getValue(); try { final File file = createFile(src, ".css"); FileUtils.writeStringToFile(file, link.getWebResponse(true).getContentAsString()); map.get("href").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlLink link) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(link.getAttributesMap()); final String src = map.get("href").getValue(); try { final File file = createFile(src, ".css"); FileUtils.writeStringToFile(file, link.getWebResponse(true).getContentAsString()); map.get("href").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlLink link) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(link.getAttributesMap()); final String src = map.get("href").getValue(); try { final File file = createFile(src, ".css"); FileUtils.writeStringToFile(file, link.getWebResponse(true).getContentAsString()); map.get("href").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlScript script) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(script.getAttributesMap()); final String src = map.get("src").getValue(); try { final File file = createFile(src, ".js"); final String content = webClient_.<Page>getPage(src).getWebResponse().getContentAsString(); FileUtils.writeStringToFile(file, content); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlLink link) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(link, "href"); final DomAttr hrefAttr = map.get("href"); if (hrefAttr != null && StringUtils.isNotBlank(hrefAttr.getValue())) { final String protocol = link.getWebRequest().getUrl().getProtocol(); if ("http".equals(protocol) || "https".equals(protocol)) { final File file = createFile(hrefAttr.getValue(), ".css"); FileUtils.writeStringToFile(file, link.getWebResponse(true, null).getContentAsString(), ISO_8859_1); hrefAttr.setValue(outputDir_.getName() + FILE_SEPARATOR + file.getName()); } } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlScript script) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(script.getAttributesMap()); final String src = map.get("src").getValue(); try { final File file = createFile(src, ".js"); final String content = webClient_.<Page>getPage(src).getWebResponse().getContentAsString(); FileUtils.writeStringToFile(file, content); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlScript script) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(script.getAttributesMap()); final String src = map.get("src").getValue(); try { final File file = createFile(src, ".js"); final String content = webClient_.<Page>getPage(src).getWebResponse().getContentAsString(); FileUtils.writeStringToFile(file, content); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(image, "src"); final DomAttr srcAttr = map.get("src"); if (srcAttr != null && StringUtils.isNotBlank(srcAttr.getValue())) { final WebResponse response = image.getWebResponse(true); final File file = createFile(srcAttr.getValue(), "." + getSuffix(response)); try (InputStream inputStream = response.getContentAsStream()) { FileUtils.copyInputStreamToFile(inputStream, file); } final String valueOnFileSystem = outputDir_.getName() + FILE_SEPARATOR + file.getName(); srcAttr.setValue(valueOnFileSystem); // this is the clone attribute node, not the original one of the page } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlLink link) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(link, "href"); final DomAttr hrefAttr = map.get("href"); if (hrefAttr != null && StringUtils.isNotBlank(hrefAttr.getValue())) { final String protocol = link.getWebRequest().getUrl().getProtocol(); if ("http".equals(protocol) || "https".equals(protocol)) { final File file = createFile(hrefAttr.getValue(), ".css"); FileUtils.writeStringToFile(file, link.getWebResponse(true, null).getContentAsString(), ISO_8859_1); hrefAttr.setValue(outputDir_.getName() + FILE_SEPARATOR + file.getName()); } } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) throws IOException { final Map<String, DomAttr> map = createAttributesCopyWithClonedAttribute(image, DomElement.SRC_ATTRIBUTE); final DomAttr srcAttr = map.get(DomElement.SRC_ATTRIBUTE); if (srcAttr != null && StringUtils.isNotBlank(srcAttr.getValue())) { final WebResponse response = image.getWebResponse(true); final File file = createFile(srcAttr.getValue(), "." + getSuffix(response)); try (InputStream inputStream = response.getContentAsStream()) { FileUtils.copyInputStreamToFile(inputStream, file); } final String valueOnFileSystem = outputDir_.getName() + FILE_SEPARATOR + file.getName(); srcAttr.setValue(valueOnFileSystem); // this is the clone attribute node, not the original one of the page } 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; }
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; }