* load the saved standalone document, and check the content of it
*/
@Test
public void testEmbedModifiedEmbeddedDocument() {
try {
OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE_EMBEDDED));
OdfDocument saveDoc = OdfTextDocument.newTextDocument();
OdfDocument embeddedDoc = doc.loadSubDocument("Object 1/");
//modify content of "Object 1"
OdfFileDom embedContentDom = embeddedDoc.getContentDom();
XPath xpath = embedContentDom.getXPath();
TextHElement header = (TextHElement) xpath.evaluate("//text:h[1]", embedContentDom, XPathConstants.NODE);
LOG.log(Level.INFO, "First para: {0}", header.getTextContent());
OdfTextSpan spanElem = new OdfTextSpan(embedContentDom);
spanElem.setTextContent(TEST_SPAN_TEXT);
header.appendChild(spanElem);
//insert image to "Object 1"
embeddedDoc.newImage(ResourceUtilities.getURI(TEST_PIC));
//embed "Object 1" to TestModifiedEmbeddedDoc.odt as the path /DocA
String embedPath = "DocA";
saveDoc.insertDocument(embeddedDoc, embedPath);
saveDoc.save(TEST_FILE_FOLDER + TEST_FILE_MODIFIED_EMBEDDED);
saveDoc.close();
//reload TestModifiedEmbeddedDoc.odt
saveDoc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE_MODIFIED_EMBEDDED));
embeddedDoc = saveDoc.loadSubDocument(embedPath);
//check the content of "DocA" and modify it again
embedContentDom = embeddedDoc.getContentDom();
header = (TextHElement) xpath.evaluate("//text:h[1]", embedContentDom, XPathConstants.NODE);
Assert.assertTrue(header.getTextContent().contains(TEST_SPAN_TEXT));
header.setTextContent("");
String packagePath = embeddedDoc.getDocumentPath() + SLASH + OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + SLASH + TEST_PIC;
OdfFileEntry imageEntry = embeddedDoc.getPackage().getFileEntry(packagePath);
Assert.assertNotNull(imageEntry);
embeddedDoc.newImage(ResourceUtilities.getURI(TEST_PIC_ANOTHER));
//save the "DocA" as the standalone document
embeddedDoc.save(TEST_FILE_FOLDER + TEST_FILE_MODIFIED_EMBEDDED_SAVE_STANDALONE);
//load the standalone document and check the content
OdfDocument standaloneDoc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE_MODIFIED_EMBEDDED_SAVE_STANDALONE));
embedContentDom = standaloneDoc.getContentDom();
header = (TextHElement) xpath.evaluate("//text:h[1]", embedContentDom, XPathConstants.NODE);
Assert.assertTrue(header.getTextContent().length() == 0);
imageEntry = standaloneDoc.getPackage().getFileEntry(OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + SLASH + TEST_PIC);
Assert.assertNotNull(imageEntry);
OdfFileEntry anotherImageEntry = standaloneDoc.getPackage().getFileEntry(OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + SLASH + TEST_PIC_ANOTHER);
Assert.assertNotNull(anotherImageEntry);
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
}