01: package org.claros.intouch.notes.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import java.sql.Timestamp;
06: import java.util.Date;
07:
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.claros.intouch.common.services.BaseService;
13: import org.claros.intouch.notes.controllers.NotesController;
14: import org.claros.intouch.notes.models.Note;
15:
16: public class SaveNoteService extends BaseService {
17:
18: /**
19: *
20: */
21: private static final long serialVersionUID = 8523420192102158048L;
22:
23: /**
24: * @param request
25: * the request send by the client to the server
26: * @param response
27: * the response send by the server to the client
28: * @throws ServletException
29: * if an error occurred
30: * @throws IOException
31: * if an error occurred
32: */
33: public void doPost(HttpServletRequest request,
34: HttpServletResponse response) throws ServletException,
35: IOException {
36:
37: response.setHeader("Expires", "-1");
38: response.setHeader("Pragma", "no-cache");
39: response.setHeader("Cache-control", "no-cache");
40: response.setHeader("Content-Type", "text/html; charset=utf-8");
41: PrintWriter out = response.getWriter();
42:
43: String sId = request.getParameter("id");
44: // String charset = Constants.charset;
45: // String content = new
46: // String(request.getParameter("content").getBytes(charset), "utf-8");
47: String content = request.getParameter("content");
48:
49: if (sId != null) {
50: try {
51: Note note = NotesController.getNoteById(
52: getAuthProfile(request), new Long(sId));
53: if (note != null) {
54: note.setNoteContent(content);
55: note
56: .setNoteDate(new Timestamp(new Date()
57: .getTime()));
58: NotesController.saveNote(getAuthProfile(request),
59: note);
60: }
61: out.print("ok");
62: } catch (Exception e) {
63: out.print("fail");
64: }
65: } else {
66: out.print("fail");
67: }
68: }
69:
70: }
|