mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -65,7 +65,7 @@ public class JteEngine implements TemplateEngine {
|
|||||||
// --------------------------------------------------------------------------------- Constructor end
|
// --------------------------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateEngine init(TemplateConfig config) {
|
public TemplateEngine init(final TemplateConfig config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
@@ -74,15 +74,15 @@ public class JteEngine implements TemplateEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Template getTemplate(String resource) {
|
public Template getTemplate(final String resource) {
|
||||||
if (TemplateConfig.ResourceMode.STRING.equals(config.getResourceMode())) {
|
if (TemplateConfig.ResourceMode.STRING.equals(config.getResourceMode())) {
|
||||||
if (!StrUtil.endWithAny(config.getPath(), ".jte", ".kte")) {
|
if (!StrUtil.endWithAny(config.getPath(), ".jte", ".kte")) {
|
||||||
throw new RuntimeException("路径path需以.jte/.kte结尾");
|
throw new RuntimeException("path need to end with '.jte' or '.kte'");
|
||||||
}
|
}
|
||||||
createEngine(new SimpleStringCodeResolver(MapUtil.of(config.getPath(), resource)), contentType);
|
createEngine(new SimpleStringCodeResolver(MapUtil.of(config.getPath(), resource)), contentType);
|
||||||
return new JteTemplate(engine, config.getPath());
|
return new JteTemplate(engine, config.getPath(), config.getCharset());
|
||||||
} else {
|
} else {
|
||||||
return new JteTemplate(engine, resource);
|
return new JteTemplate(engine, resource, config.getCharset());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public class JteEngine implements TemplateEngine {
|
|||||||
* @param codeResolver CodeResolver
|
* @param codeResolver CodeResolver
|
||||||
* @param contentType ContentType
|
* @param contentType ContentType
|
||||||
*/
|
*/
|
||||||
private void createEngine(CodeResolver codeResolver, ContentType contentType) {
|
private void createEngine(final CodeResolver codeResolver, final ContentType contentType) {
|
||||||
this.engine = gg.jte.TemplateEngine.create(codeResolver, contentType);
|
this.engine = gg.jte.TemplateEngine.create(codeResolver, contentType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ import org.dromara.hutool.core.io.file.FileUtil;
|
|||||||
import org.dromara.hutool.extra.template.Template;
|
import org.dromara.hutool.extra.template.Template;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,20 +33,29 @@ public class JteTemplate implements Template, Serializable {
|
|||||||
|
|
||||||
private final TemplateEngine templateEngine;
|
private final TemplateEngine templateEngine;
|
||||||
private final String template;
|
private final String template;
|
||||||
|
private final Charset charset;
|
||||||
|
|
||||||
public JteTemplate(TemplateEngine engine, String template) {
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param engine jet引擎
|
||||||
|
* @param template 模板
|
||||||
|
* @param charset 输出编码
|
||||||
|
*/
|
||||||
|
public JteTemplate(final TemplateEngine engine, final String template, final Charset charset) {
|
||||||
this.templateEngine = engine;
|
this.templateEngine = engine;
|
||||||
this.template = template;
|
this.template = template;
|
||||||
|
this.charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Map<?, ?> bindingMap, Writer writer) {
|
public void render(final Map<?, ?> bindingMap, final Writer writer) {
|
||||||
templateEngine.render(template, bindingMap, new WriterOutput(writer));
|
templateEngine.render(template, bindingMap, new WriterOutput(writer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Map<?, ?> bindingMap, OutputStream out) {
|
public void render(final Map<?, ?> bindingMap, final OutputStream out) {
|
||||||
this.render(bindingMap, IoUtil.toWriter(out, StandardCharsets.UTF_8));
|
this.render(bindingMap, IoUtil.toWriter(out, charset));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +64,7 @@ public class JteTemplate implements Template, Serializable {
|
|||||||
* @param model 实体类
|
* @param model 实体类
|
||||||
* @param writer 输出
|
* @param writer 输出
|
||||||
*/
|
*/
|
||||||
public void render(Object model, Writer writer) {
|
public void render(final Object model, final Writer writer) {
|
||||||
templateEngine.render(template, model, new WriterOutput(writer));
|
templateEngine.render(template, model, new WriterOutput(writer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +74,8 @@ public class JteTemplate implements Template, Serializable {
|
|||||||
* @param model 实体类
|
* @param model 实体类
|
||||||
* @param out 输出
|
* @param out 输出
|
||||||
*/
|
*/
|
||||||
public void render(Object model, OutputStream out) {
|
public void render(final Object model, final OutputStream out) {
|
||||||
render(model, IoUtil.toWriter(out, StandardCharsets.UTF_8));
|
render(model, IoUtil.toWriter(out, charset));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,17 +17,21 @@ public class SimpleStringCodeResolver implements CodeResolver {
|
|||||||
|
|
||||||
private final Map<String, String> templates;
|
private final Map<String, String> templates;
|
||||||
|
|
||||||
public SimpleStringCodeResolver(Map<String, String> templates) {
|
/**
|
||||||
|
* 构造
|
||||||
|
* @param templates 参数
|
||||||
|
*/
|
||||||
|
public SimpleStringCodeResolver(final Map<String, String> templates) {
|
||||||
this.templates = templates;
|
this.templates = templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolve(String name) {
|
public String resolve(final String name) {
|
||||||
return templates.get(name);
|
return templates.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLastModified(String name) {
|
public long getLastModified(final String name) {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user