01: /**
02: * @author garethc
03: * 15/10/2002 15:06:53
04: */package vqwiki.servlets;
05:
06: import vqwiki.Notify;
07: import vqwiki.WikiBase;
08: import vqwiki.WikiException;
09: import vqwiki.utils.JSPUtils;
10:
11: import javax.servlet.ServletException;
12: import javax.servlet.http.Cookie;
13: import javax.servlet.http.HttpServlet;
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16: import java.io.IOException;
17:
18: public class NotifyServlet extends HttpServlet {
19:
20: /**
21: *
22: */
23: protected void doPost(HttpServletRequest request,
24: HttpServletResponse response) throws ServletException,
25: IOException {
26: String virtualWiki = null;
27: String topic = null;
28: try {
29: virtualWiki = (String) request.getAttribute("virtual-wiki");
30: String action = request.getParameter("notify_action");
31: topic = request.getParameter("topic");
32: if (topic == null || topic.equals("")) {
33: throw new WikiException("Topic must be specified");
34: }
35: String user = "";
36:
37: user = request.getParameter("username");
38:
39: if (user == null || user.equals("")) {
40: Cookie[] cookies = request.getCookies();
41: if (cookies != null) {
42: if (cookies.length > 0) {
43: for (int i = 0; i < cookies.length; i++) {
44: if (cookies[i].getName().equals("username")) {
45: user = cookies[i].getValue();
46: }
47: }
48: }
49: }
50: }
51: if (user == null || user.equals("")) {
52: throw new WikiException("User name not found.");
53: }
54: Notify notifier = WikiBase.getInstance().getNotifyInstance(
55: virtualWiki, topic);
56: if (action == null || action.equals("notify_on")) {
57: notifier.addMember(user);
58: } else {
59: notifier.removeMember(user);
60: }
61: } catch (Exception e) {
62: throw new ServletException(e.getMessage(), e);
63: }
64: String next = JSPUtils
65: .createLocalRootPath(request, virtualWiki)
66: + "Wiki?" + topic;
67: response.sendRedirect(response.encodeRedirectURL(next));
68: }
69:
70: /**
71: *
72: */
73: protected void doGet(HttpServletRequest httpServletRequest,
74: HttpServletResponse httpServletResponse)
75: throws ServletException, IOException {
76: this.doPost(httpServletRequest, httpServletResponse);
77: }
78: }
|