* based on the given URI.
* */
public String newImage(URI imageUri) {
try {
OdfContentDom contentDom = this.getContentDom();
OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
XPath xpath = contentDom.getXPath();
if (this instanceof SpreadsheetDocument) {
TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]",
contentDom, XPathConstants.NODE);
lastCell.appendChild(drawFrame);
drawFrame.removeAttribute("text:anchor-type");
} else if (this instanceof TextDocument) {
TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom,
XPathConstants.NODE);
if (lastPara == null) {
lastPara = ((TextDocument) this).newParagraph();
}
lastPara.appendChild(drawFrame);
drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
} else if (this instanceof PresentationDocument) {
DrawPageElement lastPage = (DrawPageElement) xpath.evaluate("//draw:page[last()]", contentDom,
XPathConstants.NODE);
lastPage.appendChild(drawFrame);
}
OdfDrawImage image = (OdfDrawImage) drawFrame.newDrawImageElement();
String imagePath = image.newImage(imageUri);
return imagePath;
} catch (Exception ex) {
Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
}