/** * Insert content, specified by the parameter, to the beginning of each * element in the set of matched elements. */ public Jerry prepend(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertChild(workingDoc.getChildNodes(), 0); } return this; }
/** * Inserts content, specified by the parameter, before each * element in the set of matched elements. */ public Jerry before(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertBefore(workingDoc.getChildNodes(), node); } return this; }
/** * Inserts content, specified by the parameter, to the end of each * element in the set of matched elements. */ public Jerry append(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Inserts content, specified by the parameter, after each * element in the set of matched elements. */ public Jerry after(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertAfter(workingDoc.getChildNodes(), node); } return this; }
/** * Sets the HTML contents of each element in the set of matched elements. */ public Jerry html(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { node.removeAllChilds(); // clone to preserve for next iteration // as nodes will be detached from parent Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Replace each element in the set of matched elements with the provided * new content and return the set of elements that was removed. */ public Jerry replaceWith(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Node parent = node.getParentNode(); // if a node already is the root element, don't unwrap if (parent == null) { continue; } // replace, if possible Document workingDoc = doc.clone(); int index = node.getSiblingIndex(); parent.insertChild(workingDoc.getFirstChild(), index); node.detachFromParent(); } return this; }
/** * Wraps an HTML structure around each element in the set of matched elements. * Returns the original set of elements for chaining purposes. */ public Jerry wrap(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); Node inmostNode = workingDoc; while (inmostNode.hasChildNodes()) { inmostNode = inmostNode.getFirstChild(); } // replace Node parent = node.getParentNode(); int index = node.getSiblingIndex(); inmostNode.addChild(node); parent.insertChild(workingDoc.getFirstChild(), index); } return this; }
@Test void testClone() { String page = "<html><body><p id=\"w173\">Hello<br>Jodd</p></body></html>"; Document root = new LagartoDOMBuilder().parse(page); String generated = root.getHtml(); assertEquals(page, generated); Document rootClone = root.clone(); String generated2 = rootClone.getHtml(); assertEquals(page, generated2); assertNotSame(root, rootClone); assertNotSame(root.getChild(0), rootClone.getChild(0)); assertTrue(root.check()); }
/** * Inserts content, specified by the parameter, before each * element in the set of matched elements. */ public Jerry before(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertBefore(workingDoc, node); } return this; }
/** * Inserts content, specified by the parameter, to the end of each * element in the set of matched elements. */ public Jerry append(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { Document workingDoc = doc.clone(); node.addChild(workingDoc); } return this; }
/** * Inserts content, specified by the parameter, to the end of each * element in the set of matched elements. */ public Jerry append(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Inserts content, specified by the parameter, before each * element in the set of matched elements. */ public Jerry before(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertBefore(workingDoc.getChildNodes(), node); } return this; }
/** * Inserts content, specified by the parameter, before each * element in the set of matched elements. */ public Jerry before(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertBefore(workingDoc.getChildNodes(), node); } return this; }
/** * Inserts content, specified by the parameter, after each * element in the set of matched elements. */ public Jerry after(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertAfter(workingDoc.getChildNodes(), node); } return this; }
/** * Sets the HTML contents of each element in the set of matched elements. */ public Jerry html(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { node.removeAllChilds(); Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Inserts content, specified by the parameter, to the end of each * element in the set of matched elements. */ public Jerry append(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Insert content, specified by the parameter, to the beginning of each * element in the set of matched elements. */ public Jerry prepend(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { Document workingDoc = doc.clone(); node.insertChild(workingDoc.getChildNodes(), 0); } return this; }
/** * Sets the HTML contents of each element in the set of matched elements. */ public Jerry html(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { node.removeAllChilds(); // clone to preserve for next iteration // as nodes will be detached from parent Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Sets the HTML contents of each element in the set of matched elements. */ public Jerry html(String html) { if (html == null) { html = StringPool.EMPTY; } final Document doc = builder.parse(html); if (nodes.length == 0) { return this; } for (Node node : nodes) { node.removeAllChilds(); // clone to preserve for next iteration // as nodes will be detached from parent Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }
/** * Wraps an HTML structure around each element in the set of matched elements. * Returns the original set of elements for chaining purposes. */ public Jerry wrap(String html) { final Document doc = builder.parse(html); for (Node node : nodes) { Document workingDoc = doc.clone(); Node inmostNode = workingDoc; while (inmostNode.hasChildNodes()) { inmostNode = inmostNode.getFirstChild(); } // replace Node parent = node.getParentNode(); int index = node.getSiblingIndex(); inmostNode.addChild(node); parent.insertChild(workingDoc.getFirstChild(), index); } return this; }