001: package org.claros.intouch.calendar.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.text.DecimalFormat;
006: import java.util.Calendar;
007:
008: import javax.servlet.ServletException;
009: import javax.servlet.http.HttpServletRequest;
010: import javax.servlet.http.HttpServletResponse;
011:
012: import org.claros.commons.auth.models.AuthProfile;
013: import org.claros.commons.utility.Utility;
014: import org.claros.intouch.calendar.controllers.CalendarDBController;
015: import org.claros.intouch.calendar.models.CalendarObject;
016: import org.claros.intouch.common.services.BaseService;
017:
018: public class GetEventService extends BaseService {
019:
020: /**
021: *
022: */
023: private static final long serialVersionUID = 1977163899790595007L;
024:
025: /**
026: * The doPost method of the servlet. <br>
027: *
028: * This method is called when a form has its tag value method equals to post.
029: *
030: * @param request the request send by the client to the server
031: * @param response the response send by the server to the client
032: * @throws ServletException if an error occurred
033: * @throws IOException if an error occurred
034: */
035: public void doPost(HttpServletRequest request,
036: HttpServletResponse response) throws ServletException,
037: IOException {
038: response.setHeader("Expires", "-1");
039: response.setHeader("Pragma", "no-cache");
040: response.setHeader("Cache-control", "no-cache");
041: response.setHeader("Content-Type", "text/xml; charset=utf-8");
042: PrintWriter out = response.getWriter();
043:
044: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
045: out.write("<data>");
046: out.print("<events>");
047:
048: try {
049: String sEventId = request.getParameter("eventId");
050: AuthProfile auth = getAuthProfile(request);
051:
052: CalendarObject tmp = CalendarDBController.getEventById(
053: auth, new Long(sEventId));
054: Calendar cal = Calendar.getInstance();
055: Calendar calTmp = Calendar.getInstance();
056: cal.setTimeInMillis(tmp.getRecordDate().getTime());
057: DecimalFormat df = new DecimalFormat("00");
058:
059: out.print("<event>");
060: out.print("<id>" + tmp.getId() + " </id>");
061: out.print("<year>" + cal.get(Calendar.YEAR) + " </year>");
062: out.print("<month>"
063: + df.format((cal.get(Calendar.MONTH) + 1))
064: + " </month>");
065: out.print("<day>" + df.format(cal.get(Calendar.DATE))
066: + " </day>");
067: out
068: .print("<begin>"
069: + df.format(cal.get(Calendar.HOUR_OF_DAY))
070: + ":" + df.format(cal.get(Calendar.MINUTE))
071: + " </begin>");
072: calTmp.setTimeInMillis(tmp.getEndDate().getTime());
073: out.print("<end>"
074: + df.format(calTmp.get(Calendar.HOUR_OF_DAY)) + ":"
075: + df.format(calTmp.get(Calendar.MINUTE))
076: + " </end>");
077: out.print("<color>" + tmp.getColor() + " </color>");
078: out.print("<description>"
079: + Utility.htmlSpecialChars(tmp.getDescription())
080: + " </description>");
081: out
082: .print("<hasReminder>"
083: + (tmp.getReminderDays() != null
084: && tmp.getReminderDays().equals(
085: "-1") ? "false" : "true")
086: + " </hasReminder>");
087: out.print("<repeatType>" + tmp.getRepeatType()
088: + " </repeatType>");
089: out
090: .print("<location>" + tmp.getLocation()
091: + " </location>");
092: out.print("<reminderDays>" + tmp.getReminderDays()
093: + " </reminderDays>");
094: out.print("<reminderMethod>" + tmp.getReminderMethod()
095: + " </reminderMethod>");
096:
097: out.print("</event>");
098:
099: out.print("</events>");
100: out.print("<result>0</result>");
101: out.write("</data>");
102: } catch (Exception e) {
103: out.print("</events>");
104: out.print("<result>1</result>");
105: out.write("</data>");
106: }
107:
108: }
109:
110: }
|