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: * The doPost method of the servlet. <br>
029: *
030: * This method is called when a form has its tag value method equals to post.
031: *
032: * @param request the request send by the client to the server
033: * @param response the response send by the server to the client
034: * @throws ServletException if an error occurred
035: * @throws IOException if an error occurred
036: */
037: public void doPost(HttpServletRequest request,
038: HttpServletResponse response) throws ServletException,
039: IOException {
040: response.setHeader("Expires", "-1");
041: response.setHeader("Pragma", "no-cache");
042: response.setHeader("Cache-control", "no-cache");
043: response.setHeader("Content-Type", "text/xml; charset=utf-8");
044: PrintWriter out = response.getWriter();
045:
046: String sId = request.getParameter("folderId");
047: if (sId == null || sId.equals("")) {
048: sId = "0";
049: }
050: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
051: out.write("<data>");
052: out.print("<notes>");
053: try {
054: List notes = NotesController.getNotesByFolderId(
055: getAuthProfile(request), new Long(sId));
056: if (notes != null) {
057: Note tmp = null;
058: for (int i = 0; i < notes.size(); i++) {
059: try {
060: tmp = (Note) notes.get(i);
061: out.print("<note>");
062: out.print("<id>" + tmp.getId().intValue()
063: + "</id>");
064: out.print("<bar-color>"
065: + getVal(tmp.getNoteBarColor())
066: + "</bar-color>");
067: out.print("<border-color>"
068: + getVal(tmp.getNoteBorderColor())
069: + "</border-color>");
070: out.print("<bg-color>"
071: + getVal(tmp.getNoteColor())
072: + "</bg-color>");
073: out.print("<content>"
074: + Utility.htmlSpecialChars(getVal(tmp
075: .getNoteContent()))
076: + "</content>");
077: out.print("<date>"
078: + sdf.format(new Date(tmp.getNoteDate()
079: .getTime())) + "</date>");
080: out.print("<height>"
081: + tmp.getPosHeight().intValue()
082: + "</height>");
083: out.print("<left>"
084: + tmp.getPosLeft().intValue()
085: + "</left>");
086: out.print("<top>" + tmp.getPosTop().intValue()
087: + "</top>");
088: out.print("<width>"
089: + tmp.getPosWidth().intValue()
090: + "</width>");
091: out.print("</note>");
092: } catch (Exception e) {
093: e.printStackTrace();
094: }
095: }
096: }
097: } catch (Exception e) {
098: e.printStackTrace();
099: }
100: out.print("</notes>");
101: out.write("</data>");
102: }
103:
104: private static String getVal(String str) {
105: return ((str == null || str.equals("")) ? " " : str);
106: }
107: }
|