/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(String content) { if (content == null) { content = StringPool.EMPTY; } Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); } }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(final char[] content) { Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); }
/** * 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; }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(String content) { if (content == null) { content = StringPool.EMPTY; } Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); } }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(String content) { Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); } }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(final char[] content) { Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(char[] content) { Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); }
/** * 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, 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; }
/** * 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(); // clone to preserve for next iteration // as nodes will be detached from parent Document workingDoc = doc.clone(); node.addChild(workingDoc.getChildNodes()); } return this; }