Merge branch 'BF-4909' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet
Showing
1 changed file
with
47 additions
and
0 deletions
... | @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServlet; | ... | @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServlet; |
33 | import javax.servlet.http.HttpServletRequest; | 33 | import javax.servlet.http.HttpServletRequest; |
34 | import javax.servlet.http.HttpServletResponse; | 34 | import javax.servlet.http.HttpServletResponse; |
35 | import javax.servlet.http.HttpSession; | 35 | import javax.servlet.http.HttpSession; |
36 | import javax.servlet.http.Cookie; | ||
36 | 37 | ||
37 | import org.ofbiz.base.util.Debug; | 38 | import org.ofbiz.base.util.Debug; |
38 | import org.ofbiz.base.util.GroovyUtil; | 39 | import org.ofbiz.base.util.GroovyUtil; |
... | @@ -290,6 +291,52 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -290,6 +291,52 @@ public class DirectControlServlet extends HttpServlet { |
290 | writer.close(); | 291 | writer.close(); |
291 | } | 292 | } |
292 | 293 | ||
294 | if ("CSV".equals(outputHandler)) { | ||
295 | response.setContentType("text/csv"); | ||
296 | |||
297 | // Find the first list | ||
298 | List resList = null; | ||
299 | for (Object o : result.values()) { | ||
300 | if (o instanceof List) { | ||
301 | resList = (List) o; | ||
302 | break; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | if (resList != null) { | ||
307 | PrintWriter writer = response.getWriter(); | ||
308 | List<Map> data = null; | ||
309 | if (resList.get(1) instanceof List) { | ||
310 | data = (List<Map>)(resList.get(1)); | ||
311 | } else { | ||
312 | data = resList; | ||
313 | } | ||
314 | |||
315 | if (data.size() > 0) { | ||
316 | Iterator hi = ((Map) data.get(0)).keySet().iterator(); | ||
317 | StringBuffer csvBuf = new StringBuffer(); | ||
318 | while(hi.hasNext()) { | ||
319 | csvBuf.append(hi.next()); | ||
320 | if (hi.hasNext()) csvBuf.append(","); | ||
321 | } | ||
322 | writer.println(csvBuf); | ||
323 | |||
324 | for (Map row : data) { | ||
325 | Iterator i = row.values().iterator(); | ||
326 | csvBuf = new StringBuffer(); | ||
327 | while(i.hasNext()) { | ||
328 | csvBuf.append(i.next()); | ||
329 | if (i.hasNext()) csvBuf.append(","); | ||
330 | } | ||
331 | writer.println(csvBuf); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | writer.flush(); | ||
336 | writer.close(); | ||
337 | } | ||
338 | } | ||
339 | |||
293 | if ("PDF".equals(outputHandler)) { | 340 | if ("PDF".equals(outputHandler)) { |
294 | LibreOfficeRenderer.service(request, response, result); | 341 | LibreOfficeRenderer.service(request, response, result); |
295 | } | 342 | } | ... | ... |
-
Please register or sign in to post a comment