I'm trying to replace some code using the code below (inside a grails application). The replacement *seems* to be ok, but I get this error saving the file: "Couldn't get resource: docx4j.properties".
The docx file is attached (it contains brazilian words with accents)
Environment:
docx4j 2.7.1
JRE 1.6.0_29
Grails 2.0.0
Mac OS X (Lion)
Could some one please throw a light on this?
Thanks,
Andre
Code
- Code: Select all
def apply(docxTemplate) {
Map sections = new HashMap()
sections.put("educacao", "Andre")
final String XPATH_TO_SELECT_TEXT_NODES = "//w:t"
WordprocessingMLPackage template = WordprocessingMLPackage.load(docxTemplate)
List texts = template.getMainDocumentPart()
.getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true)
for (Object obj : texts) {
Text text = (Text) ((JAXBElement) obj).getValue()
String textValue = text.getValue()
for (Object key : sections.keySet()) {
textValue = textValue.replaceAll(key, sections.get(key))
}
text.setValue(textValue)
}
// error happens here
template.save(new File("/tmp/report11.docx"))
}
Error
- Code: Select all
Error 2012-02-08 10:54:16,899 [main] ERROR utils.ResourceUtils - Couldn't get resource: docx4j.properties
Error 2012-02-08 10:54:16,901 [main] ERROR docx4j.Docx4jProperties - Error reading docx4j.properties
2012-02-07 23:30:55,620 [main] ERROR StackTrace - Full Stack Trace:
java.lang.NullPointerException
at org.docx4j.utils.ResourceUtils.getResource(ResourceUtils.java:45)
at org.docx4j.Docx4jProperties.init(Docx4jProperties.java:19)
at org.docx4j.Docx4jProperties.getProperties(Docx4jProperties.java:34)
at org.docx4j.openpackaging.io.SaveToZipFile.saveRawXmlPart(SaveToZipFile.java:207)
at org.docx4j.openpackaging.io.SaveToZipFile.saveRawXmlPart(SaveToZipFile.java:194)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:410)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:164)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:105)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:219)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage$save.call(Unknown Source)