@Override public void text(final CharSequence text) { if (!enabled) { return; } String textValue = text.toString(); Node node = new Text(rootNode, textValue); parentNode.addChild(node); }
@Override public void cdata(final CharSequence cdata) { if (!enabled) { return; } CData cdataNode = new CData(rootNode, cdata.toString()); parentNode.addChild(cdataNode); }
@Override public void xml(final CharSequence version, final CharSequence encoding, final CharSequence standalone) { if (!enabled) { return; } XmlDeclaration xmlDeclaration = new XmlDeclaration(rootNode, version, encoding, standalone); parentNode.addChild(xmlDeclaration); }
@Override public void script(final Tag tag, final CharSequence body) { if (!enabled) { return; } Element node = createElementNode(tag); parentNode.addChild(node); if (body.length() != 0) { Node text = new Text(rootNode, body.toString()); node.addChild(text); } }
/** * Inserts node after provided node. */ public void insertAfter(final Node newChild, final Node refChild) { int siblingIndex = refChild.getSiblingIndex() + 1; if (siblingIndex == refChild.parentNode.getChildNodesCount()) { refChild.parentNode.addChild(newChild); } else { refChild.parentNode.insertChild(newChild, siblingIndex); } }
/** * Inserts several child nodes after referent node. */ public void insertAfter(final Node[] newChilds, final Node refChild) { if (newChilds.length == 0) { return; } int siblingIndex = refChild.getSiblingIndex() + 1; if (siblingIndex == refChild.parentNode.getChildNodesCount()) { refChild.parentNode.addChild(newChilds); } else { refChild.parentNode.insertChild(newChilds, siblingIndex); } }
@Override public void comment(final CharSequence comment) { if (!enabled) { return; } if (domBuilder.config.isIgnoreWhitespacesBetweenTags()) { removeLastChildNodeIfEmptyText(parentNode, false); } if (domBuilder.config.isIgnoreComments()) { return; } Node node = new Comment(rootNode, comment.toString()); parentNode.addChild(node); }
/** * 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; }
/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { if (nodes.length == 0) { return this; } if (text == null) { text = StringPool.EMPTY; } for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(node.getOwnerDocument(), text); node.addChild(textNode); } 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; }
@Override public void doctype(final Doctype doctype) { if (!enabled) { return; } DocumentType documentType = new DocumentType(rootNode, Util.toString(doctype.getName()), Util.toString(doctype.getPublicIdentifier()), Util.toString(doctype.getSystemIdentifier()) ); parentNode.addChild(documentType); }
/** * 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; }
parentParentNode.getParentNode().addChild(parentNode);
public void text(CharSequence text) { if (!enabled) { return; } String textValue = text.toString(); Node node = new Text(rootNode, textValue); parentNode.addChild(node); }
public void cdata(CharSequence cdata) { if (!enabled) { return; } CData cdataNode = new CData(rootNode, cdata.toString()); parentNode.addChild(cdataNode); }
/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(); textNode.setTextContent(text); node.addChild(textNode); } return this; }
/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(node.getOwnerDocument(), text); node.addChild(textNode); } 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; }