Case1:
I have an image1 in document and want to replace it with image2.
Case2:
Or I have a variable ${image1} and want to replace that with an actual image.
These are not text replacement but replacement of an image in place of a text or image.
Case1 - attempt:
I follow the example (OpenMainDocumentAndTraverse.java) and try to detect the Image in the document and modiify the URI. For an image it does not detect the binary part as org.docx4j.wml.Drawing object but as org.docx4j.wml.CTPicture. I am unable to find any way to update the referenece to a new image from the CTPicture object. If I debug the code I do not see any such class embedded.
Case 2 - attempt:
I follow the example (OpenMainDocumentAndTraverse.java) and inside walkList() method when I reach replacement part, I do below code snippet:
for (Object o : children) {
if (o instanceof JAXBElement) {
if (((JAXBElement) o).getDeclaredType().getName().equals("org.docx4j.wml.Text")) {
Text t = (Text) ((JAXBElement) o).getValue();
if (t.getValue().contains("$image1")) {
createImagePart(wordMLPackage);
}
}}}
}
createImagePart(WordprocessingMLPackage wordMLPackage) method is same as sample AddImage.java.
I get a Concurrent modification exception with List. I tried with an iterator instead of java1.5 for loop. And same exception.
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.next(Unknown Source)
at com.cisco.test.ModifySmallDocUC_STS.walkJAXBElements(ModifySmallDocUC_STS.java:137)
Any help on this would be appreciated.
Thanks.