by siva kumar » Tue Nov 27, 2012 9:24 pm
Hi Jason,
I'm getting below error while replacing variables in footer at the last line of code "footerPart.setJaxbElement((Ftr)obj);" . pls check
"java.lang.NullPointerException"
#CODE:
-----------------------
List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections();
String xml = null;
for (SectionWrapper sw : sectionWrappers) {
HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
if (hfp != null) {
FooterPart footerPart = hfp.getDefaultFooter();
if (footerPart != null) {
//xml --> string
xml = XmlUtils.marshaltoString(footerPart.getJaxbElement(), true);
System.err.println(xml);
}
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("testing footer", "${test}");
Object obj = null;
try {
obj = XmlUtils.unmarshallFromTemplate(xml, mappings);
Ftr ftr = (Ftr)obj;
System.err.println(ftr.getContent().toString());
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Inject result into docx
footerPart.setJaxbElement((Ftr)obj);
-----------------------