Skip to content

Commit

Permalink
Jakarta support (as java21 version) #22 :: fix compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
jflute committed Jul 25, 2024
1 parent 3a0822f commit 4aedd94
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<lastaflute.version>2.0.0-B-SNAPSHOT</lastaflute.version> <!-- about one year old (from now) -->
<thymeleaf.version>3.0.15.RELEASE</thymeleaf.version>
<thymeleaf.version>3.1.1.RELEASE</thymeleaf.version>
<servlet.version>6.0.0</servlet.version>
<utflute.version>0.9.6</utflute.version>
<junit.version>4.8.2</junit.version> <!-- latest version without hamcrest -->
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/org/lastaflute/thymeleaf/ThymeleafHtmlRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

// -----------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -160,17 +164,24 @@ 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());
resolver.setCacheable(isCacheable());
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() {
Expand Down

0 comments on commit 4aedd94

Please sign in to comment.