TextSelection extends Selection { public OdfElement getContainerElement() { if (mParagraph != null) { return mParagraph; } else { return mHeading; } } TextSelection(Navigation search, String text, OdfElement containerElement,
			int index); TextNavigation getTextNavigation(); static TextSelection newTextSelection(Navigation search,
			String text, OdfElement containerElement, int index); @Override OdfElement getElement(); OdfElement getContainerElement(); @Override int getIndex(); String getText(); @Override void cut(); void applyStyle(OdfStyleBase style); void replaceWith(String newText); Table replaceWith(Table newTable); Image replaceWith(Image newImage); Image replaceWith(URI imageUri); Field replaceWith(Field orgField); Paragraph replaceWith(Paragraph newParagraph); void replaceWith(TextDocument newTextDocument); TextSpanElement createSpanElement(); @Override void pasteAtFrontOf(Selection positionItem); @Override void pasteAtEndOf(Selection positionItem); void setSelectionReplaced(boolean b); boolean isSelectionReplaced(); void addHref(URL url); void addComment(String content, String creator); @Override String toString();  }
@Test public void testTextSelectionContainerElement() { search = new TextNavigation("TextSelectionContainer", doc); if (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); OdfElement container = item.getContainerElement(); Node childNode = container.getFirstChild(); while (childNode != null) { String containerText = childNode.getTextContent(); Assert.assertFalse(container.getTextContent().equals(containerText)); childNode = childNode.getNextSibling(); } } else { Assert.fail("Navigation search nothing."); } search = new TextNavigation("Task", doc); if (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); OdfElement container = item.getContainerElement(); Node childNode = container.getFirstChild(); while (childNode != null) { String containerText = childNode.getTextContent(); Assert.assertFalse(container.getTextContent().equals(containerText)); childNode = childNode.getNextSibling(); } } else { Assert.fail("Navigation search nothing."); } try { doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_DELETE_PATTERN)); } catch (Exception e) { Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testGetContainerElement() throws Exception { search = new TextNavigation("TextSelectionContainer", doc); if (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); URL url = new URL("http: item.addHref(url); OdfElement parentElement = item.getContainerElement(); Node node = parentElement.getFirstChild().getFirstChild().getNextSibling(); TextAElement textAele = (TextAElement)node; System.out.println(textAele.getXlinkTypeAttribute()); System.out.println(textAele.getXlinkHrefAttribute()); Assert.assertEquals("simple", textAele.getXlinkTypeAttribute()); Assert.assertEquals("http: } else { Assert.fail("Navigation search nothing."); } }