cd8ca01e by Adam Heath

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

2 parents ef4b37ae 8e6015ca
......@@ -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,11 +142,31 @@ 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) {
if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) {
Debug.logInfo("MODEL: " + request.getParameter("model"), module);
JSON json = new JSON(new StringReader(request.getParameter("model")));
Map<String,Object> items = json.JSONObject();
......@@ -254,7 +277,6 @@ public class DirectControlServlet extends HttpServlet {
String jsonStr = json.toString();
response.setContentLength(jsonStr.getBytes("UTF8").length);
writer.write(jsonStr);
writer.flush();
writer.close();
} catch (Throwable t) {
......