@Override public E asElement(N node) { return doc.asElement(node); }
private Builder emptyElement(E element, Builder builder) { for (N node = doc.getFirstChild(element); node != null; node = doc.getNextSibling(node)) { E elChild = doc.asElement(node); if (elChild != null) { deleteElement(elChild, builder); } else { builder.deleteCharacters(doc.getData(doc.asText(node)).length()); } } return builder; }
@Override public E createElement(Point<N> point, String tagName, Map<String, String> attributes) { // TODO(danilatos): Validate point is in document. indexed doc should throw an exception // when calling getLocation anyway. Preconditions.checkNotNull(tagName, "createElement: tagName must not be null"); Point.checkPoint(this, point, "MutableDocumentImpl.createElement"); try { begin(); int location = doc.getLocation(point); consume(createElement(tagName, new AttributesImpl(attributes), at(location))); Point<N> result = doc.locate(location); return doc.asElement(result.isInTextNode() ? doc.getNextSibling(result.getContainer()) : result.getNodeAfter()); } finally { end(); } }
/***/ public void testGetNextSiblingElementBackwards() { ReadableWDocument<Node, Element, Text> doc = DocProviders.POJO.parse( "<div>abc<p>def<q>hij</q></p><p>def<q>hij</q></p></div>"); Element previous = null; Node node = doc.getFirstChild(doc.getDocumentElement()); while (node != null) { Element p = doc.asElement(node); if (p != null) { if (previous == null) { // p is the very first element among nodes of doc. assertNull(DocHelper.getPreviousSiblingElement(doc, p)); } else { // p follows a previously seen previous element. assertSame(previous, DocHelper.getPreviousSiblingElement(doc, p)); } previous = p; } node = doc.getNextSibling(node); } // TODO(user): The following fails. Uncomment and fix if it should work. // assertNull(DocHelper.getPreviousSiblingElement(doc, null)); }
/***/ public void testGetNextSiblingElementBackwards() { ReadableWDocument<Node, Element, Text> doc = DocProviders.POJO.parse( "<div>abc<p>def<q>hij</q></p><p>def<q>hij</q></p></div>"); Element previous = null; Node node = doc.getFirstChild(doc.getDocumentElement()); while (node != null) { Element p = doc.asElement(node); if (p != null) { if (previous == null) { // p is the very first element among nodes of doc. assertNull(DocHelper.getPreviousSiblingElement(doc, p)); } else { // p follows a previously seen previous element. assertSame(previous, DocHelper.getPreviousSiblingElement(doc, p)); } previous = p; } node = doc.getNextSibling(node); } // TODO(user): The following fails. Uncomment and fix if it should work. // assertNull(DocHelper.getPreviousSiblingElement(doc, null)); }
builder.deleteCharacters(doc.getData(text).length()); } else { deleteElement(doc.asElement(node), builder);