OdfDocument doc1 = embDocs.get(eDocPath);
Assert.assertNotNull(doc1);
OdfContentDom contentDom = doc1.getContentDom();
XPath xpath = contentDom.getXPath();
TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
OdfTextSpan spanElem = new OdfTextSpan(contentDom);
spanElem.setTextContent(TEST_SPAN_TEXT);
para.appendChild(spanElem);
//save the embed document to a stand alone document
doc1.save(TEST_FILE_SAVE_EMBEDDED_OUT);
// Load test
OdfDocument loadedDoc = OdfDocument.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT);
OdfContentDom contentDom2 = loadedDoc.getContentDom();
OdfTextSpan span = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom2, XPathConstants.NODE);
Assert.assertEquals(span.getTextContent(), TEST_SPAN_TEXT);
Map<String, OdfDocument> embDocs3 = docWithEmbeddedObjects.loadSubDocuments(OdfDocument.OdfMediaType.TEXT);
for(String eDocPath3 : embDocs3.keySet()){
// Writer Doc
OdfDocument doc3 = embDocs3.get(eDocPath3);
Assert.assertNotNull(doc3);
OdfContentDom contentDom3 = doc3.getContentDom();
TextPElement para2 = (TextPElement) xpath.evaluate("//text:p[1]", contentDom3, XPathConstants.NODE);
addImageToDocument(contentDom3, para2);
TextPElement para3 = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom3, XPathConstants.NODE);
addFrameForEmbeddedDoc(contentDom3, para3, "NewEmbedded");
doc3.insertDocument(OdfTextDocument.newTextDocument(), "/NewEmbedded/");
OdfDocument doc4 = doc3.loadSubDocument("NewEmbedded");
Assert.assertNotNull(doc4);
OdfContentDom contentDom4 = doc4.getContentDom();
para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom4, XPathConstants.NODE);
spanElem = new OdfTextSpan(contentDom4);
spanElem.setTextContent(TEST_SPAN_TEXT);
para.appendChild(spanElem);
doc3.save(TEST_FILE_SAVE_EMBEDDED_OUT2);
OdfDocument testLoad = OdfDocument.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT2);
NodeList linkNodes = (NodeList) xpath.evaluate("//*[@xlink:href]", testLoad.getContentDom(), XPathConstants.NODE);
for (int i = 0; i < linkNodes.getLength(); i++) {
OdfElement object = (OdfElement) linkNodes.item(i);
String refObjPath = object.getAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href");
Assert.assertTrue(refObjPath.equals("Pictures/" + TEST_PIC) || refObjPath.equals("./NewEmbedded"));
}
Assert.assertNotNull(testLoad.getPackage().getFileEntry("Pictures/" + TEST_PIC));
OdfDocument embedDocOftestLoad = testLoad.loadSubDocument("NewEmbedded/");
contentDom4 = embedDocOftestLoad.getContentDom();
OdfTextSpan span4 = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom4, XPathConstants.NODE);
Assert.assertNotNull(span4);
Assert.assertEquals(span4.getTextContent(), TEST_SPAN_TEXT);
}
}
} catch (Exception ex) {
Logger.getLogger(DocumentCreationTest.class.getName()).log(Level.SEVERE, null, ex);
Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");