@Override public void deleteNode(E element) { getDelegate().deleteNode(element); }
/** * Deletes a tag from the document by index. * * @param index The index of the tag to delete. */ public void deleteTag(int index) { E nthTagNode = getNthTagNode(index); doc.deleteNode(nthTagNode); }
@Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { List<E> elementsToDelete = CollectionUtils.newArrayList(); for (E el : DocIterate.deepElements(doc, doc.getDocumentElement(), null)) { if (Blips.THREAD_INLINE_ANCHOR_TAGNAME.equals(doc.getTagName(el))) { elementsToDelete.add(el); } } // Reverse elements to delete so we always delete bottom up if one // contains another (which would be really weird anyway). Collections.reverse(elementsToDelete); for (E el : elementsToDelete) { doc.deleteNode(el); } } });
@Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { List<E> elementsToDelete = CollectionUtils.newArrayList(); for (E el : DocIterate.deepElements(doc, doc.getDocumentElement(), null)) { if (Blips.THREAD_INLINE_ANCHOR_TAGNAME.equals(doc.getTagName(el))) { String elId = doc.getAttribute(el, Blips.THREAD_INLINE_ANCHOR_ID_ATTR); if (threadIds.contains(elId)) { elementsToDelete.add(el); } } } // Reverse elements to delete so we always delete bottom up if one // contains another (which would be really weird anyway). Collections.reverse(elementsToDelete); for (E el : elementsToDelete) { doc.deleteNode(el); } } });
/** * Reads the document and sets up the initial state. If a node without text * is found, it is deleted and reported as a non-fatal error. */ public void processInitialState() { List<N> emptyNodes = new ArrayList<N>(); for (N node = doc.getFirstChild(doc.getDocumentElement()); node != null; node = doc.getNextSibling(node)) { T textNode = doc.asText(doc.getFirstChild(node)); if (textNode == null) { emptyNodes.add(node); } else { notifyAddTag(doc.getData(textNode)); tagElements.add(doc.asElement(node)); } } for (N emptyNode : emptyNodes) { doc.deleteNode(doc.asElement(emptyNode)); } }
/** * Deletes a tag from the document by name. * * @param tagName the name of the tag to delete. */ public void deleteTag(String tagName) { N node = doc.getFirstChild(doc.getDocumentElement()); while (node != null) { E element = doc.asElement(node); if (element != null) { T textNode = doc.asText(doc.getFirstChild(node)); if (textNode != null && doc.getData(textNode).equals(tagName)) { doc.deleteNode(element); return; } } node = doc.getNextSibling(node); } }
/** * Try to insert text into a new text node, by first inserting an element, and * then removing it after the new text is inserted. * * NOTE(user): We assume the document doesn't try to join the text nodes * after the dummy element is removed. * * @param <N> * @param at * @param text */ // TODO(user): Move somewhere common for TextLocatorTest static <N, E extends N, T extends N> void insertTextInNewTextNodeHelper( MutableDocument<N, E, T> doc, Point<N> at, String text) { E e = doc.createElement(at, "a", Collections.<String, String> emptyMap()); doc.insertText(Point.after(doc, e), text); doc.deleteNode(e); }
/** * Try to insert text into a new text node, by first inserting an element, and * then removing it after the new text is inserted. * * NOTE(user): We assume the document doesn't try to join the text nodes * after the dummy element is removed. * * @param <N> * @param at * @param text */ // TODO(user): Move somewhere common for TextLocatorTest static <N, E extends N, T extends N> void insertTextInNewTextNodeHelper( MutableDocument<N, E, T> doc, Point<N> at, String text) { E e = doc.createElement(at, "a", Collections.<String, String> emptyMap()); doc.insertText(Point.after(doc, e), text); doc.deleteNode(e); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });