Search in sources :

Example 1 with GroovyTemplates

use of com.axelor.text.GroovyTemplates in project axelor-open-suite by axelor.

the class AppLoaderExportServiceImpl method addAppDataFile.

protected void addAppDataFile(AppLoader appLoader, File exportDir) throws IOException {
    Map<String, InputStream> inputStreams = getExportTemplateResources();
    GroovyTemplates templates = new GroovyTemplates();
    for (String xmlFileName : inputStreams.keySet()) {
        log.debug("Exporting file: {}", xmlFileName);
        File file = new File(exportDir, xmlFileName);
        FileWriter writer = new FileWriter(file);
        Map<String, Object> ctx = getExportContext(appLoader);
        templates.from(new InputStreamReader(inputStreams.get(xmlFileName))).make(ctx).render(writer);
        writer.close();
        if (file.length() == 0) {
            file.delete();
        } else {
            long lines = java.nio.file.Files.lines(file.toPath()).count();
            if (lines == 1) {
                file.delete();
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) GroovyTemplates(com.axelor.text.GroovyTemplates) File(java.io.File)

Aggregations

GroovyTemplates (com.axelor.text.GroovyTemplates)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1