image2.setHyperlink(new URI("http://odftoolkit.org"));
search = null;
// 6 Simple, at the middle of original Paragraph, split original
// Paragraph, insert before the second Paragraph.
doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
search = new TextNavigation("SIMPLE", doc);
int i = 0;
TextSelection item = null;
while (search.hasNext()) {
item = (TextSelection) search.nextSelection();
Paragraph paragraph = sourcedoc.getParagraphByIndex(0, true);
TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
Node nodeImage = nodeImages.item(0);
DrawImageElement im = (DrawImageElement) nodeImage;
Image ima = Image.getInstanceof(im);
image = item.replaceWith(ima);
Assert.assertNotNull(image);
if (image.getName().startsWith("replace")) {
Assert.assertTrue(true);
} else {
Assert.fail();
}
String name = "simple" + (i++);
image.setName(name);
Assert.assertEquals(name, image.getName());
}
try {
doc.save(ResourceUtilities.newTestOutputFile("TextSelectionReplacewithImageResult.odt"));
} catch (Exception e) {
Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
}
doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
// 6 Simple, at the middle of original Paragraph, split original
// Paragraph, insert before the second Paragraph.
search = new TextNavigation("SIMPLE", doc);
i = 0;
try {
while (search.hasNext()) {
item = (TextSelection) search.nextSelection();
URI imageuri = ResourceUtilities.getURI("image_list_item.png");
image = item.replaceWith(imageuri);
Assert.assertNotNull(image);
if (image.getName().startsWith("replace")) {
Assert.assertTrue(true);
} else {
Assert.fail();
}
String name = "simple" + (i++);
image.setName(name);
Assert.assertEquals(name, image.getName());
}
doc.save(ResourceUtilities.newTestOutputFile("TextSelectionReplacewithImageURIResult.odt"));
} catch (Exception e) {
Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
}
doc = (TextDocument) Document.loadDocument(ResourceUtilities
.getAbsolutePath(TEST_FILE));
search = new TextNavigation("<<target>>", doc);
i = 0;
try {
while (search.hasNext()) {
i++;
item = (TextSelection) search.nextSelection();
URI imageuri = ResourceUtilities.getURI("image_list_item.png");
image = item.replaceWith(imageuri);
Assert.assertNotNull(image);
if (image.getName().startsWith("replace")) {
Assert.assertTrue(true);
} else {
Assert.fail();
}
}
Assert.assertEquals(11, i);
doc.save(ResourceUtilities
.newTestOutputFile("TextSelectionReplacewithImageResult-URI-BasicCases.odt"));
verifyReplaceWithImageByBasicCases("TextSelectionReplacewithImageResult-URI-BasicCases.odt");
} catch (Exception e) {
Logger.getLogger(TextSelectionTest.class.getName()).log(
Level.SEVERE, e.getMessage(), e);
Assert.fail("Failed with " + e.getClass().getName() + ": '"
+ e.getMessage() + "'");
}
doc = (TextDocument) Document.loadDocument(ResourceUtilities
.getAbsolutePath(TEST_FILE));
search = new TextNavigation("<<target>>", doc);
i = 0;
try {
while (search.hasNext()) {
i++;
item = (TextSelection) search.nextSelection();