*
* @return the new Image in the TextDocument,the image name is set to "replace" + System.currentTimeMillis(), please update the name to others by yourself
*
*/
public Image replaceWithImage(URI imageUri) {
Image mImage =null;
if(search instanceof TextNavigation){
TextNavigation textSearch = (TextNavigation) search;
int leftLength = textSelection.getText().length();
int index = textSelection.getIndex();
mIsInserted = false;
OdfElement parentElement = textSelection.getContainerElement();
OdfFileDom ownerDom = (OdfFileDom) parentElement.getOwnerDocument();
int nodeLength = TextExtractor.getText(
this.textSelection.getContainerElement()).length();
if (this.textSelection.getText().length() != nodeLength)
this.textSelection.setSelectionReplaced(true);
try{
if (imageContainer == null) {
delete(index, leftLength, parentElement);
// PrepareContainer
imageContainer = ownerDom.newOdfElement(DrawFrameElement.class);
insertOdfElement(imageContainer, index, parentElement);
} else {
NodeList nodeImages = imageContainer.getElementsByTagName("draw:image");
Node nodeImage = nodeImages.item(0);
DrawImageElement im = (DrawImageElement) nodeImage;
Image oldimage = Image.getInstanceof(im);
oldimage.remove();
// PrepareContainer
imageContainer = ownerDom.newOdfElement(DrawFrameElement.class);
insertOdfElement(imageContainer, index, parentElement);
}
// Insert Image resource to package