de2aadd0 by Adam Heath

Merge branch 'BF-4364' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet

2 parents de5a7e1c 1eb9d36e
...@@ -35,16 +35,24 @@ public class LibreOfficeRenderer { ...@@ -35,16 +35,24 @@ public class LibreOfficeRenderer {
35 context.put("Linux_X86_64", "$Linux_X86_64"); 35 context.put("Linux_X86_64", "$Linux_X86_64");
36 context.put("Build", "$Build"); 36 context.put("Build", "$Build");
37 37
38 StringBuilder output = new StringBuilder();
39 int idx = 0;
40
41 while (idx < template.length()) {
42 int remaining = template.length() - idx;
43 int chunkLength = remaining < 64000 ? remaining : 64000;
44 String tmplChunk = template.substring(idx, idx + chunkLength);
38 SimpleTemplateEngine engine = new SimpleTemplateEngine(); 45 SimpleTemplateEngine engine = new SimpleTemplateEngine();
39 Writable stTemplate = engine.createTemplate(template).make(context); 46 Writable stTemplate = engine.createTemplate(tmplChunk).make(context);
40 String output = stTemplate.toString(); 47 output.append(stTemplate.toString());
48 idx += chunkLength;
49 }
41 50
42 File outputFile = File.createTempFile("bfdcs-", "-tmpl"); 51 File outputFile = File.createTempFile("bfdcs-", "-tmpl");
43 UtilIO.writeString(outputFile, output); 52 UtilIO.writeString(outputFile, output.toString());
44 53
45 List<String> args = Arrays.asList(new String[]{"libreoffice", "--headless", "--convert-to", "pdf", outputFile.getPath(), "--outdir", "/tmp"}); 54 ProcessBuilder pb = new ProcessBuilder("libreoffice", "--headless", "--convert-to", "pdf", outputFile.getPath(), "--outdir", outputFile.getParentFile().getPath());
46 ProcessBuilder pb = new ProcessBuilder(args); 55 Map<String, String> env = pb.environment();
47 Map env = pb.environment();
48 env.put("HOME", "/home/ofbiz"); 56 env.put("HOME", "/home/ofbiz");
49 env.put("USERNAME", "ofbiz"); 57 env.put("USERNAME", "ofbiz");
50 Process process = pb.start(); 58 Process process = pb.start();
......