void produce(Map additionalContext,
String templateName,
File destination,
String identifier,
String fileType) {
String tempResult = produceToString( additionalContext, templateName );
if(tempResult.trim().length()==0) {
log.warn("Generated output is empty. Skipped creation for file " + destination);
return;
}
FileWriter fileWriter = null;
try {
th.ensureExistence( destination );
ac.addFile(destination, fileType);
log.debug("Writing " + identifier + " to " + destination.getAbsolutePath() );
fileWriter = new FileWriter(destination);
fileWriter.write(tempResult);
}
catch (Exception e) {
throw new ExporterException("Error while writing result to file", e);
} finally {
if(fileWriter!=null) {
try {
fileWriter.flush();
fileWriter.close();
}
catch (IOException e) {
log.warn("Exception while flushing/closing " + destination,e);
}
}
}
}
|