com.hibegin.template.BasicTemplateRender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplewebserver Show documentation
Show all versions of simplewebserver Show documentation
Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project.
Can quickly run embedded, Android devices
package com.hibegin.template;
import com.hibegin.common.util.IOUtil;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
public class BasicTemplateRender implements TemplateRender {
private final Map map;
private final Class> clazzLoader;
public BasicTemplateRender(Map map, Class> clazzLoader) {
this.map = map;
this.clazzLoader = clazzLoader;
}
public String render(InputStream in) {
if (in == null) {
return "InputStream in null";
}
return render(new String(IOUtil.getByteByInputStream(in), StandardCharsets.UTF_8));
}
public String render(String templateStr) {
String renderResult = templateStr;
for (Map.Entry entry : map.entrySet()) {
renderResult = renderResult.replace("${" + entry.getKey() + "}", entry.getValue().toString());
}
return renderResult;
}
@Override
public String renderByTemplateName(String templateName) {
return render(clazzLoader.getResourceAsStream(templateName));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy