| 1 | package de.aikiit.mailversendala.template; | |
| 2 | ||
| 3 | /* | |
| 4 | * Copyright (c) P. Ottlinger | |
| 5 | * | |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | * you may not use this file except in compliance with the License. | |
| 8 | * You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, | |
| 13 | * software distributed under the License is distributed on an | |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | * KIND, either express or implied. See the License for the | |
| 16 | * specific language governing permissions and limitations | |
| 17 | * under the License. | |
| 18 | */ | |
| 19 | ||
| 20 | ||
| 21 | import com.google.common.io.CharStreams; | |
| 22 | import de.aikiit.mailversendala.MailConfig; | |
| 23 | ||
| 24 | import java.io.IOException; | |
| 25 | import java.io.InputStream; | |
| 26 | import java.io.InputStreamReader; | |
| 27 | import java.nio.charset.StandardCharsets; | |
| 28 | import java.nio.file.Files; | |
| 29 | import java.nio.file.Path; | |
| 30 | import java.nio.file.Paths; | |
| 31 | ||
| 32 | /** | |
| 33 | * Immutable mail bodies read from files, streams or supplied directly as strings. | |
| 34 | * @param html HTML-format contents. | |
| 35 | * @param plaintext plain-text contents. | |
| 36 | */ | |
| 37 | public record FileMailTemplate(String html, String plaintext) implements MailTemplate { | |
| 38 | ||
| 39 | /** | |
| 40 | * Read given input streams and populate internal mailing contents. | |
| 41 | * @param html HTML-format contents. | |
| 42 | * @param plaintext plain text-contents. | |
| 43 | * @throws IOException in case of errors. | |
| 44 | */ | |
| 45 | public FileMailTemplate(InputStream html, InputStream plaintext) throws IOException { | |
| 46 | this(CharStreams.toString(new InputStreamReader(html, StandardCharsets.UTF_8)), | |
| 47 | CharStreams.toString(new InputStreamReader(plaintext, StandardCharsets.UTF_8))); | |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Apply given configuration and generate internal mailing contents. | |
| 52 | * @param config configuration parameters of the application. | |
| 53 | * @throws IOException in case of errors. | |
| 54 | */ | |
| 55 | public FileMailTemplate(MailConfig config) throws IOException { | |
| 56 | this(readTemplate(Paths.get(config.getTemplatePath(), config.getHtmlTemplate())), | |
| 57 | readTemplate(Paths.get(config.getTemplatePath(), config.getPlaintextTemplate()))); | |
| 58 | } | |
| 59 | ||
| 60 | private static String readTemplate(Path file) throws IOException { | |
| 61 |
1
1. readTemplate : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::readTemplate → KILLED |
return Files.readString(file, StandardCharsets.UTF_8); |
| 62 | } | |
| 63 | ||
| 64 | @Override | |
| 65 | public String getHtml() { | |
| 66 |
1
1. getHtml : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::getHtml → KILLED |
return html; |
| 67 | } | |
| 68 | ||
| 69 | @Override | |
| 70 | public String getPlaintext() { | |
| 71 |
1
1. getPlaintext : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::getPlaintext → KILLED |
return plaintext; |
| 72 | } | |
| 73 | } | |
Mutations | ||
| 61 |
1.1 |
|
| 66 |
1.1 |
|
| 71 |
1.1 |