# HG changeset patch # User Mike Becker # Date 1511891953 -3600 # Node ID 598670d5b0b891fe3fb1fa998c9e5fec48a221e8 # Parent da61a1646ebab04498bb4bf83e2347ff61e417e9 core functionality should also use the modules system, changed the code structure accordingly diff -r da61a1646eba -r 598670d5b0b8 .hgignore --- a/.hgignore Sun Nov 26 18:09:23 2017 +0100 +++ b/.hgignore Tue Nov 28 18:59:13 2017 +0100 @@ -1,6 +1,7 @@ syntax: regexp ^nbproject/private/ ^build/ +^dist/ \.orig\..*$ \.orig$ \.chg\..*$ diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/Constants.java --- a/src/java/de/uapcore/lightpit/Constants.java Sun Nov 26 18:09:23 2017 +0100 +++ b/src/java/de/uapcore/lightpit/Constants.java Tue Nov 28 18:59:13 2017 +0100 @@ -32,5 +32,7 @@ * Contains all constants used by the this application. */ public abstract class Constants { + public static final String HOME_NODE = "/home/"; + public static final String JSP_PATH_PREFIX = "/WEB-INF/view/"; } diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/Functions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/uapcore/lightpit/Functions.java Tue Nov 28 18:59:13 2017 +0100 @@ -0,0 +1,39 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, 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. + * + */ +package de.uapcore.lightpit; + +/** + * Contains common static functions. + */ +public class Functions { + + public static String jspPath(String filename) { + return Constants.JSP_PATH_PREFIX + filename; + } +} diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/HomeServlet.java --- a/src/java/de/uapcore/lightpit/HomeServlet.java Sun Nov 26 18:09:23 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2017 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, 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. - * - */ -package de.uapcore.lightpit; - -import java.io.IOException; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Entry point for the application. - */ -@WebServlet( - name = "HomeServlet", - urlPatterns = {"/", "/home"} -) -public class HomeServlet extends HttpServlet { - - private String jspPath(String filename) { - return Constants.JSP_PATH_PREFIX + filename; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - ServletContext ctx = getServletContext(); - RequestDispatcher dispatcher = ctx.getRequestDispatcher(jspPath("home.jsp")); - dispatcher.forward(req, resp); - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.sendError(HttpServletResponse.SC_FORBIDDEN, - "POST method not allowed for this Servlet."); - } - - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ - @Override - public String getServletInfo() { - return "Processes requests for the LightPIT start page."; - } -} diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/LightPITModule.java --- a/src/java/de/uapcore/lightpit/LightPITModule.java Sun Nov 26 18:09:23 2017 +0100 +++ b/src/java/de/uapcore/lightpit/LightPITModule.java Tue Nov 28 18:59:13 2017 +0100 @@ -28,17 +28,34 @@ */ package de.uapcore.lightpit; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import javax.servlet.annotation.WebServlet; /** * Contains information about a LightPIT module. + * + * This annotation is typically used to annotate the {@link WebServlet} which + * implements the module's functionality. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface LightPITModule { + /** + * Base name of the module specific resource bundle. + * @return a base name suitable for the JSTL tag 'setBundle'. + */ + String bundleBaseName(); + /** + * An array of required modules, identified by the string representation of + * their class names. + * @return an array of class names of required modules + */ + String[] requires() default {}; } diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/LightPITServlet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/uapcore/lightpit/LightPITServlet.java Tue Nov 28 18:59:13 2017 +0100 @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, 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. + * + */ +package de.uapcore.lightpit; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * A special implementation of a HTTPServlet which is focused on implementing + * the necessary functionality for {@link LightPITModule}s. + */ +public class LightPITServlet extends HttpServlet { + + @Override + protected final void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.getWriter().println("It works!"); + } + + @Override + protected final void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + } + +} diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/ModuleManager.java --- a/src/java/de/uapcore/lightpit/ModuleManager.java Sun Nov 26 18:09:23 2017 +0100 +++ b/src/java/de/uapcore/lightpit/ModuleManager.java Tue Nov 28 18:59:13 2017 +0100 @@ -30,10 +30,10 @@ import java.util.logging.Level; import java.util.logging.Logger; +import javax.servlet.Registration; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import javax.servlet.ServletRegistration; import javax.servlet.annotation.WebListener; /** @@ -66,20 +66,34 @@ unloadAll(); } - private boolean isRegisteredAsModule(ServletRegistration sr) { + private boolean isRegisteredAsModule(Registration reg) { try { - final Class scclass = Class.forName(sr.getClassName()); - return scclass.isAnnotationPresent(LightPITModule.class); + final Class scclass = Class.forName(reg.getClassName()); + + final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass); + final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class); + + if (lpservlet && !lpmodule) { + LOG.log(Level.WARNING, + "Servlet is a LightPITServlet but is missing the module annotation: {0}", + reg.getClassName()); + } else if (!lpservlet && lpmodule) { + LOG.log(Level.WARNING, + "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {0}", + reg.getClassName()); + } + + return lpservlet && lpmodule; } catch (ClassNotFoundException ex) { LOG.log(Level.SEVERE, "Servlet registration refers to a class which cannot be found by the class loader: {0}", - sr.getClassName()); + reg.getClassName()); return false; } } - private void handleServletRegistration(String name, ServletRegistration sr) { - if (isRegisteredAsModule(sr)) { + private void handleServletRegistration(String name, Registration reg) { + if (isRegisteredAsModule(reg)) { LOG.log(Level.CONFIG, "Module detected: {0}", name); } else { LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name); diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/modules/HomeModule.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/uapcore/lightpit/modules/HomeModule.java Tue Nov 28 18:59:13 2017 +0100 @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, 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. + * + */ +package de.uapcore.lightpit.modules; + +import de.uapcore.lightpit.Constants; +import de.uapcore.lightpit.LightPITModule; +import de.uapcore.lightpit.LightPITServlet; +import javax.servlet.annotation.WebServlet; + +/** + * Entry point for the application. + */ +@LightPITModule( + bundleBaseName = "de.uapcore.lightpit.resources.home_localization" +) +@WebServlet( + name = "HomeModule", + urlPatterns = Constants.HOME_NODE+"*" +) +public class HomeModule extends LightPITServlet { + +} diff -r da61a1646eba -r 598670d5b0b8 src/java/de/uapcore/lightpit/modules/VersionsModule.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/uapcore/lightpit/modules/VersionsModule.java Tue Nov 28 18:59:13 2017 +0100 @@ -0,0 +1,45 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, 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. + * + */ +package de.uapcore.lightpit.modules; + +import de.uapcore.lightpit.LightPITModule; +import de.uapcore.lightpit.LightPITServlet; +import javax.servlet.annotation.WebServlet; + + +@LightPITModule( + bundleBaseName = "de.uapcore.lightpit.resources.versions_localization" +) +@WebServlet( + name = "VersionsModule", + urlPatterns = "/versions/*" +) +public class VersionsModule extends LightPITServlet { + +} diff -r da61a1646eba -r 598670d5b0b8 web/index.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/index.jsp Tue Nov 28 18:59:13 2017 +0100 @@ -0,0 +1,31 @@ +<%-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2017 Mike Becker. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +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.Constants" %> +<% +response.setStatus(response.SC_MOVED_TEMPORARILY); +response.setHeader("Location", "."+Constants.HOME_NODE); +%>