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