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: * The doPost method of the servlet. <br>
25: *
26: * This method is called when a form has its tag value method equals to post.
27: *
28: * @param request the request send by the client to the server
29: * @param response the response send by the server to the client
30: * @throws ServletException if an error occurred
31: * @throws IOException 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 String(request.getParameter("content").getBytes(charset), "utf-8");
46: String content = request.getParameter("content");
47:
48: if (sId != null) {
49: try {
50: Note note = NotesController.getNoteById(
51: getAuthProfile(request), new Long(sId));
52: if (note != null) {
53: note.setNoteContent(content);
54: note
55: .setNoteDate(new Timestamp(new Date()
56: .getTime()));
57: NotesController.saveNote(getAuthProfile(request),
58: note);
59: }
60: out.print("ok");
61: } catch (Exception e) {
62: out.print("fail");
63: }
64: } else {
65: out.print("fail");
66: }
67: }
68:
69: }
|