@Test
public void testRemove() {
try {
// new image in text document
TextDocument doc = TextDocument.newTextDocument();
Paragraph para = doc.addParagraph("imagePara");
Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
image.setName("this test image");
image.setHyperlink(new URI("http://odftoolkit.org"));
//image.remove();
//save
doc.save(ResourceUtilities.newTestOutputFile("imageFretest.odt"));
TextDocument doc1 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("imageFretest.odt"));
Iterator parasIter = doc1.getParagraphIterator();
while(parasIter.hasNext()){
Paragraph parac = (Paragraph)parasIter.next();
String text = parac.getTextContent();
if("imagePara".equals(text)){
TextParagraphElementBase textParaEleBase = parac.getOdfElement();
NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
Node nodeImage = nodeImages.item(0);
OdfDrawImage im = (OdfDrawImage)nodeImage;
Image ima = Image.getInstanceof(im);
ima.getName();
boolean flag = ima.remove();
if(!flag)
Assert.fail("remove() method was executed failed.");
}
}
//save
doc1.save(ResourceUtilities.newTestOutputFile("imageEndtest.odt"));
//validate
TextDocument doc2 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("imageEndtest.odt"));
Iterator parasIter2 = doc2.getParagraphIterator();
while(parasIter2.hasNext()){
Paragraph parac = (Paragraph)parasIter2.next();
String text = parac.getTextContent();
if("imagePara".equals(text)){
TextParagraphElementBase textParaEleBase = parac.getOdfElement();
NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
Node nodeImage = nodeImages.item(0);
if(nodeImage == null)
Assert.assertTrue(true);
else