01: /**
02: * @author garethc
03: * 5/09/2002 13:03:32
04: */package vqwiki.servlets;
05:
06: import org.apache.log4j.Logger;
07: import vqwiki.WikiBase;
08: import vqwiki.utils.JSPUtils;
09: import vqwiki.utils.Utilities;
10:
11: import javax.servlet.RequestDispatcher;
12: import javax.servlet.ServletException;
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 SaveTemplateServlet extends HttpServlet {
19:
20: private static final Logger logger = Logger
21: .getLogger(SaveTemplateServlet.class);
22:
23: /**
24: *
25: */
26: protected void doPost(HttpServletRequest request,
27: HttpServletResponse response) throws ServletException,
28: IOException {
29: logger.debug("Request for save template");
30: String virtualWiki = null;
31: String topic = request.getParameter("topic");
32: String templateName = request.getParameter("save-template");
33: logger.debug("Saving template: " + templateName);
34: if (templateName == null || templateName.equals("")) {
35: throw new WikiServletException(
36: "Template name must be specified");
37: }
38: WikiBase base = null;
39: try {
40: virtualWiki = (String) request.getAttribute("virtual-wiki");
41: if (virtualWiki == null) {
42: virtualWiki = Utilities.extractVirtualWiki(request
43: .getRequestURI());
44: }
45: logger.debug("vwiki is " + virtualWiki);
46: base = WikiBase.getInstance();
47: base.unlockTopic(virtualWiki, topic);
48: } catch (Exception err) {
49: logger.error("error unlocking topic: " + err);
50: request.setAttribute("exception", new WikiServletException(
51: err.toString()));
52: RequestDispatcher dispatch = request
53: .getRequestDispatcher("/jsp/servlet-error.jsp");
54: dispatch.forward(request, response);
55: }
56: try {
57: base.saveAsTemplate(virtualWiki, templateName, request
58: .getParameter("contents"));
59: String next = JSPUtils.createLocalRootPath(request,
60: virtualWiki)
61: + "Wiki?" + topic;
62: logger.debug("Creating redirect: " + next);
63: logger.debug("Redirect URL: "
64: + response.encodeRedirectURL(next));
65: response.sendRedirect(response.encodeRedirectURL(next));
66: } catch (Exception err) {
67: request.setAttribute("exception", new WikiServletException(
68: err.toString()));
69: err.printStackTrace();
70: RequestDispatcher dispatch = request
71: .getRequestDispatcher("/jsp/servlet-error.jsp");
72: dispatch.forward(request, response);
73: }
74: }
75: }
|