31 import java.io.IOException; |
31 import java.io.IOException; |
32 import javax.servlet.ServletException; |
32 import javax.servlet.ServletException; |
33 import javax.servlet.http.HttpServlet; |
33 import javax.servlet.http.HttpServlet; |
34 import javax.servlet.http.HttpServletRequest; |
34 import javax.servlet.http.HttpServletRequest; |
35 import javax.servlet.http.HttpServletResponse; |
35 import javax.servlet.http.HttpServletResponse; |
|
36 import org.slf4j.Logger; |
|
37 import org.slf4j.LoggerFactory; |
36 |
38 |
37 /** |
39 /** |
38 * A special implementation of a HTTPServlet which is focused on implementing |
40 * A special implementation of a HTTPServlet which is focused on implementing |
39 * the necessary functionality for {@link LightPITModule}s. |
41 * the necessary functionality for {@link LightPITModule}s. |
40 */ |
42 */ |
41 public abstract class AbstractLightPITServlet extends HttpServlet { |
43 public abstract class AbstractLightPITServlet extends HttpServlet { |
42 |
44 |
|
45 private static final Logger LOG = LoggerFactory.getLogger(AbstractLightPITServlet.class); |
|
46 |
|
47 |
|
48 /** |
|
49 * Gives implementing modules access to the {@link ModuleManager}. |
|
50 * @return the module manager |
|
51 */ |
|
52 protected final ModuleManager getModuleManager() { |
|
53 return (ModuleManager) getServletContext().getAttribute(ModuleManager.SC_ATTR_NAME); |
|
54 } |
|
55 |
|
56 private void addPathInformation(HttpServletRequest req) { |
|
57 final String path = req.getServletPath()+"/"+req.getPathInfo(); |
|
58 req.setAttribute(Constants.REQ_ATTR_PATH, path); |
|
59 } |
|
60 |
|
61 private void forwardToFullView(HttpServletRequest req, HttpServletResponse resp) |
|
62 throws IOException, ServletException { |
|
63 |
|
64 addPathInformation(req); |
|
65 |
|
66 final ModuleManager mm = getModuleManager(); |
|
67 req.setAttribute(Constants.REQ_ATTR_MENU, mm.getMainMenu()); |
|
68 |
|
69 req.getRequestDispatcher(Functions.jspPath("full.jsp")).forward(req, resp); |
|
70 } |
|
71 |
43 @Override |
72 @Override |
44 protected final void doGet(HttpServletRequest req, HttpServletResponse resp) |
73 protected final void doGet(HttpServletRequest req, HttpServletResponse resp) |
45 throws ServletException, IOException { |
74 throws ServletException, IOException { |
46 |
75 forwardToFullView(req, resp); |
47 resp.getWriter().println("It works!"); |
|
48 } |
76 } |
49 |
77 |
50 @Override |
78 @Override |
51 protected final void doPost(HttpServletRequest req, HttpServletResponse resp) |
79 protected final void doPost(HttpServletRequest req, HttpServletResponse resp) |
52 throws ServletException, IOException { |
80 throws ServletException, IOException { |
|
81 |
|
82 forwardToFullView(req, resp); |
53 } |
83 } |
54 |
|
55 } |
84 } |