Allow encoding to be set with a Charset in FreeMarker support

Closes gh-33102
This commit is contained in:
Sam Brannen
2024-06-26 16:18:09 +02:00
parent 4e13a69948
commit 73c0783df1
6 changed files with 59 additions and 15 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.ui.freemarker;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -146,6 +147,7 @@ public class FreeMarkerConfigurationFactory {
* <p>Note that the encoding is not used for template rendering. Instead, an
* explicit encoding must be specified for the rendering process &mdash; for
* example, via Spring's {@code FreeMarkerView} or {@code FreeMarkerViewResolver}.
* @see #setDefaultEncoding(Charset)
* @see freemarker.template.Configuration#setDefaultEncoding
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerView#setEncoding
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerView#setContentType
@@ -155,6 +157,18 @@ public class FreeMarkerConfigurationFactory {
this.defaultEncoding = defaultEncoding;
}
/**
* Set the default encoding for the FreeMarker {@link Configuration}, which
* is used to decode byte sequences to character sequences when reading template
* files.
* <p>See {@link #setDefaultEncoding(String)} for details.
* @since 6.2
* @see java.nio.charset.StandardCharsets
*/
public void setDefaultEncoding(Charset defaultEncoding) {
setDefaultEncoding(defaultEncoding.name());
}
/**
* Set a List of {@link TemplateLoader TemplateLoaders} that will be used to
* search for templates.