01: package org.claros.intouch.tasks.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import java.util.List;
06:
07: import javax.servlet.ServletException;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.claros.commons.utility.Utility;
12: import org.claros.intouch.common.services.BaseService;
13: import org.claros.intouch.tasks.controllers.TaskController;
14: import org.claros.intouch.tasks.models.Task;
15:
16: public class GetTasksService extends BaseService {
17: private static final long serialVersionUID = 3228489296620024338L;
18:
19: /**
20: *
21: */
22: public void doGet(HttpServletRequest request,
23: HttpServletResponse response) throws ServletException,
24: IOException {
25: response.setHeader("Expires", "-1");
26: response.setHeader("Pragma", "no-cache");
27: response.setHeader("Cache-control", "no-cache");
28: response.setHeader("Content-Type", "text/xml; charset=utf-8");
29: PrintWriter out = response.getWriter();
30:
31: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
32: out.write("<data>");
33: out.print("<tasks>");
34: try {
35: List<Task> tasks = TaskController.getTasks(getAuthProfile(
36: request).getUsername());
37: if (tasks != null) {
38: Task tmp = null;
39: for (int i = 0; i < tasks.size(); i++) {
40: try {
41: tmp = (Task) tasks.get(i);
42: out.print("<task>");
43:
44: out.print("<id>" + tmp.getId() + " </id>");
45: out.print("<checked>" + tmp.getChecked()
46: + " </checked>");
47: out.print("<color>" + tmp.getColor()
48: + " </color>");
49: out.print("<description>"
50: + Utility.htmlSpecialChars(tmp
51: .getDescription())
52: + " </description>");
53: out.print("<priority>" + tmp.getPriority()
54: + " </priority>");
55: out.print("<record-date>" + tmp.getRecordDate()
56: + " </record-date>");
57:
58: out.print("</task>");
59: } catch (Exception e) {
60: e.printStackTrace();
61: }
62: }
63: }
64: } catch (Exception e) {
65: e.printStackTrace();
66: }
67: out.print("</tasks>");
68: out.write("</data>");
69: }
70:
71: /**
72: *
73: */
74: protected void doPost(HttpServletRequest req,
75: HttpServletResponse resp) throws ServletException,
76: IOException {
77: doGet(req, resp);
78: }
79: }
|