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: import java.util.List;
008:
009: import javax.servlet.ServletException;
010: import javax.servlet.http.HttpServletRequest;
011: import javax.servlet.http.HttpServletResponse;
012:
013: import org.claros.commons.utility.Utility;
014: import org.claros.intouch.calendar.controllers.CalendarController;
015: import org.claros.intouch.calendar.models.CalendarObjectWrap;
016: import org.claros.intouch.common.services.BaseService;
017:
018: public class CheckAlertService extends BaseService {
019: private static final long serialVersionUID = 1443175579513896492L;
020: private static DecimalFormat df = new DecimalFormat("00");
021:
022: /**
023: * @param request the request send by the client to the server
024: * @param response the response send by the server to the client
025: * @throws ServletException if an error occurred
026: * @throws IOException if an error occurred
027: */
028: public void doGet(HttpServletRequest request,
029: HttpServletResponse response) throws ServletException,
030: IOException {
031: response.setHeader("Expires", "-1");
032: response.setHeader("Pragma", "no-cache");
033: response.setHeader("Cache-control", "no-cache");
034: response.setHeader("Content-Type", "text/xml; charset=utf-8");
035: PrintWriter out = response.getWriter();
036:
037: try {
038: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
039: out.write("<data>");
040: out.print("<events>");
041:
042: List alerts = CalendarController
043: .getAlertsByUser(getAuthProfile(request));
044: if (alerts != null && alerts.size() > 0) {
045: CalendarObjectWrap tmp = null;
046: Calendar calTmp2 = Calendar.getInstance();
047: Calendar calTmp = Calendar.getInstance();
048: for (int i = 0; i < alerts.size(); i++) {
049: tmp = (CalendarObjectWrap) alerts.get(i);
050: if (tmp.getReminderMethod().intValue() == 1
051: && (tmp.getRemindedBefore() == null || tmp
052: .getRemindedBefore()
053: .equals("false"))) { // is it a popup reminder
054: calTmp.setTimeInMillis(tmp.getEndDate()
055: .getTime());
056: calTmp2.setTimeInMillis(tmp.getOccuringDate()
057: .getTime());
058: out.print("<event>");
059: out.print("<id>" + tmp.getId() + " </id>");
060: out.print("<year>" + calTmp2.get(Calendar.YEAR)
061: + " </year>");
062: out
063: .print("<month>"
064: + df
065: .format(calTmp2
066: .get(Calendar.MONTH) + 1)
067: + " </month>");
068: out.print("<day>"
069: + df.format(calTmp2.get(Calendar.DATE))
070: + " </day>");
071: out.print("<begin>"
072: + df.format(calTmp2
073: .get(Calendar.HOUR_OF_DAY))
074: + ":"
075: + df.format(calTmp2
076: .get(Calendar.MINUTE))
077: + " </begin>");
078: out.print("<end>"
079: + df.format(calTmp
080: .get(Calendar.HOUR_OF_DAY))
081: + ":"
082: + df
083: .format(calTmp
084: .get(Calendar.MINUTE))
085: + " </end>");
086: out.print("<color>" + tmp.getColor()
087: + " </color>");
088: out.print("<description>"
089: + Utility.htmlSpecialChars(tmp
090: .getDescription())
091: + " </description>");
092: out.print("<hasReminder>"
093: + (tmp.getReminderDays() != null
094: && tmp.getReminderDays()
095: .equals("-1") ? "false"
096: : "true") + " </hasReminder>");
097: out.print("<repeatType>" + tmp.getRepeatType()
098: + " </repeatType>");
099: out.print("<location>" + tmp.getLocation()
100: + " </location>");
101: out.print("<reminderDays>"
102: + tmp.getReminderDays()
103: + " </reminderDays>");
104: out.print("<reminderMethod>"
105: + tmp.getReminderMethod()
106: + " </reminderMethod>");
107: out.print("<remindedBefore>"
108: + tmp.getRemindedBefore()
109: + " </remindedBefore>");
110: out.print("</event>");
111: }
112: }
113: }
114: out.print("</events>");
115: out.print("<result>0</result>");
116: out.write("</data>");
117: } catch (Exception e) {
118: e.printStackTrace();
119: out.print("</events>");
120: out.print("<result>1</result>");
121: out.write("</data>");
122: }
123:
124: }
125:
126: }
|