01: package vqwiki.servlets;
02:
03: import vqwiki.TopicVersion;
04: import vqwiki.VersionManager;
05: import vqwiki.WikiBase;
06: import vqwiki.utils.Utilities;
07:
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11: import java.io.IOException;
12: import java.util.Collection;
13:
14: /**
15: * @author garethc
16: * Date: Jan 10, 2003
17: */
18: public class HistoryServlet extends VQWikiServlet {
19:
20: /**
21: *
22: */
23: protected void doGet(HttpServletRequest request,
24: HttpServletResponse response) throws ServletException,
25: IOException {
26: VersionManager manager;
27: String virtualWiki = (String) request
28: .getAttribute("virtualWiki");
29: String topicName = request.getParameter("topic");
30: try {
31: manager = WikiBase.getInstance()
32: .getVersionManagerInstance();
33: } catch (Exception e) {
34: error(request, response, e);
35: return;
36: }
37: String type = request.getParameter("type");
38: if (type.equals("all")) {
39: request.setAttribute("title", "History for " + topicName);
40: try {
41: Collection versions = manager.getAllVersions(
42: virtualWiki, topicName);
43: request.setAttribute("versions", versions);
44: dispatch("/jsp/history.jsp", request, response);
45: } catch (Exception e) {
46: error(request, response, e);
47: return;
48: }
49: } else if (type.equals("version")) {
50: int versionNumber = Integer.parseInt(request
51: .getParameter("versionNumber"));
52: try {
53: int numberOfVersions = manager.getNumberOfVersions(
54: virtualWiki, topicName);
55: TopicVersion topicVersion = manager.getTopicVersion(
56: virtualWiki, topicName, versionNumber);
57: request.setAttribute("topicVersion", topicVersion);
58: request.setAttribute("numberOfVersions", new Integer(
59: numberOfVersions));
60: request.setAttribute("title", topicName
61: + " @"
62: + Utilities.formatDateTime(topicVersion
63: .getRevisionDate()));
64: } catch (Exception e) {
65: error(request, response, e);
66: return;
67: }
68: dispatch("/jsp/history.jsp", request, response);
69: }
70: }
71: }
|