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

changeset 45
cc7f082c5ef3
parent 43
9abf0bf44c7b
child 47
57cfb94ab99f
     1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Wed May 13 18:55:05 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Wed May 13 21:10:23 2020 +0200
     1.3 @@ -71,6 +71,8 @@
     1.4       */
     1.5      private final Map<HttpMethod, Map<String, Method>> mappings = new HashMap<>();
     1.6  
     1.7 +    private final List<MenuEntry> subMenu = new ArrayList<>();
     1.8 +
     1.9      /**
    1.10       * Gives implementing modules access to the {@link ModuleManager}.
    1.11       *
    1.12 @@ -174,6 +176,14 @@
    1.13                              );
    1.14                          }
    1.15  
    1.16 +                        final var menuKey = mapping.get().menuKey();
    1.17 +                        if (!menuKey.isBlank()) {
    1.18 +                            subMenu.add(new MenuEntry(
    1.19 +                                    new ResourceKey(moduleInfo.getBundleBaseName(), menuKey),
    1.20 +                                    moduleInfo.getModulePath() + requestPath,
    1.21 +                                    mapping.get().menuSequence()));
    1.22 +                        }
    1.23 +
    1.24                          LOG.debug("{} {} maps to {}::{}",
    1.25                                  mapping.get().method(),
    1.26                                  requestPath,
    1.27 @@ -234,13 +244,16 @@
    1.28              throws IOException, ServletException {
    1.29  
    1.30          req.setAttribute(Constants.REQ_ATTR_MENU, getModuleManager().getMainMenu());
    1.31 +        req.setAttribute(Constants.REQ_ATTR_SUB_MENU, subMenu);
    1.32          req.getRequestDispatcher(SITE_JSP).forward(req, resp);
    1.33      }
    1.34  
    1.35 +    private String sanitizeRequestPath(HttpServletRequest req) {
    1.36 +        return Optional.ofNullable(req.getPathInfo()).orElse("/");
    1.37 +    }
    1.38 +
    1.39      private Optional<Method> findMapping(HttpMethod method, HttpServletRequest req) {
    1.40 -        return Optional.ofNullable(mappings.get(method))
    1.41 -                .map(rm -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/"))
    1.42 -                );
    1.43 +        return Optional.ofNullable(mappings.get(method)).map(rm -> rm.get(sanitizeRequestPath(req)));
    1.44      }
    1.45  
    1.46      private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp)
    1.47 @@ -275,7 +288,6 @@
    1.48  
    1.49          // set some internal request attributes
    1.50          req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req));
    1.51 -        req.setAttribute(Constants.REQ_ATTR_MODULE_CLASSNAME, this.getClass().getName());
    1.52          Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy));
    1.53  
    1.54          // obtain a connection and create the data access objects

mercurial