In our project we have a template (*.docx) file with text and placeholders. I use the unmarshallFromTemplate function te replace them (Actually we made a local unmarshalFromTemplate that uses the docx4j implementation).
I can replace placeholders in the maindocument, the footers but not the footnotes? Is there a reason for that.
I execute the following code:
Using java Syntax Highlighting
if ("/word/footnotes.xml".equals(part.getPartName().getName())) {
FootnotesPart footnotesPart = (FootnotesPart) part;
CTFootnotes ctFootnotes = footnotesPart.getJaxbElement();
String footnotesXML = XmlUtils.marshaltoString(ctFootnotes, true);
// valorize template
Object footnotesObj = null;
try {
footnotesObj = LocalXmlUtils.unmarshallFromTemplate(footnotesXML, mappings);
} catch (JAXBException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
if (footnotesObj != null) {
try{
footnotesPart.setJaxbElement((CTFootnotes) footnotesObj);
}catch(Exception e){
e.printStackTrace();
}
}
}
FootnotesPart footnotesPart = (FootnotesPart) part;
CTFootnotes ctFootnotes = footnotesPart.getJaxbElement();
String footnotesXML = XmlUtils.marshaltoString(ctFootnotes, true);
// valorize template
Object footnotesObj = null;
try {
footnotesObj = LocalXmlUtils.unmarshallFromTemplate(footnotesXML, mappings);
} catch (JAXBException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
if (footnotesObj != null) {
try{
footnotesPart.setJaxbElement((CTFootnotes) footnotesObj);
}catch(Exception e){
e.printStackTrace();
}
}
}
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
I get following error: javax.xml.bind.JAXBElement cannot be cast to org.docx4j.wml.CTFootnotes
If I use the code above for the maindocument or footer it works.
For example:
Using java Syntax Highlighting
if ("/word/footer1.xml".equals(part.getPartName().getName())) {
FooterPart footerPart = (FooterPart) part;
Ftr ftr = footerPart.getJaxbElement();
String footerXML = XmlUtils.marshaltoString(ftr, true);
// valorize template
Object footerObj = null;
try {
footerObj = LocalXmlUtils.unmarshallFromTemplate(footerXML, mappings);
} catch (JAXBException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
if (footerObj != null) {
footerPart.setJaxbElement((Ftr) footerObj);
}
}
FooterPart footerPart = (FooterPart) part;
Ftr ftr = footerPart.getJaxbElement();
String footerXML = XmlUtils.marshaltoString(ftr, true);
// valorize template
Object footerObj = null;
try {
footerObj = LocalXmlUtils.unmarshallFromTemplate(footerXML, mappings);
} catch (JAXBException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
if (footerObj != null) {
footerPart.setJaxbElement((Ftr) footerObj);
}
}
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
Can somebody give me a hint? Is it possible to edit placeholders in footnotes?
Thx in advance!