01: package org.claros.intouch.tasks.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.claros.commons.utility.Utility;
11: import org.claros.intouch.common.services.BaseService;
12: import org.claros.intouch.tasks.controllers.TaskController;
13: import org.claros.intouch.tasks.models.Task;
14:
15: public class GetTaskService extends BaseService {
16: private static final long serialVersionUID = -8130885905235566600L;
17:
18: /**
19: * @param request the request send by the client to the server
20: * @param response the response send by the server to the client
21: * @throws ServletException if an error occurred
22: * @throws IOException if an error occurred
23: */
24: public void doPost(HttpServletRequest request,
25: HttpServletResponse response) throws ServletException,
26: IOException {
27: response.setHeader("Expires", "-1");
28: response.setHeader("Pragma", "no-cache");
29: response.setHeader("Cache-control", "no-cache");
30: response.setHeader("Content-Type", "text/xml; charset=utf-8");
31: PrintWriter out = response.getWriter();
32:
33: String sId = request.getParameter("id");
34:
35: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
36: out.write("<data>");
37: try {
38: Task tmp = TaskController.getTaskById(getAuthProfile(
39: request).getUsername(), new Long(sId));
40: if (tmp != null) {
41: try {
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() + " </color>");
48: out.print("<description>"
49: + Utility.htmlSpecialChars(tmp
50: .getDescription())
51: + " </description>");
52: out.print("<priority>" + tmp.getPriority()
53: + " </priority>");
54: out.print("<record-date>" + tmp.getRecordDate()
55: + " </record-date>");
56:
57: out.print("</task>");
58: } catch (Exception e) {
59: e.printStackTrace();
60: }
61: }
62: } catch (Exception e) {
63: e.printStackTrace();
64: }
65: out.write("</data>");
66: }
67:
68: }
|