@Override public void text(final CharSequence text) { if (!enabled) { return; } String textValue = text.toString(); Node node = new Text(rootNode, textValue); parentNode.addChild(node); }
protected void fixText() { for (Text fosterText : fosterTexts) { // find parent table Element lastTable = findLastTable(fosterText); // move foster element above the table fosterText.detachFromParent(); Node tablesPreviousNode = lastTable.getPreviousSibling(); if (tablesPreviousNode.getNodeType() == Node.NodeType.TEXT) { // append to previous text node Text textNode = (Text) tablesPreviousNode; String text = textNode.getNodeValue(); textNode.setNodeValue(text + fosterText.getNodeValue()); } else { // insert text node before the table lastTable.getParentNode().insertBefore(fosterText, lastTable); } } }
@Test void testEncode() { LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); Document document = lagartoDOMBuilder.parse("<div foo=\"q w\">a<b</div>"); Element div = (Element) document.getFirstChild(); String foo = div.getAttribute("foo"); assertEquals("q\u00A0w", foo); div.setAttribute("foo", "q\u00A0w\u00A0e"); assertEquals("<div foo=\"q w e\">a<b</div>", document.getHtml()); Text text = (Text) document.getFirstChild().getFirstChild(); assertEquals("a<b", text.getNodeValue()); assertEquals("a<b", text.getTextContent()); assertEquals("a<b", text.getTextValue()); assertTrue(document.check()); }
/** * Removes last child node if contains just empty text. */ protected void removeLastChildNodeIfEmptyText(final Node parentNode, final boolean closedTag) { if (parentNode == null) { return; } Node lastChild = parentNode.getLastChild(); if (lastChild == null) { return; } if (lastChild.getNodeType() != Node.NodeType.TEXT) { return; } if (closedTag) { if (parentNode.getChildNodesCount() == 1) { return; } } Text text = (Text) lastChild; if (text.isBlank()) { lastChild.detachFromParent(); } }
assertEquals("text1", t1.getNodeValue()); assertNotNull(p3.getNextSibling()); Text t3 = (Text) t1.getNextSiblingElement().getNextSiblingElement().getNextSibling(); assertEquals("text3", t3.getNodeValue()); assertEquals(t1, t3.getPreviousSiblingElement().getPreviousSiblingElement().getPreviousSibling()); assertEquals(p1, p2.getPreviousSiblingElement()); assertEquals(t1, p2.getPreviousSibling());
/** * 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; }
assertEquals(Node.NodeType.TEXT, t.getNodeType()); assertEquals("Hello", t.getNodeValue()); assertEquals("Jodd", t.getNodeValue());
@Override public void text(final Text text) { String nodeValue = text.getTextValue(); try { appendable.append(nodeValue); } catch (IOException ioex) { throw new LagartoDOMException(ioex); } }
/** * Appends the text content to <code>Appendable</code>. */ @Override public void appendTextContent(Appendable appendable) { try { appendable.append(getTextContent()); } catch (IOException ioex) { throw new LagartoDOMException(ioex); } }
/** * Removes last child node if contains just empty text. */ protected void removeLastChildNodeIfEmptyText(Node parentNode, boolean closedTag) { if (parentNode == null) { return; } Node lastChild = parentNode.getLastChild(); if (lastChild == null) { return; } if (lastChild.getNodeType() != Node.NodeType.TEXT) { return; } if (closedTag) { if (parentNode.getChildNodesCount() == 1) { return; } } Text text = (Text) lastChild; if (text.isBlank()) { lastChild.detachFromParent(); } }
@Override public void text(final Text text) { String nodeValue = text.getTextValue(); try { appendable.append(nodeValue); } catch (IOException ioex) { throw new LagartoDOMException(ioex); } }
public void text(Text text) { String nodeValue = text.getTextContent(); try { appendable.append(nodeValue); } catch (IOException ioex) { throw new LagartoDOMException(ioex); } }
@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); } }
protected void fixText() { for (Text fosterText : fosterTexts) { // find parent table Element lastTable = findLastTable(fosterText); // move foster element above the table fosterText.detachFromParent(); Node tablesPreviousNode = lastTable.getPreviousSibling(); if (tablesPreviousNode.getNodeType() == Node.NodeType.TEXT) { // append to previous text node Text textNode = (Text) tablesPreviousNode; String text = textNode.getNodeValue(); textNode.setNodeValue(text + fosterText.getNodeValue()); } else { // insert text node before the table lastTable.getParentNode().insertBefore(fosterText, lastTable); } } }
/** * Removes last child node if contains just empty text. */ protected void removeLastChildNodeIfEmptyText(final Node parentNode, final boolean closedTag) { if (parentNode == null) { return; } Node lastChild = parentNode.getLastChild(); if (lastChild == null) { return; } if (lastChild.getNodeType() != Node.NodeType.TEXT) { return; } if (closedTag) { if (parentNode.getChildNodesCount() == 1) { return; } } Text text = (Text) lastChild; if (text.isBlank()) { lastChild.detachFromParent(); } }
/** * 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; }
protected void fixText() { for (Text fosterText : fosterTexts) { // find parent table Element lastTable = findLastTable(fosterText); // move foster element above the table fosterText.detachFromParent(); Node tablesPreviousNode = lastTable.getPreviousSibling(); if (tablesPreviousNode.getNodeType() == Node.NodeType.TEXT) { // append to previous text node Text textNode = (Text) tablesPreviousNode; String text = textNode.getNodeValue(); textNode.setNodeValue(text + fosterText.getNodeValue()); } else { // insert text node before the table lastTable.getParentNode().insertBefore(fosterText, lastTable); } } }