migrates constants and removes global functions

Fri, 06 Nov 2020 10:50:32 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 06 Nov 2020 10:50:32 +0100
changeset 158
4f912cd42876
parent 157
1e6f16fad3a5
child 159
86b5d8a1662f

migrates constants and removes global functions

src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/Constants.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/Functions.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/LanguageModule.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/Constants.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/site.jsp file | annotate | diff | comparison | revisions
     1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Thu Nov 05 13:37:48 2020 +0100
     1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Fri Nov 06 10:50:32 2020 +0100
     1.3 @@ -53,7 +53,7 @@
     1.4  
     1.5      private static final Logger LOG = LoggerFactory.getLogger(AbstractLightPITServlet.class);
     1.6  
     1.7 -    private static final String SITE_JSP = Functions.jspPath("site");
     1.8 +    private static final String SITE_JSP = jspPath("site");
     1.9  
    1.10  
    1.11      @FunctionalInterface
    1.12 @@ -102,7 +102,7 @@
    1.13       */
    1.14      private DataAccessObjects createDataAccessObjects(Connection connection) throws SQLException {
    1.15          final var df = (DataSourceProvider) getServletContext().getAttribute(DataSourceProvider.Companion.getSC_ATTR_NAME());
    1.16 -        if (df.getDialect() == DatabaseDialect.Postgres) {
    1.17 +        if (df.getDialect() == DataSourceProvider.Dialect.Postgres) {
    1.18              return new PGDataAccessObjects(connection);
    1.19          }
    1.20          throw new UnsupportedOperationException("Non-exhaustive if-else - this is a bug.");
    1.21 @@ -238,7 +238,7 @@
    1.22       * @see Constants#REQ_ATTR_CONTENT_PAGE
    1.23       */
    1.24      protected void setContentPage(HttpServletRequest req, String pageName) {
    1.25 -        req.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, Functions.jspPath(pageName));
    1.26 +        req.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, jspPath(pageName));
    1.27      }
    1.28  
    1.29      /**
    1.30 @@ -249,7 +249,7 @@
    1.31       * @see Constants#REQ_ATTR_NAVIGATION
    1.32       */
    1.33      protected void setNavigationMenu(HttpServletRequest req, String jspName) {
    1.34 -        req.setAttribute(Constants.REQ_ATTR_NAVIGATION, Functions.jspPath(jspName));
    1.35 +        req.setAttribute(Constants.REQ_ATTR_NAVIGATION, jspPath(jspName));
    1.36      }
    1.37  
    1.38      /**
    1.39 @@ -259,7 +259,7 @@
    1.40       */
    1.41      protected void setRedirectLocation(HttpServletRequest req, String location) {
    1.42          if (location.startsWith("./")) {
    1.43 -            location = location.replaceFirst("\\./", Functions.baseHref(req));
    1.44 +            location = location.replaceFirst("\\./", baseHref(req));
    1.45          }
    1.46          req.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, location);
    1.47      }
    1.48 @@ -277,7 +277,7 @@
    1.49       * @param stylesheet the name of the stylesheet
    1.50       */
    1.51      public void setStylesheet(HttpServletRequest req, String stylesheet) {
    1.52 -        req.setAttribute(Constants.REQ_ATTR_STYLESHEET, Functions.enforceExt(stylesheet, ".css"));
    1.53 +        req.setAttribute(Constants.REQ_ATTR_STYLESHEET, enforceExt(stylesheet, ".css"));
    1.54      }
    1.55  
    1.56      /**
    1.57 @@ -384,12 +384,32 @@
    1.58          req.getRequestDispatcher(SITE_JSP).forward(req, resp);
    1.59      }
    1.60  
    1.61 +    protected Optional<String[]> availableLanguages() {
    1.62 +        return Optional.ofNullable(getServletContext().getInitParameter(Constants.CTX_ATTR_LANGUAGES)).map((x) -> x.split("\\s*,\\s*"));
    1.63 +    }
    1.64 +
    1.65 +    private static String baseHref(HttpServletRequest req) {
    1.66 +        return String.format("%s://%s:%d%s/",
    1.67 +                req.getScheme(),
    1.68 +                req.getServerName(),
    1.69 +                req.getServerPort(),
    1.70 +                req.getContextPath());
    1.71 +    }
    1.72 +
    1.73 +    private static String enforceExt(String filename, String ext) {
    1.74 +        return filename.endsWith(ext) ? filename : filename + ext;
    1.75 +    }
    1.76 +
    1.77 +    private static String jspPath(String filename) {
    1.78 +        return enforceExt(Constants.JSP_PATH_PREFIX + filename, ".jsp");
    1.79 +    }
    1.80 +
    1.81      private void doProcess(HttpMethod method, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    1.82  
    1.83          // choose the requested language as session language (if available) or fall back to english, otherwise
    1.84          HttpSession session = req.getSession();
    1.85          if (session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) == null) {
    1.86 -            Optional<List<String>> availableLanguages = Functions.availableLanguages(getServletContext()).map(Arrays::asList);
    1.87 +            Optional<List<String>> availableLanguages = availableLanguages().map(Arrays::asList);
    1.88              Optional<Locale> reqLocale = Optional.of(req.getLocale());
    1.89              Locale sessionLocale = reqLocale.filter((rl) -> availableLanguages.map((al) -> al.contains(rl.getLanguage())).orElse(false)).orElse(Locale.ENGLISH);
    1.90              session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale);
    1.91 @@ -401,8 +421,8 @@
    1.92          }
    1.93  
    1.94          // set some internal request attributes
    1.95 -        final String fullPath = Functions.fullPath(req);
    1.96 -        req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req));
    1.97 +        final String fullPath = req.getServletPath() + Optional.ofNullable(req.getPathInfo()).orElse("");
    1.98 +        req.setAttribute(Constants.REQ_ATTR_BASE_HREF, baseHref(req));
    1.99          req.setAttribute(Constants.REQ_ATTR_PATH, fullPath);
   1.100          req.setAttribute(Constants.REQ_ATTR_RESOURCE_BUNDLE, getResourceBundleName());
   1.101  
     2.1 --- a/src/main/java/de/uapcore/lightpit/Constants.java	Thu Nov 05 13:37:48 2020 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,115 +0,0 @@
     2.4 -/*
     2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 - *
     2.7 - * Copyright 2018 Mike Becker. All rights reserved.
     2.8 - *
     2.9 - * Redistribution and use in source and binary forms, with or without
    2.10 - * modification, are permitted provided that the following conditions are met:
    2.11 - *
    2.12 - *   1. Redistributions of source code must retain the above copyright
    2.13 - *      notice, this list of conditions and the following disclaimer.
    2.14 - *
    2.15 - *   2. Redistributions in binary form must reproduce the above copyright
    2.16 - *      notice, this list of conditions and the following disclaimer in the
    2.17 - *      documentation and/or other materials provided with the distribution.
    2.18 - *
    2.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.29 - * POSSIBILITY OF SUCH DAMAGE.
    2.30 - *
    2.31 - */
    2.32 -package de.uapcore.lightpit;
    2.33 -
    2.34 -import static de.uapcore.lightpit.Functions.fqn;
    2.35 -
    2.36 -/**
    2.37 - * Contains all non-local scope constants used by the this application.
    2.38 - * <p>
    2.39 - * Constants with (class) local scope are defined in their respective classes.
    2.40 - */
    2.41 -public final class Constants {
    2.42 -    /**
    2.43 -     * The path where the JSP files reside.
    2.44 -     */
    2.45 -    public static final String JSP_PATH_PREFIX = "/WEB-INF/jsp/";
    2.46 -
    2.47 -    /**
    2.48 -     * The name of the generic JSP page that is displayed after a successful commit.
    2.49 -     */
    2.50 -    public static final String JSP_COMMIT_SUCCESSFUL = "commit-successful";
    2.51 -
    2.52 -    /**
    2.53 -     * Name for the context parameter specifying the available languages.
    2.54 -     */
    2.55 -    public static final String CTX_ATTR_LANGUAGES = "available-languages";
    2.56 -
    2.57 -    /**
    2.58 -     * Name for the context parameter optionally specifying a database schema.
    2.59 -     */
    2.60 -    public static final String CTX_ATTR_DB_SCHEMA = "db-schema";
    2.61 -
    2.62 -    /**
    2.63 -     * Name for the context parameter optionally specifying a database dialect.
    2.64 -     */
    2.65 -    public static final String CTX_ATTR_DB_DIALECT = "db-dialect";
    2.66 -
    2.67 -    /**
    2.68 -     * Key for the request attribute containing the resource bundle name.
    2.69 -     */
    2.70 -    public static final String REQ_ATTR_RESOURCE_BUNDLE = fqn(AbstractLightPITServlet.class, "bundleName");
    2.71 -
    2.72 -    /**
    2.73 -     * Key for the request attribute containing the optional navigation menu jsp.
    2.74 -     */
    2.75 -    public static final String REQ_ATTR_NAVIGATION = fqn(AbstractLightPITServlet.class, "navMenu");
    2.76 -
    2.77 -    /**
    2.78 -     * Key for the request attribute containing the base href.
    2.79 -     */
    2.80 -    public static final String REQ_ATTR_BASE_HREF = fqn(AbstractLightPITServlet.class, "base_href");
    2.81 -
    2.82 -    /**
    2.83 -     * Key for the request attribute containing the full path information (servlet path + path info).
    2.84 -     */
    2.85 -    public static final String REQ_ATTR_PATH = fqn(AbstractLightPITServlet.class, "path");
    2.86 -
    2.87 -    /**
    2.88 -     * Key for the name of the page which should be rendered.
    2.89 -     */
    2.90 -    public static final String REQ_ATTR_CONTENT_PAGE = fqn(AbstractLightPITServlet.class, "content-page");
    2.91 -
    2.92 -    /**
    2.93 -     * Key for the view model object (the type depends on the rendered site).
    2.94 -     */
    2.95 -    public static final String REQ_ATTR_VIEWMODEL = "viewmodel";
    2.96 -
    2.97 -    /**
    2.98 -     * Key for the name of the additional stylesheet used by a module.
    2.99 -     */
   2.100 -    public static final String REQ_ATTR_STYLESHEET = fqn(AbstractLightPITServlet.class, "extraCss");
   2.101 -
   2.102 -    /**
   2.103 -     * Key for a location the page shall redirect to.
   2.104 -     * Will be used in a meta element.
   2.105 -     */
   2.106 -    public static final String REQ_ATTR_REDIRECT_LOCATION = fqn(AbstractLightPITServlet.class, "redirectLocation");
   2.107 -
   2.108 -    /**
   2.109 -     * Key for the current language selection within the session.
   2.110 -     */
   2.111 -    public static final String SESSION_ATTR_LANGUAGE = fqn(AbstractLightPITServlet.class, "language");
   2.112 -
   2.113 -    /**
   2.114 -     * This class is not instantiatable.
   2.115 -     */
   2.116 -    private Constants() {
   2.117 -    }
   2.118 -}
     3.1 --- a/src/main/java/de/uapcore/lightpit/Functions.java	Thu Nov 05 13:37:48 2020 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,90 +0,0 @@
     3.4 -/*
     3.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 - *
     3.7 - * Copyright 2018 Mike Becker. All rights reserved.
     3.8 - *
     3.9 - * Redistribution and use in source and binary forms, with or without
    3.10 - * modification, are permitted provided that the following conditions are met:
    3.11 - *
    3.12 - *   1. Redistributions of source code must retain the above copyright
    3.13 - *      notice, this list of conditions and the following disclaimer.
    3.14 - *
    3.15 - *   2. Redistributions in binary form must reproduce the above copyright
    3.16 - *      notice, this list of conditions and the following disclaimer in the
    3.17 - *      documentation and/or other materials provided with the distribution.
    3.18 - *
    3.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    3.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    3.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    3.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    3.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    3.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    3.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    3.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    3.29 - * POSSIBILITY OF SUCH DAMAGE.
    3.30 - *
    3.31 - */
    3.32 -package de.uapcore.lightpit;
    3.33 -
    3.34 -import org.slf4j.Logger;
    3.35 -import org.slf4j.LoggerFactory;
    3.36 -
    3.37 -import javax.servlet.ServletContext;
    3.38 -import javax.servlet.http.HttpServletRequest;
    3.39 -import java.util.Optional;
    3.40 -
    3.41 -/**
    3.42 - * Contains common static functions.
    3.43 - */
    3.44 -public final class Functions {
    3.45 -
    3.46 -    private static final Logger LOG = LoggerFactory.getLogger(Functions.class);
    3.47 -
    3.48 -    public static Optional<String[]> availableLanguages(ServletContext ctx) {
    3.49 -        return Optional.ofNullable(ctx.getInitParameter(Constants.CTX_ATTR_LANGUAGES)).map((x) -> x.split("\\s*,\\s*"));
    3.50 -    }
    3.51 -
    3.52 -    public static String enforceExt(String filename, String ext) {
    3.53 -        return filename.endsWith(ext) ? filename : filename + ext;
    3.54 -    }
    3.55 -
    3.56 -    public static String jspPath(String filename) {
    3.57 -        return enforceExt(Constants.JSP_PATH_PREFIX + filename, ".jsp");
    3.58 -    }
    3.59 -
    3.60 -    public static String fqn(String base, String name) {
    3.61 -        return base + "." + name;
    3.62 -    }
    3.63 -
    3.64 -    public static String fqn(Class<?> clazz, String name) {
    3.65 -        return fqn(clazz.getName(), name);
    3.66 -    }
    3.67 -
    3.68 -    public static String baseHref(HttpServletRequest req) {
    3.69 -        return String.format("%s://%s:%d%s/",
    3.70 -                req.getScheme(),
    3.71 -                req.getServerName(),
    3.72 -                req.getServerPort(),
    3.73 -                req.getContextPath());
    3.74 -    }
    3.75 -
    3.76 -    public static String fullPath(HttpServletRequest req) {
    3.77 -        return req.getServletPath() + Optional.ofNullable(req.getPathInfo()).orElse("");
    3.78 -    }
    3.79 -
    3.80 -    public static int parseIntOrZero(String str) {
    3.81 -        try {
    3.82 -            return Integer.parseInt(str);
    3.83 -        } catch (NumberFormatException ex) {
    3.84 -            return 0;
    3.85 -        }
    3.86 -    }
    3.87 -
    3.88 -    /**
    3.89 -     * This class is not instantiatable.
    3.90 -     */
    3.91 -    private Functions() {
    3.92 -    }
    3.93 -}
     4.1 --- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java	Thu Nov 05 13:37:48 2020 +0100
     4.2 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java	Fri Nov 06 10:50:32 2020 +0100
     4.3 @@ -28,7 +28,10 @@
     4.4   */
     4.5  package de.uapcore.lightpit.modules;
     4.6  
     4.7 -import de.uapcore.lightpit.*;
     4.8 +import de.uapcore.lightpit.AbstractLightPITServlet;
     4.9 +import de.uapcore.lightpit.Constants;
    4.10 +import de.uapcore.lightpit.HttpMethod;
    4.11 +import de.uapcore.lightpit.RequestMapping;
    4.12  import de.uapcore.lightpit.viewmodel.LanguageView;
    4.13  import org.slf4j.Logger;
    4.14  import org.slf4j.LoggerFactory;
    4.15 @@ -59,7 +62,7 @@
    4.16      public void init() throws ServletException {
    4.17          super.init();
    4.18  
    4.19 -        Optional<String[]> langs = Functions.availableLanguages(getServletContext());
    4.20 +        Optional<String[]> langs = availableLanguages();
    4.21          if (langs.isPresent()) {
    4.22              for (String lang : langs.get()) {
    4.23                  try {
     5.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Thu Nov 05 13:37:48 2020 +0100
     5.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Fri Nov 06 10:50:32 2020 +0100
     5.3 @@ -64,6 +64,14 @@
     5.4          return "localization.projects";
     5.5      }
     5.6  
     5.7 +    private static int parseIntOrZero(String str) {
     5.8 +        try {
     5.9 +            return Integer.parseInt(str);
    5.10 +        } catch (NumberFormatException ex) {
    5.11 +            return 0;
    5.12 +        }
    5.13 +    }
    5.14 +
    5.15      private void populate(ProjectView viewModel, PathParameters pathParameters, DataAccessObjects dao) throws SQLException {
    5.16          final var projectDao = dao.getProjectDao();
    5.17          final var versionDao = dao.getVersionDao();
    5.18 @@ -439,7 +447,7 @@
    5.19          }
    5.20  
    5.21          final var issueDao = dao.getIssueDao();
    5.22 -        final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue")));
    5.23 +        final var issue = issueDao.find(parseIntOrZero(pathParameters.get("issue")));
    5.24          if (issue == null) {
    5.25              resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    5.26              return;
    5.27 @@ -465,7 +473,7 @@
    5.28          }
    5.29  
    5.30          final var issueDao = dao.getIssueDao();
    5.31 -        final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue")));
    5.32 +        final var issue = issueDao.find(parseIntOrZero(pathParameters.get("issue")));
    5.33          if (issue == null) {
    5.34              resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    5.35              return;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/main/kotlin/de/uapcore/lightpit/Constants.kt	Fri Nov 06 10:50:32 2020 +0100
     6.3 @@ -0,0 +1,99 @@
     6.4 +/*
     6.5 + * Copyright 2020 Mike Becker. All rights reserved.
     6.6 + *
     6.7 + * Redistribution and use in source and binary forms, with or without
     6.8 + * modification, are permitted provided that the following conditions are met:
     6.9 + *
    6.10 + * 1. Redistributions of source code must retain the above copyright
    6.11 + * notice, this list of conditions and the following disclaimer.
    6.12 + *
    6.13 + * 2. Redistributions in binary form must reproduce the above copyright
    6.14 + * notice, this list of conditions and the following disclaimer in the
    6.15 + * documentation and/or other materials provided with the distribution.
    6.16 + *
    6.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    6.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    6.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    6.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    6.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    6.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    6.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    6.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    6.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    6.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    6.27 + */
    6.28 +
    6.29 +package de.uapcore.lightpit
    6.30 +
    6.31 +object Constants {
    6.32 +    /**
    6.33 +     * The path where the JSP files reside.
    6.34 +     */
    6.35 +    const val JSP_PATH_PREFIX = "/WEB-INF/jsp/"
    6.36 +
    6.37 +    /**
    6.38 +     * The name of the generic JSP page that is displayed after a successful commit.
    6.39 +     */
    6.40 +    const val JSP_COMMIT_SUCCESSFUL = "commit-successful"
    6.41 +
    6.42 +    /**
    6.43 +     * Name for the context parameter specifying the available languages.
    6.44 +     */
    6.45 +    const val CTX_ATTR_LANGUAGES = "available-languages"
    6.46 +
    6.47 +    /**
    6.48 +     * Name for the context parameter optionally specifying a database schema.
    6.49 +     */
    6.50 +    const val CTX_ATTR_DB_SCHEMA = "db-schema"
    6.51 +
    6.52 +    /**
    6.53 +     * Name for the context parameter optionally specifying a database dialect.
    6.54 +     */
    6.55 +    const val CTX_ATTR_DB_DIALECT = "db-dialect"
    6.56 +
    6.57 +    /**
    6.58 +     * Key for the request attribute containing the resource bundle name.
    6.59 +     */
    6.60 +    const val REQ_ATTR_RESOURCE_BUNDLE = "bundleName"
    6.61 +
    6.62 +    /**
    6.63 +     * Key for the request attribute containing the optional navigation menu jsp.
    6.64 +     */
    6.65 +    const val REQ_ATTR_NAVIGATION = "navMenu"
    6.66 +
    6.67 +    /**
    6.68 +     * Key for the request attribute containing the base href.
    6.69 +     */
    6.70 +    const val REQ_ATTR_BASE_HREF = "base_href"
    6.71 +
    6.72 +    /**
    6.73 +     * Key for the request attribute containing the full path information (servlet path + path info).
    6.74 +     */
    6.75 +    const val REQ_ATTR_PATH = "requestPath"
    6.76 +
    6.77 +    /**
    6.78 +     * Key for the name of the page which should be rendered.
    6.79 +     */
    6.80 +    const val REQ_ATTR_CONTENT_PAGE = "contentPage"
    6.81 +
    6.82 +    /**
    6.83 +     * Key for the view model object (the type depends on the rendered site).
    6.84 +     */
    6.85 +    const val REQ_ATTR_VIEWMODEL = "viewmodel"
    6.86 +
    6.87 +    /**
    6.88 +     * Key for the name of the additional stylesheet used by a module.
    6.89 +     */
    6.90 +    const val REQ_ATTR_STYLESHEET = "extraCss"
    6.91 +
    6.92 +    /**
    6.93 +     * Key for a location the page shall redirect to.
    6.94 +     * Will be used in a meta element.
    6.95 +     */
    6.96 +    const val REQ_ATTR_REDIRECT_LOCATION = "redirectLocation"
    6.97 +
    6.98 +    /**
    6.99 +     * Key for the current language selection within the session.
   6.100 +     */
   6.101 +    const val SESSION_ATTR_LANGUAGE = "language"
   6.102 +}
     7.1 --- a/src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt	Thu Nov 05 13:37:48 2020 +0100
     7.2 +++ b/src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt	Fri Nov 06 10:50:32 2020 +0100
     7.3 @@ -34,23 +34,23 @@
     7.4  import javax.servlet.annotation.WebListener
     7.5  import javax.sql.DataSource
     7.6  
     7.7 -enum class DatabaseDialect {
     7.8 -    Postgres
     7.9 -}
    7.10 -
    7.11  /**
    7.12   * Provides access to the database.
    7.13   */
    7.14  @WebListener
    7.15  class DataSourceProvider : ServletContextListener, LoggingTrait {
    7.16  
    7.17 +    enum class Dialect {
    7.18 +        Postgres
    7.19 +    }
    7.20 +
    7.21      /**
    7.22       * The database dialect to use.
    7.23       * May be overridden by context parameter.
    7.24       *
    7.25       * @see Constants.CTX_ATTR_DB_DIALECT
    7.26       */
    7.27 -    var dialect = DatabaseDialect.Postgres; private set
    7.28 +    var dialect = Dialect.Postgres; private set
    7.29  
    7.30      /**
    7.31       * The data source, if available.
    7.32 @@ -130,7 +130,7 @@
    7.33          val dbSchema = sc.getInitParameter(Constants.CTX_ATTR_DB_SCHEMA) ?: DB_DEFAULT_SCHEMA
    7.34          sc.getInitParameter(Constants.CTX_ATTR_DB_DIALECT)?.let {dbDialect ->
    7.35              try {
    7.36 -                dialect = DatabaseDialect.valueOf(dbDialect)
    7.37 +                dialect = Dialect.valueOf(dbDialect)
    7.38              } catch (ex: IllegalArgumentException) {
    7.39                  logger().error(
    7.40                      "Unknown or unsupported database dialect {}. Defaulting to {}.",
     8.1 --- a/src/main/webapp/WEB-INF/jsp/site.jsp	Thu Nov 05 13:37:48 2020 +0100
     8.2 +++ b/src/main/webapp/WEB-INF/jsp/site.jsp	Fri Nov 06 10:50:32 2020 +0100
     8.3 @@ -1,7 +1,7 @@
     8.4  <%-- 
     8.5  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6  
     8.7 -Copyright 2018 Mike Becker. All rights reserved.
     8.8 +Copyright 2020 Mike Becker. All rights reserved.
     8.9  
    8.10  Redistribution and use in source and binary forms, with or without
    8.11  modification, are permitted provided that the following conditions are met:

mercurial