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

changeset 45
cc7f082c5ef3
parent 43
9abf0bf44c7b
child 47
57cfb94ab99f
equal deleted inserted replaced
44:835dd169642a 45:cc7f082c5ef3
68 * <p> 68 * <p>
69 * The reason for this is the different handling of empty paths in 69 * The reason for this is the different handling of empty paths in
70 * {@link HttpServletRequest#getPathInfo()}. 70 * {@link HttpServletRequest#getPathInfo()}.
71 */ 71 */
72 private final Map<HttpMethod, Map<String, Method>> mappings = new HashMap<>(); 72 private final Map<HttpMethod, Map<String, Method>> mappings = new HashMap<>();
73
74 private final List<MenuEntry> subMenu = new ArrayList<>();
73 75
74 /** 76 /**
75 * Gives implementing modules access to the {@link ModuleManager}. 77 * Gives implementing modules access to the {@link ModuleManager}.
76 * 78 *
77 * @return the module manager 79 * @return the module manager
172 mapping.get().method(), 174 mapping.get().method(),
173 mapping.get().requestPath() 175 mapping.get().requestPath()
174 ); 176 );
175 } 177 }
176 178
179 final var menuKey = mapping.get().menuKey();
180 if (!menuKey.isBlank()) {
181 subMenu.add(new MenuEntry(
182 new ResourceKey(moduleInfo.getBundleBaseName(), menuKey),
183 moduleInfo.getModulePath() + requestPath,
184 mapping.get().menuSequence()));
185 }
186
177 LOG.debug("{} {} maps to {}::{}", 187 LOG.debug("{} {} maps to {}::{}",
178 mapping.get().method(), 188 mapping.get().method(),
179 requestPath, 189 requestPath,
180 getClass().getSimpleName(), 190 getClass().getSimpleName(),
181 method.getName() 191 method.getName()
232 242
233 private void forwardToFullView(HttpServletRequest req, HttpServletResponse resp) 243 private void forwardToFullView(HttpServletRequest req, HttpServletResponse resp)
234 throws IOException, ServletException { 244 throws IOException, ServletException {
235 245
236 req.setAttribute(Constants.REQ_ATTR_MENU, getModuleManager().getMainMenu()); 246 req.setAttribute(Constants.REQ_ATTR_MENU, getModuleManager().getMainMenu());
247 req.setAttribute(Constants.REQ_ATTR_SUB_MENU, subMenu);
237 req.getRequestDispatcher(SITE_JSP).forward(req, resp); 248 req.getRequestDispatcher(SITE_JSP).forward(req, resp);
238 } 249 }
239 250
251 private String sanitizeRequestPath(HttpServletRequest req) {
252 return Optional.ofNullable(req.getPathInfo()).orElse("/");
253 }
254
240 private Optional<Method> findMapping(HttpMethod method, HttpServletRequest req) { 255 private Optional<Method> findMapping(HttpMethod method, HttpServletRequest req) {
241 return Optional.ofNullable(mappings.get(method)) 256 return Optional.ofNullable(mappings.get(method)).map(rm -> rm.get(sanitizeRequestPath(req)));
242 .map(rm -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/"))
243 );
244 } 257 }
245 258
246 private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp) 259 private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp)
247 throws ServletException, IOException { 260 throws ServletException, IOException {
248 switch (type) { 261 switch (type) {
273 LOG.trace("Continuing session {} with language {}", session.getId(), sessionLocale); 286 LOG.trace("Continuing session {} with language {}", session.getId(), sessionLocale);
274 } 287 }
275 288
276 // set some internal request attributes 289 // set some internal request attributes
277 req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req)); 290 req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req));
278 req.setAttribute(Constants.REQ_ATTR_MODULE_CLASSNAME, this.getClass().getName());
279 Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); 291 Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy));
280 292
281 // obtain a connection and create the data access objects 293 // obtain a connection and create the data access objects
282 final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); 294 final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME);
283 try (final var connection = db.getDataSource().getConnection()) { 295 try (final var connection = db.getDataSource().getConnection()) {

mercurial