7646b262 by Ean Schuessler

Merge branch 'master' into BF-3913

Conflicts:
	src/com/brainfood/ofbiz/DirectControlServlet.java
2 parents 38519f21 cd8ca01e
...@@ -55,6 +55,9 @@ import org.ofbiz.service.LocalDispatcher; ...@@ -55,6 +55,9 @@ import org.ofbiz.service.LocalDispatcher;
55 import org.ofbiz.service.ModelService; 55 import org.ofbiz.service.ModelService;
56 import org.ofbiz.service.ServiceContainer; 56 import org.ofbiz.service.ServiceContainer;
57 57
58 import org.apache.commons.csv.CSVFormat;
59 import org.apache.commons.csv.CSVRecord;
60
58 import groovy.lang.GroovyClassLoader; 61 import groovy.lang.GroovyClassLoader;
59 import groovy.lang.Script; 62 import groovy.lang.Script;
60 63
...@@ -139,6 +142,28 @@ public class DirectControlServlet extends HttpServlet { ...@@ -139,6 +142,28 @@ public class DirectControlServlet extends HttpServlet {
139 for (String key : items.keySet()) { 142 for (String key : items.keySet()) {
140 context.put(key, items.get(key)); 143 context.put(key, items.get(key));
141 } 144 }
145 } else if ("text/csv".equals(contentType)) {
146 // Directly copy request parameters into context.
147 for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
148 String param = params.nextElement();
149 Object[] values = request.getParameterValues(param);
150 if (!"sessionId".equals(param) && !"_method".equals(param)) {
151 context.put(param, values.length == 1 ? values[0] : values);
152 }
153 }
154
155 Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader());
156 List<List<String>> data = new ArrayList<List<String>>();
157 for (CSVRecord record : records) {
158 List<String> row = new ArrayList<String>();
159 String cell = null;
160 Iterator<String> i=record.iterator();
161 while (i.hasNext()) {
162 row.add(i.next());
163 }
164 data.add(row);
165 }
166 context.put("data", data);
142 } else { 167 } else {
143 // Check if the request is a backbone style "emulateJSON" request 168 // Check if the request is a backbone style "emulateJSON" request
144 if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) { 169 if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) {
......
...@@ -14,6 +14,8 @@ import java.io.FileInputStream; ...@@ -14,6 +14,8 @@ import java.io.FileInputStream;
14 import java.io.IOException; 14 import java.io.IOException;
15 15
16 import org.ofbiz.base.util.UtilIO; 16 import org.ofbiz.base.util.UtilIO;
17 import org.ofbiz.base.component.ComponentConfig;
18 import org.ofbiz.base.component.ComponentException;
17 19
18 import groovy.text.SimpleTemplateEngine; 20 import groovy.text.SimpleTemplateEngine;
19 import groovy.text.Template; 21 import groovy.text.Template;
...@@ -21,11 +23,13 @@ import groovy.lang.Writable; ...@@ -21,11 +23,13 @@ import groovy.lang.Writable;
21 23
22 public class LibreOfficeRenderer { 24 public class LibreOfficeRenderer {
23 public static void service(HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) 25 public static void service(HttpServletRequest request, HttpServletResponse response, Map<String, Object> context)
24 throws InterruptedException, IOException, ClassNotFoundException { 26 throws InterruptedException, IOException, ClassNotFoundException, ComponentException {
25 Object templateFile = context.get("_template"); 27 Object templateFile = context.get("_template");
26 28
27 if (templateFile != null) { 29 if (templateFile != null) {
28 String template = UtilIO.readString(new FileInputStream(templateFile.toString())); 30 String fullPath = ComponentConfig.getRootLocation("driverup") + "/pdf-templates/" + templateFile.toString();
31
32 String template = UtilIO.readString(new FileInputStream(fullPath));
29 33
30 // FIXME: This is a hack. The Libreoffice file contains a $ declaration and this fixes it. 34 // FIXME: This is a hack. The Libreoffice file contains a $ declaration and this fixes it.
31 context.put("Linux_X86_64", "$Linux_X86_64"); 35 context.put("Linux_X86_64", "$Linux_X86_64");
......