Sat, 23 May 2020 13:52:04 +0200
bloat removal 2/3 - moduleInfo
--- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 23 13:52:04 2020 +0200 @@ -58,10 +58,6 @@ private static final String SITE_JSP = Functions.jspPath("site"); - /** - * The EL proxy is necessary, because the EL resolver cannot handle annotation properties. - */ - private LightPITModule.ELProxy moduleInfo = null; @FunctionalInterface protected interface SQLFindFunction<K, T> { @@ -102,6 +98,12 @@ return (ModuleManager) getServletContext().getAttribute(ModuleManager.SC_ATTR_NAME); } + /** + * Returns the name of the resource bundle associated with this servlet. + * @return the resource bundle base name + */ + protected abstract String getResourceBundleName(); + /** * Creates a set of data access objects for the specified connection. @@ -150,12 +152,7 @@ @Override public void init() throws ServletException { - moduleInfo = Optional.ofNullable(this.getClass().getAnnotation(LightPITModule.class)) - .map(LightPITModule.ELProxy::new).orElse(null); - - if (moduleInfo != null) { - scanForRequestMappings(); - } + scanForRequestMappings(); LOG.trace("{} initialized", getServletName()); } @@ -387,7 +384,7 @@ final String fullPath = Functions.fullPath(req); req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req)); req.setAttribute(Constants.REQ_ATTR_PATH, fullPath); - Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); + req.setAttribute(Constants.REQ_ATTR_RESOURCE_BUNDLE, getResourceBundleName()); // if this is an error path, bypass the normal flow if (fullPath.startsWith("/error/")) {
--- a/src/main/java/de/uapcore/lightpit/Constants.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/Constants.java Sat May 23 13:52:04 2020 +0200 @@ -62,9 +62,9 @@ public static final String CTX_ATTR_DB_DIALECT = "db-dialect"; /** - * Key for the request attribute containing the {@link LightPITModule} information of the currently dispatching module. + * Key for the request attribute containing the resource bundle name. */ - public static final String REQ_ATTR_MODULE_INFO = fqn(AbstractLightPITServlet.class, "moduleInfo"); + public static final String REQ_ATTR_RESOURCE_BUNDLE = fqn(AbstractLightPITServlet.class, "bundleName"); /** * Key for the request attribute containing the menu list.
--- a/src/main/java/de/uapcore/lightpit/Functions.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/Functions.java Sat May 23 13:52:04 2020 +0200 @@ -75,28 +75,6 @@ } /** - * Returns the module path of the given LightPIT Servlet module. - * <p> - * If you specify a malformed LightPIT servlet, which does not have a module - * annotation, the path to the <code>/error/404.html</code> page is returned. - * - * @param clazz the servlet class - * @return the module path - */ - public static String modulePathOf(Class<? extends AbstractLightPITServlet> clazz) { - Optional<LightPITModule> moduleInfo = Optional.ofNullable(clazz.getAnnotation(LightPITModule.class)); - if (moduleInfo.isPresent()) { - return moduleInfo.get().modulePath(); - } else { - LOG.warn( - "{} is a LightPIT Servlet but is missing the module annotation.", - clazz.getName() - ); - return "/error/404.html"; - } - } - - /** * This class is not instantiatable. */ private Functions() {
--- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat May 23 13:52:04 2020 +0200 @@ -51,6 +51,11 @@ public static final String REQ_ATTR_RETURN_LINK = "returnLink"; + @Override + protected String getResourceBundleName() { + return "localization.error"; + } + @RequestMapping(requestPath = "generic", method = HttpMethod.GET) public ResponseType onError(HttpServletRequest req, HttpServletResponse resp) { Optional.ofNullable(req.getHeader("Referer")).ifPresent(
--- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat May 23 13:52:04 2020 +0200 @@ -55,6 +55,11 @@ private final List<Locale> languages = new ArrayList<>(); @Override + protected String getResourceBundleName() { + return "localization.language"; + } + + @Override public void init() throws ServletException { super.init();
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat May 23 13:52:04 2020 +0200 @@ -133,6 +133,10 @@ } } + @Override + protected String getResourceBundleName() { + return "localization.projects"; + } /** * Creates the breadcrumb menu.
--- a/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Sat May 23 13:34:41 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Sat May 23 13:52:04 2020 +0200 @@ -53,6 +53,11 @@ private static final Logger LOG = LoggerFactory.getLogger(UsersModule.class); + @Override + protected String getResourceBundleName() { + return "localization.users"; + } + @RequestMapping(method = HttpMethod.GET) public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { final var userDao = dao.getUserDao();
--- a/src/main/webapp/WEB-INF/jsp/issue-form.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/issue-form.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,19 +25,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> - <jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" /> <jsp:useBean id="issue" type="de.uapcore.lightpit.entities.Issue" scope="request"/> <jsp:useBean id="issueStatusEnum" type="de.uapcore.lightpit.entities.IssueStatus[]" scope="request"/> <jsp:useBean id="issueCategoryEnum" type="de.uapcore.lightpit.entities.IssueCategory[]" scope="request"/> <jsp:useBean id="users" type="java.util.List<de.uapcore.lightpit.entities.User>" scope="request"/> -<form action="./${moduleInfo.modulePath}/issues/commit" method="post"> +<form action="./projects/issues/commit" method="post"> <table class="formtable"> <colgroup> <col> @@ -165,10 +162,10 @@ <input type="hidden" name="id" value="${issue.id}"/> <c:choose> <c:when test="${not empty issue.project and issue.project.id ge 0}"> - <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${issue.project.id}</c:set> + <c:set var="cancelUrl">./projects/view?pid=${issue.project.id}</c:set> </c:when> <c:otherwise> - <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set> + <c:set var="cancelUrl">./projects/</c:set> </c:otherwise> </c:choose> <a href="${cancelUrl}" class="button">
--- a/src/main/webapp/WEB-INF/jsp/project-details.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/project-details.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,20 +25,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@page import="de.uapcore.lightpit.modules.ProjectsModule" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> <c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/> <jsp:useBean id="versions" type="java.util.List<de.uapcore.lightpit.entities.Version>" scope="request"/> <jsp:useBean id="issues" type="java.util.List<de.uapcore.lightpit.entities.Issue>" scope="request"/> <div id="tool-area"> - <a href="./${moduleInfo.modulePath}/versions/edit" class="button"><fmt:message key="button.version.create"/></a> - <a href="./${moduleInfo.modulePath}/issues/edit" class="button"><fmt:message key="button.issue.create"/></a> + <a href="./projects/versions/edit" class="button"><fmt:message key="button.version.create"/></a> + <a href="./projects/issues/edit" class="button"><fmt:message key="button.issue.create"/></a> </div> <c:if test="${not empty versions}"> @@ -53,7 +51,7 @@ <tbody> <c:forEach var="version" items="${versions}"> <tr class="nowrap"> - <td style="width: 2em;"><a href="./${moduleInfo.modulePath}/versions/edit?id=${version.id}">✎</a> + <td style="width: 2em;"><a href="./projects/versions/edit?id=${version.id}">✎</a> </td> <td><c:out value="${version.name}"/></td> <td><fmt:message key="version.status.${version.status}"/></td>
--- a/src/main/webapp/WEB-INF/jsp/project-form.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/project-form.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,16 +25,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> - <jsp:useBean id="project" type="de.uapcore.lightpit.entities.Project" scope="request"/> <jsp:useBean id="users" type="java.util.List<de.uapcore.lightpit.entities.User>" scope="request"/> -<form action="./${moduleInfo.modulePath}/commit" method="post"> +<form action="./projects/commit" method="post"> <table class="formtable"> <colgroup> <col> @@ -71,8 +68,9 @@ <tr> <td colspan="2"> <input type="hidden" name="id" value="${project.id}"/> - <a href="./${moduleInfo.modulePath}/" class="button"><fmt:message bundle="${lightpit_bundle}" - key="button.cancel"/></a> + <a href="./projects/" class="button"> + <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/> + </a> <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button> </td> </tr>
--- a/src/main/webapp/WEB-INF/jsp/projects.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/projects.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,12 +25,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@page import="de.uapcore.lightpit.modules.ProjectsModule" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> <c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/> <jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request"/> @@ -42,7 +40,7 @@ </c:if> <div id="tool-area"> - <a href="./${moduleInfo.modulePath}/edit" class="button"><fmt:message key="button.create"/></a> + <a href="./projects/edit" class="button"><fmt:message key="button.create"/></a> </div> <c:if test="${not empty projects}"> @@ -66,8 +64,8 @@ <tbody> <c:forEach var="project" items="${projects}"> <tr class="nowrap"> - <td style="width: 2em;"><a href="./${moduleInfo.modulePath}/edit?id=${project.id}">✎</a></td> - <td><a href="./${moduleInfo.modulePath}/view?pid=${project.id}"><c:out value="${project.name}"/></a> + <td style="width: 2em;"><a href="./projects/edit?id=${project.id}">✎</a></td> + <td><a href="./projects/view?pid=${project.id}"><c:out value="${project.name}"/></a> </td> <td><c:out value="${project.description}"/></td> <td>
--- a/src/main/webapp/WEB-INF/jsp/site.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/site.jsp Sat May 23 13:52:04 2020 +0200 @@ -52,8 +52,8 @@ <%-- Define an alias for the additional stylesheet --%> <c:set scope="page" var="extraCss" value="${requestScope[Constants.REQ_ATTR_STYLESHEET]}"/> -<%-- Define an alias for the module info --%> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> +<%-- Define an alias for the bundle name --%> +<c:set scope="page" var="bundleName" value="${requestScope[Constants.REQ_ATTR_RESOURCE_BUNDLE]}"/> <%-- Apply the session locale (should always be present, but check nevertheless) --%> <c:if test="${not empty sessionScope[Constants.SESSION_ATTR_LANGUAGE]}"> @@ -63,15 +63,15 @@ <%-- Selected project, if any --%> <c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/> +<%-- Load resource bundles --%> +<fmt:setBundle scope="request" basename="${bundleName}"/> +<fmt:setBundle scope="request" var="lightpit_bundle" basename="localization.lightpit"/> + <!DOCTYPE html> <html> <head> <base href="${baseHref}"> - <title>LightPIT - - <fmt:bundle basename="${moduleInfo.bundleBaseName}"> - <fmt:message key="pageTitle"/> - </fmt:bundle> - </title> + <title>LightPIT - <fmt:message key="pageTitle"/></title> <meta charset="UTF-8"> <c:if test="${not empty redirectLocation}"> <meta http-equiv="refresh" content="0; URL=${redirectLocation}"> @@ -96,8 +96,6 @@ </c:if> <div id="content-area"> <c:if test="${not empty contentPage}"> - <fmt:setBundle scope="request" basename="${moduleInfo.bundleBaseName}"/> - <fmt:setBundle scope="request" var="lightpit_bundle" basename="localization.lightpit"/> <c:import url="${contentPage}"/> </c:if> </div>
--- a/src/main/webapp/WEB-INF/jsp/user-form.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/user-form.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,15 +25,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> - <jsp:useBean id="user" type="de.uapcore.lightpit.entities.User" scope="request"/> -<form action="./${moduleInfo.modulePath}/commit" method="post"> +<form action="./teams/commit" method="post"> <table class="formtable"> <colgroup> <col> @@ -62,8 +59,9 @@ <tr> <td colspan="2"> <input type="hidden" name="userid" value="${user.id}"/> - <a href="./${moduleInfo.modulePath}/" class="button"><fmt:message bundle="${lightpit_bundle}" - key="button.cancel"/></a> + <a href="./teams/" class="button"> + <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/> + </a> <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button> </td> </tr>
--- a/src/main/webapp/WEB-INF/jsp/users.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/users.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,12 +25,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> - <jsp:useBean id="users" type="java.util.List<de.uapcore.lightpit.entities.User>" scope="request"/> <c:if test="${empty users}"> @@ -40,7 +37,7 @@ </c:if> <div id="tool-area"> - <a href="./${moduleInfo.modulePath}/edit" class="button"><fmt:message key="button.create"/></a> + <a href="./teams/edit" class="button"><fmt:message key="button.create"/></a> </div> <c:if test="${not empty users}"> @@ -54,7 +51,7 @@ <tbody> <c:forEach var="user" items="${users}"> <tr> - <td><a href="./${moduleInfo.modulePath}/edit?id=${user.id}">✎</a></td> + <td><a href="./teams/edit?id=${user.id}">✎</a></td> <td><c:out value="${user.displayname}"/></td> </tr> </c:forEach>
--- a/src/main/webapp/WEB-INF/jsp/version-form.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/version-form.jsp Sat May 23 13:52:04 2020 +0200 @@ -25,17 +25,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%@page pageEncoding="UTF-8" %> -<%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> - <jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" /> <jsp:useBean id="version" type="de.uapcore.lightpit.entities.Version" scope="request"/> <jsp:useBean id="versionStatusEnum" type="de.uapcore.lightpit.entities.VersionStatus[]" scope="request"/> -<form action="./${moduleInfo.modulePath}/versions/commit" method="post"> +<form action="./projects/versions/commit" method="post"> <table class="formtable" style="width: 35ch"> <colgroup> <col> @@ -83,10 +80,10 @@ <input type="hidden" name="id" value="${version.id}"/> <c:choose> <c:when test="${not empty version.project and version.project.id ge 0}"> - <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${version.project.id}</c:set> + <c:set var="cancelUrl">./projects/view?pid=${version.project.id}</c:set> </c:when> <c:otherwise> - <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set> + <c:set var="cancelUrl">./projects/</c:set> </c:otherwise> </c:choose> <a href="${cancelUrl}" class="button">
--- a/src/main/webapp/index.jsp Sat May 23 13:34:41 2020 +0200 +++ b/src/main/webapp/index.jsp Sat May 23 13:52:04 2020 +0200 @@ -24,9 +24,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> -<%@page import="de.uapcore.lightpit.Functions" %> -<%@ page import="de.uapcore.lightpit.modules.ProjectsModule" %> <% response.setStatus(response.SC_MOVED_TEMPORARILY); - response.setHeader("Location", Functions.modulePathOf(ProjectsModule.class)); + response.setHeader("Location", "/projects/"); %>