35 lines
1.0 KiB
Java
35 lines
1.0 KiB
Java
package nl.veenm.paypoint.service;
|
|
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Map;
|
|
|
|
@ApplicationScoped
|
|
public class EmailTemplateService {
|
|
|
|
public String loadTemplate(String templatePath, Map<String, String> replacements) {
|
|
try (InputStream is = Thread.currentThread().getContextClassLoader()
|
|
.getResourceAsStream(templatePath)) {
|
|
|
|
if (is == null) {
|
|
throw new RuntimeException("Kon e-mailtemplate niet vinden!");
|
|
}
|
|
|
|
String template = new String(is.readAllBytes(), StandardCharsets.UTF_8);
|
|
|
|
|
|
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
|
template = template.replace("{{" + entry.getKey() + "}}", entry.getValue());
|
|
}
|
|
|
|
return template;
|
|
} catch (IOException e) {
|
|
throw new RuntimeException("Kon e-mailtemplate niet inladen: " + templatePath, e);
|
|
}
|
|
}
|
|
}
|
|
|