001: package org.claros.intouch.notes.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.text.SimpleDateFormat;
006: import java.util.Date;
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.common.services.BaseService;
015: import org.claros.intouch.notes.controllers.NotesController;
016: import org.claros.intouch.notes.models.Note;
017:
018: public class GetNotesByFolderService extends BaseService {
019:
020: /**
021: *
022: */
023: private static final long serialVersionUID = 105823654066222540L;
024: private static final SimpleDateFormat sdf = new SimpleDateFormat(
025: "dd.MM.yyyy");
026:
027: /**
028: *
029: * @param request
030: * the request send by the client to the server
031: * @param response
032: * the response send by the server to the client
033: * @throws ServletException
034: * if an error occurred
035: * @throws IOException
036: * if an error occurred
037: */
038: public void doPost(HttpServletRequest request,
039: HttpServletResponse response) throws ServletException,
040: IOException {
041: response.setHeader("Expires", "-1");
042: response.setHeader("Pragma", "no-cache");
043: response.setHeader("Cache-control", "no-cache");
044: response.setHeader("Content-Type", "text/xml; charset=utf-8");
045: PrintWriter out = response.getWriter();
046:
047: String sId = request.getParameter("folderId");
048: if (sId == null || sId.equals("")) {
049: sId = "0";
050: }
051: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
052: out.write("<data>");
053: out.print("<notes>");
054: try {
055: List notes = NotesController.getNotesByFolderId(
056: getAuthProfile(request), new Long(sId));
057: if (notes != null) {
058: Note tmp = null;
059: for (int i = 0; i < notes.size(); i++) {
060: try {
061: tmp = (Note) notes.get(i);
062: out.print("<note>");
063: out.print("<id>" + tmp.getId().intValue()
064: + "</id>");
065: out.print("<bar-color>"
066: + getVal(tmp.getNoteBarColor())
067: + "</bar-color>");
068: out.print("<border-color>"
069: + getVal(tmp.getNoteBorderColor())
070: + "</border-color>");
071: out.print("<bg-color>"
072: + getVal(tmp.getNoteColor())
073: + "</bg-color>");
074: out.print("<content>"
075: + Utility.htmlSpecialChars(getVal(tmp
076: .getNoteContent()))
077: + "</content>");
078: out.print("<date>"
079: + sdf.format(new Date(tmp.getNoteDate()
080: .getTime())) + "</date>");
081: out.print("<height>"
082: + tmp.getPosHeight().intValue()
083: + "</height>");
084: out.print("<left>"
085: + tmp.getPosLeft().intValue()
086: + "</left>");
087: out.print("<top>" + tmp.getPosTop().intValue()
088: + "</top>");
089: out.print("<width>"
090: + tmp.getPosWidth().intValue()
091: + "</width>");
092: out.print("</note>");
093: } catch (Exception e) {
094: e.printStackTrace();
095: }
096: }
097: }
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: out.print("</notes>");
102: out.write("</data>");
103: }
104:
105: private static String getVal(String str) {
106: return ((str == null || str.equals("")) ? " " : str);
107: }
108: }
|