01: package vqwiki.servlets;
02:
03: import vqwiki.Topic;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08: import java.io.IOException;
09: import java.util.Enumeration;
10:
11: /**
12: * @author garethc
13: * Date: Jan 8, 2003
14: */
15: public class DiffServlet extends VQWikiServlet {
16:
17: /**
18: *
19: */
20: protected void doPost(HttpServletRequest httpServletRequest,
21: HttpServletResponse httpServletResponse)
22: throws ServletException, IOException {
23: doGet(httpServletRequest, httpServletResponse);
24: }
25:
26: /**
27: *
28: */
29: protected void doGet(HttpServletRequest request,
30: HttpServletResponse response) throws ServletException,
31: IOException {
32: String virtualWiki = (String) request
33: .getAttribute("virtualWiki");
34: String topic = request.getParameter("topic");
35: request.setAttribute("title", "Diff " + topic);
36: request.setAttribute("topic", topic);
37: try {
38: Topic t = new Topic(topic);
39: String diffType = request.getParameter("type");
40: if (diffType != null && "arbitrary".equals(diffType)) {
41: int firstVersion = -1;
42: int secondVersion = -1;
43: Enumeration e = request.getParameterNames();
44: while (e.hasMoreElements()) {
45: String name = (String) e.nextElement();
46: if (name.startsWith("diff:")) {
47: int version = Integer.parseInt(name
48: .substring(name.indexOf(":") + 1));
49: if (firstVersion >= 0) {
50: secondVersion = version;
51: } else {
52: firstVersion = version;
53: }
54: }
55: }
56: if (firstVersion == -1 || secondVersion == -1) {
57: request.setAttribute("badinput", "true");
58: } else {
59: request.setAttribute("diff", t.getDiff(virtualWiki,
60: Math.min(firstVersion, secondVersion), Math
61: .max(firstVersion, secondVersion),
62: true));
63: }
64: } else {
65: request.setAttribute("diff", t.mostRecentDiff(
66: virtualWiki, true));
67: }
68: } catch (Exception e) {
69: error(request, response, e);
70: return;
71: }
72: dispatch("/jsp/diff.jsp", request, response);
73: }
74: }
|