Package: St4Template
St4Template
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
St4Template(String, char) |
|
|
|
|
|
||||||||||||||||||||
addAttribute(String, Object) |
|
|
|
|
|
||||||||||||||||||||
render(Template.Aggregates[]) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.core.impl.text;
28:
29: import javax.annotation.Nonnull;
30: import java.util.List;
31: import org.stringtemplate.v4.ST;
32: import it.tidalwave.northernwind.core.model.Template;
33: import lombok.extern.slf4j.Slf4j;
34:
35: /******************************************************************************************************************************
36: *
37: * An implementation of {@link Template} based on StringTemplate ({@link ST}.
38: *
39: * @author Fabrizio Giudici
40: *
41: *****************************************************************************************************************************/
42: @Slf4j
43: public class St4Template implements Template
44: {
45: // @Nonnull
46: // private final STGroup stg;
47:
48: @Nonnull
49: private final ST st;
50:
51: /**************************************************************************************************************************
52: *
53: *************************************************************************************************************************/
54: public St4Template (@Nonnull final String templateText, final char delimiter)
55: {
56: log.trace("Creating template: {} - {}", templateText, delimiter);
57: // stg = new STGroup(delimiter, delimiter);
58: // stg.defineTemplate("main", templateText);
59: // st = stg.getInstanceOf("main");
60: st = new ST(templateText, delimiter, delimiter);
61: }
62:
63: // public void include (final @Nonnull String name, final @Nonnull Template template)
64: // {
65: // stg.defineTemplate(name, template.templateText);
66: // }
67:
68: /**************************************************************************************************************************
69: *
70: * {@inheritDoc}
71: *
72: *************************************************************************************************************************/
73: @Override
74: public Template addAttribute (@Nonnull final String name, @Nonnull final Object value)
75: {
76: st.add(name, value);
77: return this;
78: }
79:
80: /**************************************************************************************************************************
81: *
82: * {@inheritDoc}
83: *
84: *************************************************************************************************************************/
85: @Override @Nonnull
86: public String render (@Nonnull final Aggregates ... aggregatesSet)
87: {
88:• for (final var aggregates : aggregatesSet)
89: {
90:• if (aggregates.getSize() == 1)
91: {
92: st.add(aggregates.getName(), List.of(aggregates.iterator().next().getMap()));
93: }
94: else
95: {
96:• for (final var aggregate : aggregates)
97: {
98: st.add(aggregates.getName(), aggregate.getMap());
99: }
100: }
101: }
102:
103: return st.render();
104: }
105: }