From 4aedd9488ae488bcbed39e12e7d405a6e5fb56e8 Mon Sep 17 00:00:00 2001 From: jflute Date: Thu, 25 Jul 2024 22:06:46 +0900 Subject: [PATCH] Jakarta support (as java21 version) #22 :: fix compile error --- pom.xml | 2 +- .../thymeleaf/ThymeleafHtmlRenderer.java | 28 +++++++++++++------ .../thymeleaf/ThymeleafRenderingProvider.java | 19 ++++++++++--- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 0bdf508..900b251 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 2.0.0-B-SNAPSHOT - 3.0.15.RELEASE + 3.1.1.RELEASE 6.0.0 0.9.6 4.8.2 diff --git a/src/main/java/org/lastaflute/thymeleaf/ThymeleafHtmlRenderer.java b/src/main/java/org/lastaflute/thymeleaf/ThymeleafHtmlRenderer.java index 42dc546..032d7b0 100644 --- a/src/main/java/org/lastaflute/thymeleaf/ThymeleafHtmlRenderer.java +++ b/src/main/java/org/lastaflute/thymeleaf/ThymeleafHtmlRenderer.java @@ -22,11 +22,6 @@ import java.util.Locale; import java.util.Set; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.dbflute.helper.message.ExceptionMessageBuilder; import org.dbflute.util.Srl; import org.lastaflute.core.message.UserMessages; @@ -48,6 +43,13 @@ import org.slf4j.LoggerFactory; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; +import org.thymeleaf.web.servlet.IServletWebExchange; +import org.thymeleaf.web.servlet.JakartaServletWebApplication; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * @author jflute @@ -121,12 +123,22 @@ protected void showRendering(NextJourney journey) { // ----------------------------------------------------- // Template Context // ---------------- + // #jakarta the way to create web context has been changed by jflute (2024/07/25) protected WebContext createTemplateContext(RequestManager requestManager) { + final IServletWebExchange exchange = createWebExchange(requestManager); + return newWebContext(exchange, requestManager.getUserLocale()); + } + + protected IServletWebExchange createWebExchange(RequestManager requestManager) { + final ServletContext servletContext = requestManager.getServletContext(); final HttpServletRequest request = requestManager.getRequest(); final HttpServletResponse response = requestManager.getResponseManager().getResponse(); - final ServletContext servletContext = request.getServletContext(); - final Locale locale = requestManager.getUserLocale(); - return new WebContext(request, response, servletContext, locale); + final JakartaServletWebApplication application = JakartaServletWebApplication.buildApplication(servletContext); + return application.buildExchange(request, response); + } + + protected WebContext newWebContext(IServletWebExchange exchange, Locale locale) { + return new WebContext(exchange, locale); } // ----------------------------------------------------- diff --git a/src/main/java/org/lastaflute/thymeleaf/ThymeleafRenderingProvider.java b/src/main/java/org/lastaflute/thymeleaf/ThymeleafRenderingProvider.java index c792773..b760db2 100644 --- a/src/main/java/org/lastaflute/thymeleaf/ThymeleafRenderingProvider.java +++ b/src/main/java/org/lastaflute/thymeleaf/ThymeleafRenderingProvider.java @@ -31,7 +31,11 @@ import org.thymeleaf.messageresolver.StandardMessageResolver; import org.thymeleaf.standard.StandardDialect; import org.thymeleaf.templateresolver.ITemplateResolver; -import org.thymeleaf.templateresolver.ServletContextTemplateResolver; +import org.thymeleaf.templateresolver.WebApplicationTemplateResolver; +import org.thymeleaf.web.IWebApplication; +import org.thymeleaf.web.servlet.JakartaServletWebApplication; + +import jakarta.servlet.ServletContext; /** * Thymeleaf rendering provider of Lastaflute. @@ -160,8 +164,9 @@ protected StandardDialect findStandardDialect(TemplateEngine engine) { // ----------------------------------------------------- // Template Resolver // ----------------- + // #jakarta the way to create template resolver has been changed by jflute (2024/07/25) protected ITemplateResolver createTemplateResolver() { - final ServletContextTemplateResolver resolver = newServletContextTemplateResolver(); + final WebApplicationTemplateResolver resolver = createWebApplicationTemplateResolver(); resolver.setPrefix(getHtmlViewPrefix()); resolver.setTemplateMode(getTemplateMode()); resolver.setCharacterEncoding(getEncoding()); @@ -169,8 +174,14 @@ protected ITemplateResolver createTemplateResolver() { return resolver; } - protected ServletContextTemplateResolver newServletContextTemplateResolver() { - return new ServletContextTemplateResolver(LaServletContextUtil.getServletContext()); + protected WebApplicationTemplateResolver createWebApplicationTemplateResolver() { + final ServletContext servletContext = LaServletContextUtil.getServletContext(); + final JakartaServletWebApplication webApplication = JakartaServletWebApplication.buildApplication(servletContext); + return newWebApplicationTemplateResolver(webApplication); + } + + protected WebApplicationTemplateResolver newWebApplicationTemplateResolver(IWebApplication webApplication) { + return new WebApplicationTemplateResolver(webApplication); } protected String getHtmlViewPrefix() {