01: package org.claros.intouch.contacts.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import java.util.ArrayList;
06:
07: import javax.servlet.ServletException;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.claros.commons.auth.models.AuthProfile;
12: import org.claros.intouch.common.services.BaseService;
13: import org.claros.intouch.contacts.controllers.ImportExportController;
14:
15: public class ExportAllContactsService extends BaseService {
16:
17: /**
18: *
19: */
20: private static final long serialVersionUID = -234121498656197582L;
21:
22: /**
23: * The doGet method of the servlet. <br>
24: *
25: * This method is called when a form has its tag value method equals to get.
26: *
27: * @param request the request send by the client to the server
28: * @param response the response send by the server to the client
29: * @throws ServletException if an error occurred
30: * @throws IOException if an error occurred
31: */
32: public void doGet(HttpServletRequest request,
33: HttpServletResponse response) throws ServletException,
34: IOException {
35: response.setContentType("text/csv; charset=UTF-8");
36: response.setHeader("Pragma", "public");
37: response.setHeader("Cache-Control", "must-revalidate");
38: response.setDateHeader("Expires", 0);
39:
40: response.setHeader("Content-disposition",
41: "attachment; filename=contacts.csv");
42:
43: PrintWriter out = response.getWriter();
44:
45: AuthProfile auth = (AuthProfile) request.getSession()
46: .getAttribute("auth");
47: ArrayList result = ImportExportController.exportContacts(auth);
48: if (result != null) {
49: for (int i = 0; i < result.size(); i++) {
50: out.write((String) result.get(i) + "\n");
51: }
52: }
53: }
54: }
|