com.github.resource4j.thymeleaf3.Resource4jTemplateResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resource4j-thymeleaf3 Show documentation
Show all versions of resource4j-thymeleaf3 Show documentation
Integration of Resource4J with Thymeleaf 3.x
package com.github.resource4j.thymeleaf3;
import com.github.resource4j.resources.Resources;
import org.thymeleaf.IEngineConfiguration;
import org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver;
import org.thymeleaf.templateresource.ITemplateResource;
import org.thymeleaf.templateresource.StringTemplateResource;
import java.util.Locale;
import java.util.Map;
import static com.github.resource4j.objects.parsers.ResourceParsers.string;
public class Resource4jTemplateResolver extends AbstractConfigurableTemplateResolver {
private Resources resources;
public Resource4jTemplateResolver(Resources resources) {
this.resources = resources;
}
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration,
String ownerTemplate, String template,
String resourceName,
String characterEncoding,
Map templateResolutionAttributes) {
Locale locale = (Locale) templateResolutionAttributes.get("locale");
String string = resources.contentOf(resourceName, locale).parsedTo(string()).asIs();
return new StringTemplateResource(string);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy