@Test public void replacePlaceholderWithNodeHTML() { Map<String, Node> nodeIdMap = new HashMap<>(); StringBuilder html = new StringBuilder("<div>"); for (int i = 0; i < 5; i++) { Attributes attrs = new Attributes(); String id = "id_" + i; attrs.put("id", id); Element ele = new Element(Tag.valueOf("span"), "", attrs); ele.append("The original node"); nodeIdMap.put(id, ele); Element placeholder = ArticleUtil.generatePlaceholderNode(id); html.append(placeholder.outerHtml()); } html.append("</div>"); String results = ArticleUtil.replacePlaceholderWithNodeHTML(nodeIdMap, html.toString()); for (Node originalNode: nodeIdMap.values()) { assertThat(results).contains(originalNode.outerHtml()); } }
static String replacePlaceholderWithNodeHTML( Map<String, Node> nodeIdMap, String html) { return replacePlaceholderWithNode(nodeIdMap, html, ArticleUtil::wrapHTML); }
ArticleUtil { static String replacePlaceholderWithNodeHTML( Map<String, Node> nodeIdMap, String html) { return replacePlaceholderWithNode(nodeIdMap, html, ArticleUtil::wrapHTML); } }
ArticleUtil { static String replacePlaceholderWithNodeHTML( Map<String, Node> nodeIdMap, String html) { return replacePlaceholderWithNode(nodeIdMap, html, ArticleUtil::wrapHTML); } @SuppressWarnings("unused") private  ArticleUtil(); }
ArticleUtil { static String replacePlaceholderWithNodeHTML( Map<String, Node> nodeIdMap, String html) { return replacePlaceholderWithNode(nodeIdMap, html, ArticleUtil::wrapHTML); } @SuppressWarnings("unused") private  ArticleUtil(); static TranslatableNodeList replaceNonTranslatableNodeHTML(int prefix,
            String html); static TranslatableNodeList replaceNonTranslatableNodeXML(int prefix,
            String xml); static String generatePlaceholderId(int prefix, int index); static Element generatePlaceholderNode(@NotNull String id); static Document wrapHTML(String html); static Document wrapXML(String html); static List<Node> unwrapAsNodes(@NotNull Element element); static List<Node> unwrapAsElements(@NotNull Element element); static @Nullable Node asElement(String html, Function<String, Element> toElement); static String replacePlaceholderWithNode(
            Map<String, Node> nodeIdMap, String xml, Function<String, Element> toElement); }
ArticleUtil { static String replacePlaceholderWithNodeHTML( Map<String, Node> nodeIdMap, String html) { return replacePlaceholderWithNode(nodeIdMap, html, ArticleUtil::wrapHTML); } @SuppressWarnings("unused") private  ArticleUtil(); static TranslatableNodeList replaceNonTranslatableNodeHTML(int prefix,
            String html); static TranslatableNodeList replaceNonTranslatableNodeXML(int prefix,
            String xml); static String generatePlaceholderId(int prefix, int index); static Element generatePlaceholderNode(@NotNull String id); static Document wrapHTML(String html); static Document wrapXML(String html); static List<Node> unwrapAsNodes(@NotNull Element element); static List<Node> unwrapAsElements(@NotNull Element element); static @Nullable Node asElement(String html, Function<String, Element> toElement); static String replacePlaceholderWithNode(
            Map<String, Node> nodeIdMap, String xml, Function<String, Element> toElement);  }