8cf89907 by Ean Schuessler

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

2 parents de2aadd0 115554f0
......@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Cookie;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GroovyUtil;
......@@ -290,6 +291,52 @@ public class DirectControlServlet extends HttpServlet {
writer.close();
}
if ("CSV".equals(outputHandler)) {
response.setContentType("text/csv");
// Find the first list
List resList = null;
for (Object o : result.values()) {
if (o instanceof List) {
resList = (List) o;
break;
}
}
if (resList != null) {
PrintWriter writer = response.getWriter();
List<Map> data = null;
if (resList.get(1) instanceof List) {
data = (List<Map>)(resList.get(1));
} else {
data = resList;
}
if (data.size() > 0) {
Iterator hi = ((Map) data.get(0)).keySet().iterator();
StringBuffer csvBuf = new StringBuffer();
while(hi.hasNext()) {
csvBuf.append(hi.next());
if (hi.hasNext()) csvBuf.append(",");
}
writer.println(csvBuf);
for (Map row : data) {
Iterator i = row.values().iterator();
csvBuf = new StringBuffer();
while(i.hasNext()) {
csvBuf.append(i.next());
if (i.hasNext()) csvBuf.append(",");
}
writer.println(csvBuf);
}
}
writer.flush();
writer.close();
}
}
if ("PDF".equals(outputHandler)) {
LibreOfficeRenderer.service(request, response, result);
}
......