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;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceContainer;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import groovy.lang.GroovyClassLoader;
import groovy.lang.Script;
......@@ -139,6 +142,28 @@ public class DirectControlServlet extends HttpServlet {
for (String key : items.keySet()) {
context.put(key, items.get(key));
}
} else if ("text/csv".equals(contentType)) {
// Directly copy request parameters into context.
for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
String param = params.nextElement();
Object[] values = request.getParameterValues(param);
if (!"sessionId".equals(param) && !"_method".equals(param)) {
context.put(param, values.length == 1 ? values[0] : values);
}
}
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader());
List<List<String>> data = new ArrayList<List<String>>();
for (CSVRecord record : records) {
List<String> row = new ArrayList<String>();
String cell = null;
Iterator<String> i=record.iterator();
while (i.hasNext()) {
row.add(i.next());
}
data.add(row);
}
context.put("data", data);
} else {
// Check if the request is a backbone style "emulateJSON" request
if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) {
......
......@@ -14,6 +14,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import org.ofbiz.base.util.UtilIO;
import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.component.ComponentException;
import groovy.text.SimpleTemplateEngine;
import groovy.text.Template;
......@@ -21,11 +23,13 @@ import groovy.lang.Writable;
public class LibreOfficeRenderer {
public static void service(HttpServletRequest request, HttpServletResponse response, Map<String, Object> context)
throws InterruptedException, IOException, ClassNotFoundException {
throws InterruptedException, IOException, ClassNotFoundException, ComponentException {
Object templateFile = context.get("_template");
if (templateFile != null) {
String template = UtilIO.readString(new FileInputStream(templateFile.toString()));
String fullPath = ComponentConfig.getRootLocation("driverup") + "/pdf-templates/" + templateFile.toString();
String template = UtilIO.readString(new FileInputStream(fullPath));
// FIXME: This is a hack. The Libreoffice file contains a $ declaration and this fixes it.
context.put("Linux_X86_64", "$Linux_X86_64");
......