src/java/de/uapcore/lightpit/AbstractLightPITServlet.java

Sat, 16 Dec 2017 20:19:28 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 16 Dec 2017 20:19:28 +0100
changeset 10
89e3e6e28b69
parent 9
20a9b2bc9063
child 11
737ab27e37b3
permissions
-rw-r--r--

implements automatic menu generation from module information

universe@7 1 /*
universe@7 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@7 3 *
universe@7 4 * Copyright 2017 Mike Becker. All rights reserved.
universe@7 5 *
universe@7 6 * Redistribution and use in source and binary forms, with or without
universe@7 7 * modification, are permitted provided that the following conditions are met:
universe@7 8 *
universe@7 9 * 1. Redistributions of source code must retain the above copyright
universe@7 10 * notice, this list of conditions and the following disclaimer.
universe@7 11 *
universe@7 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@7 13 * notice, this list of conditions and the following disclaimer in the
universe@7 14 * documentation and/or other materials provided with the distribution.
universe@7 15 *
universe@7 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@7 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@7 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@7 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@7 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@7 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@7 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@7 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@7 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@7 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@7 26 * POSSIBILITY OF SUCH DAMAGE.
universe@7 27 *
universe@7 28 */
universe@7 29 package de.uapcore.lightpit;
universe@7 30
universe@7 31 import java.io.IOException;
universe@7 32 import javax.servlet.ServletException;
universe@7 33 import javax.servlet.http.HttpServlet;
universe@7 34 import javax.servlet.http.HttpServletRequest;
universe@7 35 import javax.servlet.http.HttpServletResponse;
universe@10 36 import org.slf4j.Logger;
universe@10 37 import org.slf4j.LoggerFactory;
universe@7 38
universe@7 39 /**
universe@7 40 * A special implementation of a HTTPServlet which is focused on implementing
universe@7 41 * the necessary functionality for {@link LightPITModule}s.
universe@7 42 */
universe@9 43 public abstract class AbstractLightPITServlet extends HttpServlet {
universe@7 44
universe@10 45 private static final Logger LOG = LoggerFactory.getLogger(AbstractLightPITServlet.class);
universe@10 46
universe@10 47
universe@10 48 /**
universe@10 49 * Gives implementing modules access to the {@link ModuleManager}.
universe@10 50 * @return the module manager
universe@10 51 */
universe@10 52 protected final ModuleManager getModuleManager() {
universe@10 53 return (ModuleManager) getServletContext().getAttribute(ModuleManager.SC_ATTR_NAME);
universe@10 54 }
universe@10 55
universe@10 56 private void addPathInformation(HttpServletRequest req) {
universe@10 57 final String path = req.getServletPath()+"/"+req.getPathInfo();
universe@10 58 req.setAttribute(Constants.REQ_ATTR_PATH, path);
universe@10 59 }
universe@10 60
universe@10 61 private void forwardToFullView(HttpServletRequest req, HttpServletResponse resp)
universe@10 62 throws IOException, ServletException {
universe@10 63
universe@10 64 addPathInformation(req);
universe@10 65
universe@10 66 final ModuleManager mm = getModuleManager();
universe@10 67 req.setAttribute(Constants.REQ_ATTR_MENU, mm.getMainMenu());
universe@10 68
universe@10 69 req.getRequestDispatcher(Functions.jspPath("full.jsp")).forward(req, resp);
universe@10 70 }
universe@10 71
universe@7 72 @Override
universe@7 73 protected final void doGet(HttpServletRequest req, HttpServletResponse resp)
universe@7 74 throws ServletException, IOException {
universe@10 75 forwardToFullView(req, resp);
universe@7 76 }
universe@7 77
universe@7 78 @Override
universe@7 79 protected final void doPost(HttpServletRequest req, HttpServletResponse resp)
universe@7 80 throws ServletException, IOException {
universe@10 81
universe@10 82 forwardToFullView(req, resp);
universe@7 83 }
universe@7 84 }

mercurial