|
9 | 9 | import java.util.Map; |
10 | 10 |
|
11 | 11 | /** |
12 | | - * Container for all parameters needed for the template processinf |
| 12 | + * Container for all parameters needed for the template processing |
13 | 13 | */ |
14 | | -public class ProcessTemplateContext { |
15 | | - |
16 | | - private HttpServerRequest request; |
17 | | - private JsonObject params; |
18 | | - private String templateString; |
19 | | - private Reader reader; |
20 | | - private boolean escapeHtml; |
21 | | - private String defaultValue; |
22 | | - private final Map<String, Mustache.Lambda> lambdas = new HashMap<>(); |
23 | | - |
24 | | - public ProcessTemplateContext request(HttpServerRequest request) { |
| 14 | +public final class ProcessTemplateContext { |
| 15 | + |
| 16 | + private final HttpServerRequest request; |
| 17 | + private final JsonObject params; |
| 18 | + private final String templateString; |
| 19 | + private final Reader reader; |
| 20 | + private final boolean escapeHtml; |
| 21 | + private final String defaultValue; |
| 22 | + private final Map<String, Mustache.Lambda> lambdas; |
| 23 | + |
| 24 | + private ProcessTemplateContext(HttpServerRequest request, JsonObject params, String templateString, Reader reader, |
| 25 | + boolean escapeHtml, String defaultValue, Map<String, Mustache.Lambda> lambdas) { |
25 | 26 | this.request = request; |
26 | | - return this; |
27 | | - } |
28 | | - |
29 | | - public ProcessTemplateContext escapeHtml(boolean escapeHtml) { |
30 | | - this.escapeHtml = escapeHtml; |
31 | | - return this; |
32 | | - } |
33 | | - |
34 | | - public ProcessTemplateContext setDefaultValue(String defaultValue) { |
35 | | - this.defaultValue = defaultValue; |
36 | | - return this; |
37 | | - } |
38 | | - |
39 | | - public ProcessTemplateContext params(JsonObject params) { |
40 | 27 | this.params = params; |
41 | | - return this; |
42 | | - } |
43 | | - |
44 | | - public ProcessTemplateContext templateString(String templateString) { |
45 | 28 | this.templateString = templateString; |
46 | | - return this; |
47 | | - } |
48 | | - |
49 | | - public ProcessTemplateContext reader(Reader reader) { |
50 | 29 | this.reader = reader; |
51 | | - return this; |
| 30 | + this.escapeHtml = escapeHtml; |
| 31 | + this.defaultValue = defaultValue; |
| 32 | + this.lambdas = new HashMap<>(lambdas); |
52 | 33 | } |
53 | 34 |
|
54 | | - public ProcessTemplateContext lambdas(Map<String, Mustache.Lambda> lambdas) { |
55 | | - this.lambdas.putAll(lambdas); |
56 | | - return this; |
| 35 | + public static class Builder { |
| 36 | + |
| 37 | + private HttpServerRequest request; |
| 38 | + private JsonObject params; |
| 39 | + private String templateString; |
| 40 | + private Reader reader; |
| 41 | + private boolean escapeHtml; |
| 42 | + private String defaultValue; |
| 43 | + private final Map<String, Mustache.Lambda> lambdas = new HashMap<>(); |
| 44 | + |
| 45 | + public Builder request(HttpServerRequest request) { |
| 46 | + this.request = request; |
| 47 | + return this; |
| 48 | + } |
| 49 | + |
| 50 | + public Builder escapeHtml(boolean escapeHtml) { |
| 51 | + this.escapeHtml = escapeHtml; |
| 52 | + return this; |
| 53 | + } |
| 54 | + |
| 55 | + public Builder setDefaultValue(String defaultValue) { |
| 56 | + this.defaultValue = defaultValue; |
| 57 | + return this; |
| 58 | + } |
| 59 | + |
| 60 | + public Builder params(JsonObject params) { |
| 61 | + this.params = params; |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + public Builder templateString(String templateString) { |
| 66 | + this.templateString = templateString; |
| 67 | + return this; |
| 68 | + } |
| 69 | + |
| 70 | + public Builder reader(Reader reader) { |
| 71 | + this.reader = reader; |
| 72 | + return this; |
| 73 | + } |
| 74 | + |
| 75 | + public Builder lambdas(Map<String, Mustache.Lambda> lambdas) { |
| 76 | + this.lambdas.putAll(lambdas); |
| 77 | + return this; |
| 78 | + } |
| 79 | + |
| 80 | + public HttpServerRequest request() { |
| 81 | + return request; |
| 82 | + } |
| 83 | + |
| 84 | + public ProcessTemplateContext build() { |
| 85 | + return new ProcessTemplateContext(request, params, templateString, reader, escapeHtml, defaultValue, lambdas); |
| 86 | + } |
| 87 | + |
57 | 88 | } |
58 | 89 |
|
59 | 90 | public HttpServerRequest request() { |
|
0 commit comments