use of jodd.lagarto.dom.Document in project jodd by oblac.
the class Jerry method wrap.
// ---------------------------------------------------------------- wrap
/**
* 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;
}
use of jodd.lagarto.dom.Document in project jodd by oblac.
the class ParsingProblemsTest method testIssue23_1.
@Test
public void testIssue23_1() throws IOException {
File file = new File(testDataRoot, "index-4-v1.html");
LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
lagartoDOMBuilder.getConfig().setCalculatePosition(true);
lagartoDOMBuilder.getConfig().setCollectErrors(true);
Document doc = lagartoDOMBuilder.parse(FileUtil.readString(file));
assertTrue(doc.check());
assertEquals(1, doc.getErrors().size());
}
use of jodd.lagarto.dom.Document in project jodd by oblac.
the class Jerry method prepend.
/**
* 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;
}