private String getStyleAsString()

in src/main/java/com/epam/digital/data/platform/report/service/ExcerptService.java [96:123]


  private String getStyleAsString(Document document, File dir) {
    Elements links = document.select("link[href]");

    var styleString = new StringBuilder();
    for (Element link : links) {
      String styleNameHref = link.attr("href");

      if (StringUtils.isNotBlank(styleNameHref)) {
        var styleFile = Path.of(dir.getPath(), "css", FilenameUtils.getName(styleNameHref))
            .toFile();

        if (styleFile.exists()) {
          try {
            styleString.append(FileUtils.readFileToString(styleFile, StandardCharsets.UTF_8))
                .append("\n");
            link.remove();
          } catch (Exception e) {
            throw new ExcerptBuildingException("Failed to embed styles into template", e);
          }
        } else {
          log.error("Failed to embed styles into template, file '{}' doesn't exist.",
              styleNameHref);
        }
      }
    }

    return styleString.toString();
  }