@Override public int getLocation(N node) { return getDelegate().getLocation(node); }
@Override public int getLocation(Point<N> point) { return getDelegate().getLocation(point); }
@Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { for (E el : DocIterate.deepElements(doc, doc.getDocumentElement(), null)) { if (Blips.THREAD_INLINE_ANCHOR_TAGNAME.equals(doc.getTagName(el))) { String threadId = doc.getAttribute(el, Blips.THREAD_INLINE_ANCHOR_ID_ATTR); if ((threadId != null) && !anchors.containsKey(threadId)) { anchors.put(threadId, doc.getLocation(el)); } } } } });
private void checkInsertLineish(Point<Node> expectedPoint, Rounding rounding, Point<Node> location, boolean useParagraphs, int add) { int expectedLocation = doc.getLocation(expectedPoint) + add; Element el = LineContainers.insertLine(doc, rounding, location); assertTrue(LineContainers.isLineElement(doc, el)); assertEquals(expectedLocation, doc.getLocation(el)); }
private void checkInsertLineish(Point<Node> expectedPoint, Rounding rounding, Point<Node> location, boolean useParagraphs, int add) { int expectedLocation = doc.getLocation(expectedPoint) + add; Element el = LineContainers.insertLine(doc, rounding, location); assertTrue(LineContainers.isLineElement(doc, el)); assertEquals(expectedLocation, doc.getLocation(el)); }
private void checkAppendLineish(Point<Node> expectedPoint, XmlStringBuilder content, boolean useParagraphs) { int expectedLocation = doc.getLocation(expectedPoint); Element el = LineContainers.appendLine(doc, content); if (content == null) { content = XmlStringBuilder.createEmpty(); } assertTrue(LineContainers.isLineElement(doc, el)); XmlStringBuilderDoc<Node, Element, Text> siblingContent = XmlStringBuilder.createEmpty(doc); for (Node n = el.getNextSibling(); n != null; n = n.getNextSibling()) { siblingContent.appendNode(n); } assertEquals(content, siblingContent); assertEquals(expectedLocation, doc.getLocation(el)); }
private void checkAppendLineish(Point<Node> expectedPoint, XmlStringBuilder content, boolean useParagraphs) { int expectedLocation = doc.getLocation(expectedPoint); Element el = LineContainers.appendLine(doc, content); if (content == null) { content = XmlStringBuilder.createEmpty(); } assertTrue(LineContainers.isLineElement(doc, el)); XmlStringBuilderDoc<Node, Element, Text> siblingContent = XmlStringBuilder.createEmpty(doc); for (Node n = el.getNextSibling(); n != null; n = n.getNextSibling()) { siblingContent.appendNode(n); } assertEquals(content, siblingContent); assertEquals(expectedLocation, doc.getLocation(el)); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
private static <N, E extends N, T extends N> int locateAfterLineElementInner( MutableDocument<N, E, T> doc) { for (E el : DocIterate.deepElementsReverse(doc, doc.getDocumentElement(), null)) { if (LineContainers.isLineContainer(doc, el)) { Point<N> point = Point.inElement((N) el, null); return doc.getLocation(point); } } LineContainers.appendLine(doc, XmlStringBuilder.createEmpty()); return locateAfterLineElement(doc); }
private static <N, E extends N, T extends N> int locateAfterLineElementInner( MutableDocument<N, E, T> doc) { for (E el : DocIterate.deepElementsReverse(doc, doc.getDocumentElement(), null)) { if (LineContainers.isLineContainer(doc, el)) { Point<N> point = Point.inElement((N) el, null); return doc.getLocation(point); } } LineContainers.appendLine(doc, XmlStringBuilder.createEmpty()); return locateAfterLineElement(doc); }
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); } });
public void testFindCharacter() { checkFindCharacter("<x>abcd</x>", 1, "a", true, 1); checkFindCharacter("<x>abcd</x>", 1, "b", true, 2); checkFindCharacter("<x>abcd</x>", 4, "d", true, 4); checkFindCharacter("<x>abcd</x>", 3, "a", false, 1); checkFindCharacter("<x>abcd</x>", 3, "b", false, 2); checkFindCharacter("<x>abcd</x>", 5, "d", false, 4); checkFindCharacter("<x>ab<a/>cd</x>", 1, "a", true, 1); checkFindCharacter("<x>ab<a/>cd</x>", 1, "b", true, 2); checkFindCharacter("<x>ab<a/>cd</x>", 1, "c", true, 3); checkFindCharacter("<x>ab<a/>cd</x>", 1, "d", true, 3); // Test with split text node MutableDocument<Node, Element, Text> doc = DocProviders.MOJO.parse("<x>hello</x>"); DocHelperTest.insertTextInNewTextNodeHelper(doc, doc.locate(6), "world"); Tx<Node> helloStart = doc.locate(1).asTextPoint(); assertEquals(3, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "l", true))); assertEquals(6, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "w", true))); assertEquals(1, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "h", false))); }
public void testFindCharacter() { checkFindCharacter("<x>abcd</x>", 1, "a", true, 1); checkFindCharacter("<x>abcd</x>", 1, "b", true, 2); checkFindCharacter("<x>abcd</x>", 4, "d", true, 4); checkFindCharacter("<x>abcd</x>", 3, "a", false, 1); checkFindCharacter("<x>abcd</x>", 3, "b", false, 2); checkFindCharacter("<x>abcd</x>", 5, "d", false, 4); checkFindCharacter("<x>ab<a/>cd</x>", 1, "a", true, 1); checkFindCharacter("<x>ab<a/>cd</x>", 1, "b", true, 2); checkFindCharacter("<x>ab<a/>cd</x>", 1, "c", true, 3); checkFindCharacter("<x>ab<a/>cd</x>", 1, "d", true, 3); // Test with split text node MutableDocument<Node, Element, Text> doc = DocProviders.MOJO.parse("<x>hello</x>"); DocHelperTest.insertTextInNewTextNodeHelper(doc, doc.locate(6), "world"); Tx<Node> helloStart = doc.locate(1).asTextPoint(); assertEquals(3, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "l", true))); assertEquals(6, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "w", true))); assertEquals(1, doc.getLocation(TextLocator.findCharacter(doc, helloStart, "h", false))); }
public void testFindWordBoundary() { checkWordBoundary("<x>a b</x>", 1, true, 2); checkWordBoundary("<x>ab bc</x>", 1, true, 3); checkWordBoundary("<x>ab bc de</x>", 3, true, 6); checkWordBoundary("<x>ab bc de</x>", 4, true, 6); checkWordBoundary("<x>ab bc de</x>", 4, true, 8); checkWordBoundary("<x>hello</x>", 1, true, 6); checkWordBoundary("<x>hello<a/> hi</x>", 1, true, 6); checkWordBoundary("<x>hello</x>", 6, true, 6); checkWordBoundary("<x>hello</x>", 6, false, 1); checkWordBoundary("<x>a b</x>", 5, false, 4); checkWordBoundary("<x>a b</x>", 3, false, 1); checkWordBoundary("<x>a bc de</x>", 7, false, 4); checkWordBoundary("<x>a bc de</x>", 1, false, 1); // Test with split text node MutableDocument<Node, Element, Text> doc = DocProviders.MOJO.parse("<x>hello </x>"); DocHelperTest.insertTextInNewTextNodeHelper(doc, doc.locate(7), "world"); assertEquals(6, doc.getLocation(TextLocator.getWordBoundary(doc.locate(1).asTextPoint(), doc, true))); assertEquals(6, doc.getLocation(TextLocator.getWordBoundary(doc.locate(2).asTextPoint(), doc, true))); assertEquals(12, doc.getLocation(TextLocator.getWordBoundary(doc.locate(7).asTextPoint(), doc, true))); assertEquals(7, doc.getLocation(TextLocator.getWordBoundary(doc.locate(12).asTextPoint(), doc, false))); assertEquals(1, doc.getLocation(TextLocator.getWordBoundary(doc.locate(2).asTextPoint(), doc, false))); }
public void testFindById() { MutableDocument<Node, Element, Text> doc = getDoc( "<x id=\"x\">hello</x><y id=\"y\"><yy id=\"y\">blah</yy>yeah</y><z>final</z>"); Element root = doc.getDocumentElement(); Node x = root.getFirstChild(); Node z = root.getLastChild(); Node y = z.getPreviousSibling(); int firstLoc = doc.getLocation(x); assertSame(firstLoc, DocHelper.findLocationById(doc, "x")); assertSame(x, DocHelper.findElementById(doc, "x")); assertSame(firstLoc + 7, DocHelper.findLocationById(doc, "y")); assertSame(y, DocHelper.findElementById(doc, "y")); assertSame(-1, DocHelper.findLocationById(doc, "a")); assertSame(null, DocHelper.findElementById(doc, "a")); }
public void testFindById() { MutableDocument<Node, Element, Text> doc = getDoc( "<x id=\"x\">hello</x><y id=\"y\"><yy id=\"y\">blah</yy>yeah</y><z>final</z>"); Element root = doc.getDocumentElement(); Node x = root.getFirstChild(); Node z = root.getLastChild(); Node y = z.getPreviousSibling(); int firstLoc = doc.getLocation(x); assertSame(firstLoc, DocHelper.findLocationById(doc, "x")); assertSame(x, DocHelper.findElementById(doc, "x")); assertSame(firstLoc + 7, DocHelper.findLocationById(doc, "y")); assertSame(y, DocHelper.findElementById(doc, "y")); assertSame(-1, DocHelper.findLocationById(doc, "a")); assertSame(null, DocHelper.findElementById(doc, "a")); }